fix: make `Graph.options` truly per-instance by tbouffard · Pull Request #751 · maxGraph/maxGraph

@tbouffard

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.

@tbouffard added the bug

Something isn't working

label

Apr 5, 2025

@tbouffard

@tbouffard

@tbouffard tbouffard marked this pull request as ready for review

April 5, 2025 08:32

@tbouffard tbouffard changed the title fix(graph): make Graph.options truly per-instance fix: make Graph.options truly per-instance

Apr 5, 2025

@tbouffard

@tbouffard tbouffard deleted the fix/side_effect_when_changing_Graph_options branch

April 6, 2025 06:14