PuppyAgent's if/else node has a configuration menu. Suppose A and B are already on the canvas. When I drag a connection from A's output to B, the menu should immediately list B so I can configure that branch. An easy-to-miss detail in debugging: getNodes() returns A and B both before and after the drag. Looking only at the node list, I couldn't even tell a connection had just been made.1
Which nodes should the menu list?
On December 27, 2024, I asked how the configuration menu could support multiple inputs and outputs, and whether it could find upstream nodes through the parentId passed down by its parent. Here parentId is a PuppyAgent menu parameter whose value is the ID of the node being configured. Suppose the canvas has nodes A, B, and C and only one edge, A → B. Open A's menu and only B should appear in the outputs. Open B's menu and only A should appear in the inputs. C doesn't belong in either list.2
A React Flow edge stores its endpoint node IDs in source and target, with sourceHandle and targetHandle further distinguishing the ports. For example, THEN and ELSE can be two source handles on the same node. To list configurable target nodes, derive them from the current edges. To configure the connection on a particular branch, keep the entire edge and its handles. This simplified example addresses the first requirement.1
function OutputList({ nodeId, edges }) {
const outgoing = edges.filter(edge => edge.source === nodeId)
const targets = [...new Set(outgoing.map(edge => edge.target))]
return <ul>{targets.map(id => <li key={id}>{id}</li>)}</ul>
}
Here the parent component that manages canvas state passes the latest edges to the menu. Add A → C and the menu rerenders with B and C. Remove A → B and B disappears. For inputs, reverse the direction: filter by edge.target === nodeId and read source. Calling getEdges() inside an event handler gives you the current value. A menu that follows graph changes must also subscribe to edge state or receive an updated array from its parent as in the example.3
I see two lines while dragging. How many are stored after release?
Before you release the mouse, connectionLineComponent draws a preview from the origin to the pointer. PuppyAgent's implementation has a small threshold: it returns null when neither the horizontal nor vertical movement exceeds 10 pixels. If you don't see a line immediately after pressing a handle, try moving the pointer. Whether the edge remains after release depends on whether the connection is accepted and whether the controlled canvas adds it to edges in onConnect. See Why a custom edge misses its handle for how saved edges choose their rendering component and endpoints.4
On December 30, 2024, I read the official Multi Connection Line example. Select A and B, drag from A to C, and two preview lines appear. On release, the example's onConnect adds both A → C and B → C to the edges. If you implement only the preview and save only A → C in the callback, B's output menu obviously can't find C. It's also a useful test of filter direction: after that operation, C's input menu should find both A and B.5
Why can't the toolbar read the canvas state?
I also ran into state access problems in a standalone three-node demo. On January 2, 2025, I posted the error “Seems like you have not used zustand provider as an ancestor”. My extra clue was that passing custom node and edge types to ReactFlow caused the error, and removing them made it disappear. That narrowed the investigation considerably. Keep the graph data fixed, reduce the custom node to text and the edge to BaseEdge, then restore Handle and the node-reading hook one at a time. That shows which component first loses access to canvas state.6
ReactFlowProvider gives its descendants a store for one graph. Components rendered by the canvas through nodeTypes and edgeTypes are already in its context. An external toolbar, sibling sidebar, or editor component that calls useReactFlow() before returning <ReactFlow /> needs the same provider higher in the tree. Here's the minimal structure for an external toolbar.7
function Editor() {
return (
<ReactFlowProvider>
<Toolbar />
<Canvas />
</ReactFlowProvider>
)
}
// Toolbar 和 Canvas 内部都可以调用 useReactFlow()。
Another inexpensive check: which packages supply the canvas, hook, and handle? Cursor suggested checking for a mix of the old reactflow package and v12's @xyflow/react. The official guide also lists duplicate dependencies as a cause of context mismatches. Inspect the installed tree with npm ls reactflow @xyflow/react @xyflow/system. The saved demo imports these components from @xyflow/react, renders <App /> directly at the entry point, and lets the canvas mount the custom edges. I don't have a separate commit showing exactly which change cleared that morning's error.78
Once a context menu opens, which node does it act on?
Several interactions in a workflow look like “menus.” For a node context menu, prevent the default browser menu in onNodeContextMenu(event, node), save that node's node.id and the pointer position, and close the menu on onPaneClick. Use the saved ID for deletion or duplication so the target remains clear even if selection changes afterward. If a portal mounts the menu under document.body with position: fixed, position it directly with clientX/clientY. If you want to create a canvas node there, pass the same screen coordinates to screenToFlowPosition. Store screen coordinates directly as the node's position and the error becomes apparent as soon as you pan or zoom.9
PuppyAgent also uses right-click for another purpose. The toolbar listens for contextmenu only after entering “place new node” mode. A right-click during placement cancels, and leaving the drag interaction cleans up the listener. The drop position goes through screenToFlowPosition; the code also adds a zoom-dependent offset to match the node's appearance at the time. That interaction is separate from the if/else node's own configuration menu.4
PuppyAgent's custom nodes also handle editor focus, sizing, and click events. I wrote about those in Monaco's read-only preview and change events, A JSON node that keeps growing after a resize, and The upload button receives a click but won't open the file picker.
What did PuppyAgent actually change?
On January 2 I had already added cascading selection to the if/else configuration. By February 10, when dragging a connection to add an output, ChooseConfigMenu was still finding targets by taking all the node IDs returned by getNodes(). I changed it to filter getEdges() for edges whose source === parentId, read their target IDs, and update outputs from the current target list when a new target appeared. That gave the menu evidence even when A connected to B already on the canvas. An isolated C wouldn't be mistaken for an output just because it happened to exist.1
On February 21 I also handled duplicate if/else edges using the pair of source and target node IDs. That rule has a limit: if THEN → B and ELSE → B are both legal, their endpoint node pairs are identical. For a menu asking “Which nodes are downstream?”, listing B once is enough. To save “Which branch leads to B?”, retain the source handle or branch identity as well.1
References
Footnotes
-
xyflow. (n.d.). useReactFlow; useEdges. React Flow. Querying instance state on demand; subscribing to the edge list. ↩
-
PuppyAgent contributors. (2025, February 21). PuppyFlow [Historical source snapshot, commit
697caa0c]. GitHub. Node placement and right-click cancellation; connection preview. ↩ ↩2 -
xyflow. (n.d.). Multi connection line [Example and
onConnectsource]. React Flow. Connecting multiple selected nodes. Thompson, H. (2024, February 9). New multi-connection line example!. React Flow. ↩ -
CaiBorui. (2025, January 2). Fixing Zustand Provider Error in React Flow [Private development conversation with Cursor]. Session
1a500de7-f798-4621-a562-7907ab7ccd24. See messages 1 and 7 for the provider error and feedback about registered types. ↩ -
xyflow. (n.d.). ReactFlowProvider; Common errors. React Flow. Provider scope; Zustand provider warning and duplicate installations. ↩ ↩2
-
CaiBorui. (2025, January 2–5). reactflowtest/vite-project [Standalone local Git repository]. Commit
91bafafsaved custom floating edges,5be1d44added diamond nodes, and929d243on thefeat-animated-loading-effect-edgebranch saved an animation. Main files:src/App.jsx,src/customEdges/SimpleFloatingEdge.jsx,SimpleFloatingEdgeAnimated.jsx, andsrc/xy-theme.css. ↩ -
xyflow. (n.d.). Context menu; ReactFlowInstance. React Flow. Node right-click and closing by clicking the pane; viewport coordinate conversion methods. ↩