-
Notifications
You must be signed in to change notification settings - Fork 199
fix: make Graph.options truly per-instance
#751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Before, setting `Graph.options.foldingEnabled = false` on one `Graph` instance affected other instances too — because the `options` object was shared between them. For example, switching to the Constituent story (which disables `Graph.options.foldingEnabled`) then back to another story relying on the default (`true`) would break folding: the folding icon disappeared and cells couldn't be collapsed anymore. This could be seen with the `Collapse` and the `Folding` stories. The bug exists at least as of version 0.14.0, but probably from the first version of maxGraph. 🔍 Root cause: `options` was defined via mixins as an object, but the internal `applyMixin` function probably copies object references, not values — effectively making `Graph.options` global. ✅ Fix: move the `options` property directly onto the `Graph` class. It's the only object-typed prop in our mixins, and we're planning to turn `FoldingMixin` into a plugin anyway — so this fix is simple and future-proof. ℹ️ No impact for users, just internal code structure changes. In addition, migrate Constituent.stories.js to TypeScript to ease future maintenance.
WalkthroughThe changes update documentation for i18n configuration, introduce and integrate a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Graph
participant FoldingManager
User->>Graph: Trigger fold/expand action
Graph->>FoldingManager: Retrieve folding options
FoldingManager-->>Graph: Return configured ImageBox (collapsed/expanded)
Graph-->>User: Update visual with folding image
sequenceDiagram
participant User
participant MyCustomGraph
participant Template
User->>MyCustomGraph: Initiate mouse event
MyCustomGraph->>MyCustomGraph: getInitialCellForEvent(event: InternalMouseEvent)
MyCustomGraph->>MyCustomGraph: isPart(cell: Cell | null)
MyCustomGraph->>MyCustomGraph: selectCellForEvent(cell: Cell, event: MouseEvent)
MyCustomGraph-->>User: Update selection based on event
Suggested labels
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
🧰 Additional context used🧬 Code Definitions (2)packages/core/src/view/Graph.ts (1)
packages/html/stories/Constituent.stories.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (24)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Graph.options truly per-instanceGraph.options truly per-instance
|



Before, setting
Graph.options.foldingEnabled = falseon oneGraphinstance affected other instances too - because theoptionsobject was shared between them.For example, switching to the Constituent story (which disables
Graph.options.foldingEnabled) then back to another story relying on the default (true) would break folding: the folding icon disappeared and cells couldn't be collapsed anymore.This could be seen with the
Collapseand theFoldingstories.The bug exists at least as of version 0.14.0, but probably from the first version of maxGraph.
🔍 Root cause:
optionswas defined via mixins as an object, but the internalmixIntofunction probably copiesobject references, not values — effectively making
Graph.optionsglobal.✅ Fix: move the
optionsproperty directly onto theGraphclass.It's the only object-typed prop in our mixins, and we're planning to turn
FoldingMixininto a plugin anyway — so this fix is simple and future-proof.ℹ️ No impact for users, just internal code structure changes.
In addition, migrate Constituent.stories.js to TypeScript to ease future maintenance.
Summary by CodeRabbit
New Features
Refactor
Documentation