From bfd0b47c1994a35c6e3eea243933825f38648b7f Mon Sep 17 00:00:00 2001 From: Will Eastcott Date: Wed, 29 Apr 2026 15:08:54 +0100 Subject: [PATCH] fix: avoid double initialization of node context menu items `Graph.createNode` was calling `_initializeNodeContextMenuItems` and then passing the result to `view.addNodeContextMenu`, which (via `GraphViewNode.addContextMenu`) calls `_initializeNodeContextMenuItems` again. The second invocation runs `structuredClone` on items that now contain `onSelect` function references attached during the first invocation, causing: Failed to execute 'structuredClone' on 'Window': () => this._createUnconnectedEdgeForNode(node, item.edgeType) could not be cloned. This regression was exposed by #136 (replacing `deepCopyFunction` with `structuredClone`); the previous custom deep-copy silently preserved function references on objects, masking the latent bug. Pass the raw schema items straight to `view.addNodeContextMenu` so initialization happens exactly once inside `GraphViewNode.addContextMenu`, matching the existing flow used by `updateNodeType`. Fixed #141 Made-with: Cursor --- src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9cf67a9..10099ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -471,8 +471,7 @@ class Graph extends Element { }); } if (nodeSchema.contextMenuItems) { - const contextMenuItems = this._initializeNodeContextMenuItems(node, nodeSchema.contextMenuItems); - this.view.addNodeContextMenu(node.id, contextMenuItems); + this.view.addNodeContextMenu(node.id, nodeSchema.contextMenuItems); } }