Skip to content

fix: use the right list of excluded fields in GraphCodec#777

Merged
tbouffard merged 2 commits intomainfrom
fix/GraphCodec
Apr 25, 2025
Merged

fix: use the right list of excluded fields in GraphCodec#777
tbouffard merged 2 commits intomainfrom
fix/GraphCodec

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Apr 25, 2025

Doing an export/encode of a Graph generated an error "Maximum call stack size exceeded. RangeError: Maximum call stack size exceeded".

In GraphCodec, the list of excluded fields was incorrect:

Tests have been added to validate that the Graph import/export works.

In all existing tests involving Codecs, unregister all codecs before and after to ensure there is no side effects between tests.

Summary by CodeRabbit

  • New Features

    • Added tests for serialization and deserialization of graphs and their constituents, ensuring accurate XML import/export.
  • Bug Fixes

    • Improved test reliability by resetting codec registrations before and after tests to prevent side effects.
  • Refactor

    • Centralized codec creation logic for better maintainability and code reuse.
    • Simplified and clarified codec constructors and encoding logic for graph and view serialization.
  • Chores

    • Registered codecs for additional core types to support broader serialization scenarios.
    • Introduced a shared utility for creating object codecs to streamline codec registration.

Doing an export/encode of a Graph generated an error "Maximum call stack size exceeded. RangeError: Maximum call stack size exceeded".

In `GraphCodec`, the list of excluded fields was incorrect:
  - `selection` was in the list, but this field doesn't exist, it is named `selectionModel`.
  The bug already existed in mxGraph https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/io/mxGraphCodec.js#L26
  - `plugins` was missing. There is currently no codec for Plugin so it is not supported for now

Tests have been added to validate that the Graph import/export works.

In all existing tests involving Codecs, unregister all codecs before and after to ensure there is no side effects between tests.
@tbouffard tbouffard added the bug Something isn't working label Apr 25, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 25, 2025

"""

Walkthrough

The changes introduce a new test suite for graph serialization and deserialization, enhance codec registration management in existing test files, and refactor codec registration logic for better modularity. The GraphCodec and GraphViewCodec constructors are updated to set explicit codec names and adjust transient fields. Codec registration functions are refactored to use a shared createObjectCodec utility, which is newly exported for centralized codec creation. Additional codecs for Rectangle and ImageBox are registered. Lifecycle hooks are added to tests to unregister codecs and prevent state leakage between tests.

Changes

File(s) Change Summary
packages/core/__tests__/serialization/codecs/graph-and-constituents.test.ts New test suite added for serialization and deserialization of graphs and constituents, with utility functions for exporting/importing XML and setup/teardown for codec registration.
packages/core/__tests__/serialization/serialization.xml.mxGraph.test.ts,
packages/core/__tests__/serialization/serialization.xml.test.ts
Added Jest lifecycle hooks (beforeAll, afterEach) to unregister codecs before/after tests, updating imports accordingly. No changes to test logic.
packages/core/src/serialization/codecs/GraphCodec.ts Updated constructor to instantiate Graph without plugins, changed transient fields, added explicit codec name via setName('Graph'), and updated comments.
packages/core/src/serialization/codecs/GraphViewCodec.ts Simplified constructor, set explicit codec name via setName('GraphView'), and updated root cell retrieval in encode method to use non-null assertion.
packages/core/src/serialization/register-model-codecs.ts Refactored to import and use createObjectCodec from register-shared instead of defining it locally.
packages/core/src/serialization/register-other-codecs.ts Added codec registrations for Rectangle and ImageBox using the shared createObjectCodec utility.
packages/core/src/serialization/register-shared.ts Added and exported createObjectCodec function for centralized codec creation.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite as Test Suite
    participant Codec as Codec Registry
    participant Graph as Graph Instance

    TestSuite->>Codec: unregisterAllCodecs() (beforeAll/afterEach)
    TestSuite->>Codec: register codecs as needed
    TestSuite->>Graph: create Graph instance (with/without plugins)
    TestSuite->>Codec: export Graph to XML
    TestSuite->>Codec: import XML to Graph
    TestSuite->>Graph: verify properties after import/export
Loading

Possibly related PRs

Suggested labels

documentation
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a41d4c and 2a6852f.

📒 Files selected for processing (1)
  • packages/core/__tests__/serialization/codecs/graph-and-constituents.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/tests/serialization/codecs/graph-and-constituents.test.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit ee74226 into main Apr 25, 2025
2 checks passed
@tbouffard tbouffard deleted the fix/GraphCodec branch April 25, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant