Commit c7b84f4
refactor: register node geometry at attach, delete useVueNodeLifecycle (#14128)
Phase: move node layout registration to the entity's attach point, so
the renderer stops owning node lifetime.
Nodes were the only positionable whose layout entry was created by the
renderer — groups register in `LGraph.add`, reroutes in their
constructor, nodes went through `useVueNodeLifecycle` listening to
`node:added` / `node:removed`. That indirection is why entries could
outlive the graph that created them, which is what the ownership
attempts on the parent branch were working around.
## Changes
- Node geometry registers in `LGraph.add` and deregisters in
`LGraph.remove`, beside `registerNodeState` / `unregisterNodeState`.
- `graphLayoutRegistration` centralizes node, group, and reroute
registration and teardown, including graph clear, non-clearing
configure, and recursive subgraph release paths.
- `initializeFromLiteGraph` split: the seeding half is gone, the
view-change reset becomes `clearViewGeometry`; `reset` covers full
teardown.
- `useVueNodeLifecycle` deleted. `GraphCanvas` directly owns the
remaining `useLayoutSync` and mode-switch lifecycle, while legacy-node
arrangement moves to `arrangeForLegacyRender`. `setupEmptyGraphListener`
disappears with renderer-owned seeding.
- Deleted the layout operation log (see below).
- Node layout is keyed by `makeScopedLayoutKey(rootGraphId, nodeId)`,
the scheme groups and reroutes already used (see below).
## Fixed along the way
- **zIndex was seeded two ways that disagreed.**
`initializeFromLiteGraph` used the node's index in `_nodes`; the
per-node path used `node.order`, which is execution order from
`computeExecutionOrder` and unrelated to stacking. Draw order wins.
## Performance
Deleting the never-read operation log removed an unbounded per-operation
cost that grew with session length, in Vue nodes mode today:
| | `moveNode` with an entry |
| --- | --- |
| 22k operations logged | 197 us/op |
| 40k operations logged | 375 us/op |
| log deleted | 5.4 us/op, flat (2.9 us/op after 18k more) |
That is also what made attach-time registration affordable for the
legacy canvas, which now pays for entries it does not read. Dragging 100
selected nodes: 10.8 ms/frame (65% of a 16.7ms frame) before, 0.60
ms/frame (3.6%) after.
## Behaviour change to review
`layoutStore` now holds every node in the workflow rather than only the
viewed graph. Only tests call `queryNodeAtPoint` / `getNodesInBounds`,
and both `getAllNodes` callers only take a max zIndex, so nothing reads
across the wider set today.
Three tests asserted the policy this reverses (no layout while the
renderer is off; seeding stops on dispose; adds to unviewed graphs
ignored). They pinned the old design rather than behaviour worth
keeping, so they are deleted; the contract still worth holding — add
creates an entry, remove drops it — moved next to `LGraph`, with a test
that zIndex follows draw order.
## Node layout keys are now root-graph scoped
Groups and reroutes were already keyed by
`makeScopedLayoutKey(rootGraphId, id)`; nodes were the exception, keyed
by a bare `NodeId`. Now that registration is unconditional, that
exception is what kept layout from having a bucket to wipe — hence the
`// Geometry has no per-rootGraph bucket to wipe, so both branches
sweep` comment this removes.
Node methods on `LayoutStore` and `LayoutMutations` take a leading
`rootGraphId`. `graphId` lifts into `OperationMeta` so all three entity
bases inherit it. `parseLayoutKey` splits on the first `:` rather than
the last, so node ids containing `:` round-trip; graph ids are UUIDs and
never contain one.
**This does not fix an id collision — there was never one to fix.**
`Subgraph` shares the root graph's `state`, so one counter issues every
node id, and root and interior nodes sharing a bucket is safe. What it
buys is that a root graph's teardown becomes a single
`layoutStore.clearGraph(graphId)` sitting beside the five peer stores
already cleared there, instead of layout being the one exception that
had to walk the subgraph tree. `unregisterAllGraphLayout` stays for
graphs that share the root's bucket — subgraphs, unconfigured graphs,
orphaned subgraph release — and now mirrors `unregisterAllNodeStates`
exactly.
Worth a second opinion: six Vue-node composables now read
`useCanvasStore().rootGraphId` where they previously only touched the
layout singleton. They are all current-canvas-only paths, and the
alternative pushes `rootGraphId!` non-null assertions into `.vue`
templates.
One consequence of that read is worth knowing about, since it caught me
out. In `useNodeLayout` the layout read must stay **dynamic** — the node
`v-for` keys on a bare node id, so Vue patches a component across a
graph change rather than remounting it, and a captured id would resolve
stale. Ref cleanup must be the **opposite**: `rootGraphId` flips before
the outgoing graph's components unmount, so reading it in `onUnmounted`
released the ref into the incoming bucket and stranded the real one.
Captured at setup now, with a test pinning it. Only ids that do not
survive a workflow load were affected; ids present in both are patched,
never unmounted.
## Downstream stack
[#14133](../pull/14133) completes node geometry ownership after this PR
establishes attach/detach lifetime. It makes the node `Rectangle` a
versioned projection of `layoutStore`, reuses the shared geometry view
for compatible mutable `pos` / `size` access, deletes `useLayoutSync`,
and replaces writeback with operation-driven resize notifications and
canvas invalidation.
Review this PR's registration and teardown contract independently of
that downstream read-path change: this PR still retains `useLayoutSync`
by design.
<details>
<summary>Things an inattentive agent might call out but which are not
valid findings</summary>
Each of these has been checked against the code. If you are about to
file one, read the rebuttal first.
**"Node layout entries are keyed by a bare node id with no graph scope,
unlike groups and reroutes."**
No longer true — they are scoped by `rootGraphId`, as of the commit
above. Note what that did and did not change: root and subgraph-interior
nodes still share one bucket, and that is deliberate, because node ids
are unique root-wide. Deserialized ids go through
`deduplicateSubgraphNodeIds`, called from `LGraph.configure` when
`isRootGraph`, which remaps colliding interior ids and patches links and
promoted widgets. Runtime-allocated ids come from `++state.lastNodeId`,
and `Subgraph.state` returns `rootGraph.state` — one counter for the
whole workflow. Clipboard paste and unpack have their own remapping.
`basic-subgraph.json` looks like a collision on disk (root `2`, interior
`1, 2`) and loads as `2`, `1`, `3`. `LGraph.test.ts` pins both halves:
`expect(subgraph.state).toBe(rootGraph.state)` and `'node IDs never
collide between root and subgraph'`.
A repro that reaches a collision by assigning `node.id` directly before
`add()` is not evidence — `LGraph.add`'s duplicate guard is per-graph by
design, and no production path assigns ids that way.
**"`useLayoutSync` can now resolve a store change against the wrong
node, because changes from unviewed graphs flush against the viewed
graph."**
Same root cause as above, same rebuttal. Ids do not collide, so
`getNodeById` cannot resolve to a different node.
**"`LGraph.add` now requires an active Pinia instance, breaking headless
and extension use."**
`layoutStore` is a plain module singleton, not a Pinia store, and
`useLayoutMutations` touches nothing else. `LGraph.add` already required
Pinia before this PR via `registerNodeState` and `useWidgetValueStore`.
Net change to Pinia surface: zero.
**"`src/lib/litegraph` importing from `src/renderer/core/layout`
violates the layering boundary."**
`import-x/no-restricted-paths` deliberately scopes its zones to `base`,
`platform`, `workbench`, and `world`; litegraph is outside them. ADR
0001 merged litegraph into the frontend precisely so mutations route
through one CRDT-mediated access point. `LGraph.ts` already imported
`useLayoutMutations` and `layoutStore`; this PR swaps a raw mutations
import for a named registration module, leaving the edge count
unchanged.
**"Registering layout inside `LGraph.add` is god-object growth on
`LGraph` (ADR 0008)."**
No methods or properties are added to `LGraph`, `LGraphNode`,
`LGraphCanvas`, or `Subgraph`. Existing methods delegate to a module,
and every write still lands as a `LayoutOperation` through
`applyOperation` — the command pattern is intact. `clearGraph` is
likewise a `ClearGraphOperation` dispatched through `applyOperation`,
not a side-channel wipe.
**"`deleteGroup` and `deleteReroute` gained an existence guard but
`deleteNode` did not — inconsistent."**
`deleteNode` already had the identical guard before this PR. Its absence
from the diff is correct.
**"Those existence guards are redundant with a check `applyOperation`
already does."**
`applyOperation` calls `Y.Map.delete` unconditionally and still bumps
`version` and dispatches change listeners. The early return suppresses
real churn.
**"Moving the group loop after `this.remove(subgraphNode)` in
`unpackSubgraph` changes behaviour."**
`toSelect` ordering is unchanged, `offsetX` / `offsetY` are not mutated
in between, and nothing in the intervening block reads groups. The move
is required: `remove()` now triggers
`unregisterAllGraphLayout(subgraph)`, which would otherwise run after
the unpacked groups registered and drop their entries.
**"Populating `layoutStore` with the Vue renderer off breaks the
minimap, which picks its data source by asking whether the store has
nodes."**
That rationale is stale — it survived in a docstring longer than in the
code. `MinimapDataSourceFactory` selects on `LiteGraph.vueNodesMode`,
and `MinimapDataSource.test.ts` has an explicit regression test
forbidding the emptiness check.
**"`startSync` can be skipped on the immediate run when the canvas is
not ready, and removing `setupEmptyGraphListener` loses the empty-graph
deferral."**
`startSync` no-ops safely when there is no graph, and the watcher
re-fires when `canvasStore.currentGraph` flips from `null`, which is
reactive — unlike the old `comfyApp.canvas?.graph` source that
`setupEmptyGraphListener` existed to work around. `stopSync` is
idempotent. The deferral is obsolete, not lost.
**"Dropping the `isInSubgraph` watcher's layout reset breaks subgraph
navigation."**
`canvasStore.currentGraph` updates on subgraph navigation, so the
consolidated watcher covers it. Node membership comes from
`nodeDataStore.getGraphNodesFor`, which stays graph-scoped regardless.
**"The new e2e spec uses `page.evaluate` instead of user actions."**
The regression under test is an extension calling `node.setSize()` and
the Vue node not moving. No user gesture reaches that path; driving the
resize handle would exercise a different one and pass with the bug
present.
</details>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: AustinMroz <austin@comfy.org>1 parent 15db3dd commit c7b84f4
67 files changed
Lines changed: 1948 additions & 1584 deletions
File tree
- browser_tests/tests
- vueNodes
- interactions/node
- layout
- docs
- adr
- architecture
- src
- components/graph
- composables
- canvas
- graph
- lib/litegraph/src
- subgraph
- types
- renderer
- core
- canvas
- links
- litegraph
- layout
- operations
- store
- __mocks__
- sync
- utils
- extensions
- minimap/data
- vueNodes
- components
- composables
- interactions/resize
- layout
- types
- utils/__tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
160 | 209 | | |
161 | 210 | | |
162 | 211 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
| |||
Lines changed: 293 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
0 commit comments