ssssssss-team/spider-flow · error · Error

" + id + ": Duplicate ID

Error message

" + id + ": Duplicate ID

What it means

mxGraph's object registry (mxObjectCodec / codec element map) enforces unique IDs: when decoding, if an ID is already registered and maps to a different node, it throws Error(id + ': Duplicate ID'). Each cell/element ID in the model must be globally unique.

Solutions

  1. Regenerate unique IDs in the graph XML before loading (e.g. mxGraphModel's editor or post-process the XML to reassign ids).
  2. Fix the server-side/client-side ID generator so counters never repeat (use mxUtils/uuid-style generation).
  3. If merging diagrams, remap IDs in the incoming document to avoid collisions.

Example fix

// before (XML)
<mxCell id="1" .../>
<mxCell id="1" .../>
// after
<mxCell id="1" .../>
<mxCell id="2" .../>
Defensive patterns

Strategy: validation

Validate before calling

function validateUniqueIds(xmlDoc) {
  var ids = {}, dup = [];
  Array.prototype.forEach.call(xmlDoc.querySelectorAll('[id]'), function(el) {
    if (ids[el.getAttribute('id')]) dup.push(el.getAttribute('id'));
    ids[el.getAttribute('id')] = true;
  });
  return dup; // must be empty before decoding
}

Try / catch

try {
  codec.decode(doc.documentElement, graph.getModel());
} catch (e) {
  if (/Duplicate ID/.test(e.message)) { rewriteDuplicateIds(xmlDoc); codec.decode(doc.documentElement, graph.getModel()); }
  else throw e;
}

Prevention

When it happens

Trigger: Decoding an mxGraphModel (e.g. from saved XML) that contains two elements sharing the same `id` attribute, or registering two different nodes under the same id via the codec's elements map.

Common situations: Hand-edited or generated graph XML with repeated IDs, merging two diagrams whose ID sequences overlap, or backend serialization that resets/loops ID counters.

Related errors


AI-assisted analysis of ssssssss-team/spider-flow@c799cca99c (2026-09-08). Data as JSON: /api/errors/d6cad218d8d0e775. Report an issue: GitHub.

Appendix: source

Thrown at spider-flow-web/src/main/resources/static/js/mxgraph/mxgraph.js:86560

 * Function: addElement
 *
 * Adds the given element to <elements> if it has an ID.
 */
mxCodec.prototype.addElement = function(node)
{
	if (node.nodeType == mxConstants.NODETYPE_ELEMENT)
	{
		var id = node.getAttribute('id');
		
		if (id != null)
		{
			if (this.elements[id] == null)
			{
				this.elements[id] = node;
			}
			else if (this.elements[id] != node)
			{
				throw new Error(id + ': Duplicate ID');
			}
		}
	}
	
	node = node.firstChild;
	
	while (node != null)
	{
		this.addElement(node);
		node = node.nextSibling;
	}
};

/**
 * Function: getId
 *
 * Returns the ID of the specified object. This implementation
 * calls <reference> first and if that returns null handles

View on GitHub (pinned to c799cca99c)