Problem
_idSeq (js/model.js:307) is a module-level mutable global. Diagram.loadJSON() at line 826 advances it:
_idSeq = Math.max(_idSeq, data._idSeq || 0);
Two Diagram instances in the same process share this counter. Loading a diagram with a high _idSeq permanently skews ID generation for all future diagrams — including Monte Carlo clones and undo snapshots.
Fix
Remove the global mutation. Store _idSeq per-Diagram:
// Diagram.loadJSON, line 826 — change:
_idSeq = Math.max(_idSeq, data._idSeq || 0);
// to:
this._idSeq = Math.max(this._idSeq || _idSeq, data._idSeq || 0);
Add _idSeq initialization in the Diagram constructor.
The module-level _idSeq still exists for genId() calls outside a diagram context (tests, demos), but loading a diagram no longer mutates it globally.
Effort
~10 minutes. 1 file (js/model.js). 3 lines changed.
Problem
_idSeq(js/model.js:307) is a module-level mutable global.Diagram.loadJSON()at line 826 advances it:Two
Diagraminstances in the same process share this counter. Loading a diagram with a high_idSeqpermanently skews ID generation for all future diagrams — including Monte Carlo clones and undo snapshots.Fix
Remove the global mutation. Store
_idSeqper-Diagram:Add
_idSeqinitialization in theDiagramconstructor.The module-level
_idSeqstill exists forgenId()calls outside a diagram context (tests, demos), but loading a diagram no longer mutates it globally.Effort
~10 minutes. 1 file (
js/model.js). 3 lines changed.