ssssssss-team/spider-flow · error · Error

" + parent.id + ": Self Reference

Error message

" + parent.id + ": Self Reference

What it means

When setting a cell's parent (mxGraphModel.parentForCellChanged), mxGraph rejects a cell being made its own parent, throwing Error(parent.id + ': Self Reference'). A cell that is its own ancestor would create a cycle in the model tree and break traversal/serialization.

Solutions

  1. Check `parent !== cell` (and that parent is not a descendant of cell) before calling model.add.
  2. Fix variable assignment so the target cell and parent cell are not confused.
  3. In group operations, exclude the new parent node from the set of cells being reparented.

Example fix

// before
model.add(parent, cell); // parent may be cell itself
// after
if (parent != null && parent !== cell && !isDescendant(parent, cell)) {
  model.add(parent, cell);
}
Defensive patterns

Strategy: validation

Validate before calling

function canReparent(parent, cell) {
  return parent != null && parent !== cell && !isAncestor(cell, parent); // mxCell.isAncestor exists
}

Try / catch

try {
  model.add(parent, cell);
} catch (e) {
  if (/Self Reference/.test(e.message)) { console.warn('Refused self/ancestor reparent of cell ' + cell.id); }
  else throw e;
}

Prevention

When it happens

Trigger: Calling model.add(parent, cell) or setting the parent where parent === cell; also occurs with group operations that compute the group incorrectly.

Common situations: Programmatic graph building where variables holding 'parent' and 'child' are swapped, group/ungroup code that includes the parent itself in the selection, drag-and-drop handlers dropping a cell onto itself.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

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

 *
 * Inserts the given cell into its parent and terminal cells.
 */
mxCodec.prototype.insertIntoGraph = function(cell)
{
	var parent = cell.parent;
	var source = cell.getTerminal(true);
	var target = cell.getTerminal(false);

	// Fixes possible inconsistencies during insert into graph
	cell.setTerminal(null, false);
	cell.setTerminal(null, true);
	cell.parent = null;
	
	if (parent != null)
	{
		if (parent == cell)
		{
			throw new Error(parent.id + ': Self Reference');
		}
		else
		{
			parent.insert(cell);
		}
	}

	if (source != null)
	{
		source.insertEdge(cell, true);
	}

	if (target != null)
	{
		target.insertEdge(cell, false);
	}
};

View on GitHub (pinned to c799cca99c)