Update Node Internals
Edges attach where the canvas last measured a node's handles. When a handle moves without the node changing size - switched to another side, or shifted by CSS - call UpdateNodeInternals so the canvas reads the node again and its edges follow, as React Flow's useUpdateNodeInternals does.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- Flip handle side moves the node's source handles between its right and bottom sides; the edge leaves from the new place straight away.
- Add handle adds another source handle (up to five), spread evenly along the side. Drag from a new handle to Target to connect it.
- Tick shift handles with CSS on the node: the handles slide along the side, but the edge still ends where they were. Press Update node internals and it jumps to them. Untick it and the edge is left behind again.
- With the box ticked, drag the node instead: letting go measures it too, and the edge catches up.
How it works
- The handles are
BlowHandles in the node'sNodeTemplate; theirPosition(side), count andStyle(where along the side) come from fields of the page. - The canvas does not ask the browser where a handle is each time it draws an edge: it measures the nodes - their size and every handle's offset - and edges attach at what was measured. It measures by itself when a node changes size, when handles are added or removed, when a drag or a resize ends, and after each render of the page that hosts it.
UpdateNodeInternals("dyn")has the browser layer read the named node again and send it across whatever it last reported; with no ids it reads every node, asRefresh(remeasure: true)does.- Flip and Add handle change the page's state, so the page renders and the canvas measures after that render anyway; they call
UpdateNodeInternals("dyn")all the same, which is the safe habit whenever code changes a node's handles. - The call is indispensable when a handle moves and nothing renders: the CSS box shifts the handles with a
:has()rule on the node, which the browser applies without Blazor - or the canvas - hearing of it. A node component re-rendering its own state, or a script, is the same case.