Skip to content

Fix _idSeq global mutation on diagram load #46

Description

@zntznt

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions