From 5e4aa21546b77daae9cddf2c1bdeb488851d4a81 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 23 Aug 2026 00:19:43 -0700 Subject: [PATCH 1/7] fix: preserve a live resize when serializing missing-node placeholders The placeholder branch in LGraphNode.serialize() replays last_serialization so a missing node's original data survives a save, and #6792 added pos and mode on top of it so a user could move or bypass the placeholder without losing the change. size was left out, so resizing a placeholder to read its error text was silently discarded on save while a move of the same node was kept. Carry size through the same way. Every placeholder creation site seeds the live size from the same data as last_serialization, so this is a no-op until the user actually resizes. Co-authored-by: Christian Byrne --- src/lib/litegraph/src/LGraphNode.test.ts | 37 ++++++++++++++++++++++++ src/lib/litegraph/src/LGraphNode.ts | 7 ++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/lib/litegraph/src/LGraphNode.test.ts b/src/lib/litegraph/src/LGraphNode.test.ts index 879cd0d3fac..07ac90f0f57 100644 --- a/src/lib/litegraph/src/LGraphNode.test.ts +++ b/src/lib/litegraph/src/LGraphNode.test.ts @@ -100,6 +100,43 @@ describe('LGraphNode', () => { expect(Array.from(node.size)).toEqual([70, 80]) }) + describe('missing-node placeholder serialization', () => { + function createPlaceholder(): LGraphNode { + const lastSerialization = getMockISerialisedNode({ + type: 'UninstalledNodeType', + pos: [100, 100], + size: [140, 60], + widgets_values: [512] + }) + const placeholder = new LGraphNode('') + placeholder.last_serialization = lastSerialization + placeholder.has_errors = true + placeholder.configure(lastSerialization) + return placeholder + } + + test('carries the live pos and size through to the replayed serialization', () => { + const placeholder = createPlaceholder() + placeholder.pos = [999, 888] + placeholder.size = [777, 666] + + const serialized = placeholder.serialize() + + expect(serialized.pos).toEqual([999, 888]) + expect(serialized.size).toEqual([777, 666]) + }) + + test('still replays the fields it has no definition to regenerate', () => { + const placeholder = createPlaceholder() + placeholder.size = [777, 666] + + const serialized = placeholder.serialize() + + expect(serialized.type).toEqual('UninstalledNodeType') + expect(serialized.widgets_values).toEqual([512]) + }) + }) + test('should configure inputs correctly', () => { const node = new LGraphNode('TestNode') node.configure( diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 38723cce556..8a0c4927c91 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1061,7 +1061,12 @@ export class LGraphNode // special case for when there were errors if (this.constructor === LGraphNode && this.last_serialization) - return { ...this.last_serialization, mode: o.mode, pos: o.pos } + return { + ...this.last_serialization, + mode: o.mode, + pos: o.pos, + size: o.size + } if (this.inputs) o.inputs = this.inputs.map((input) => inputAsSerialisable(input)) From c9f2b966dec207967a9aff4cea8b61b5f5895b93 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 23 Aug 2026 00:21:58 -0700 Subject: [PATCH 2/7] test: update v0.4 graph snapshot for the placeholder size passthrough The fixture node has no type, so it loads as a placeholder whose last_serialization carries neither pos nor size. pos was already synthesised from the live node into the snapshot; size now is too. --- src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap b/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap index 836ad17563b..15debdecef6 100644 --- a/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap +++ b/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap @@ -34,6 +34,10 @@ exports[`LGraph > supports schema v0.4 graphs > oldSchemaGraph 1`] = ` 10, 10, ], + "size": [ + 140, + 60, + ], }, ], "revision": 0, From b6b38701187532e1546f0029b73a00a0b09729b8 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 23 Aug 2026 00:43:53 -0700 Subject: [PATCH 3/7] fix: scope the placeholder size passthrough to expanded nodes with a recorded size Guard the new `size` passthrough on two cases review surfaced: - `last_serialization` with no `size` (schema v0.4 / partial entries): the unconditional override wrote the LGraphNode constructor default [140, 60] into the saved workflow, a dimension the source file never had, pinning the real node to it once the pack is installed. Reverts the v0.4 snapshot churn along with it. - Collapsed placeholders: Vue nodes mode clears the CSS width/height floors on collapse, so the ResizeObserver -> layoutStore -> useLayoutSync chain writes the collapsed card's measurement back to `node.size`. Since `flags` is still replayed from the file, persisting that would pair `collapsed: false` with collapsed dimensions. Tests now drive geometry through `setPos`/`setSize` (the production mutators `LGraphCanvas` resizing uses) rather than raw field assignment. --- src/lib/litegraph/src/LGraphNode.test.ts | 33 ++++++++++++++++--- src/lib/litegraph/src/LGraphNode.ts | 15 +++++++-- .../src/__snapshots__/LGraph.test.ts.snap | 4 --- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/lib/litegraph/src/LGraphNode.test.ts b/src/lib/litegraph/src/LGraphNode.test.ts index 07ac90f0f57..4d0e78b5dfd 100644 --- a/src/lib/litegraph/src/LGraphNode.test.ts +++ b/src/lib/litegraph/src/LGraphNode.test.ts @@ -101,12 +101,15 @@ describe('LGraphNode', () => { }) describe('missing-node placeholder serialization', () => { - function createPlaceholder(): LGraphNode { + function createPlaceholder( + overrides: Partial = {} + ): LGraphNode { const lastSerialization = getMockISerialisedNode({ type: 'UninstalledNodeType', pos: [100, 100], size: [140, 60], - widgets_values: [512] + widgets_values: [512], + ...overrides }) const placeholder = new LGraphNode('') placeholder.last_serialization = lastSerialization @@ -117,8 +120,8 @@ describe('LGraphNode', () => { test('carries the live pos and size through to the replayed serialization', () => { const placeholder = createPlaceholder() - placeholder.pos = [999, 888] - placeholder.size = [777, 666] + placeholder.setPos(999, 888) + placeholder.setSize([777, 666]) const serialized = placeholder.serialize() @@ -128,13 +131,33 @@ describe('LGraphNode', () => { test('still replays the fields it has no definition to regenerate', () => { const placeholder = createPlaceholder() - placeholder.size = [777, 666] + placeholder.setSize([777, 666]) const serialized = placeholder.serialize() expect(serialized.type).toEqual('UninstalledNodeType') expect(serialized.widgets_values).toEqual([512]) }) + + test('does not invent a size when the recorded serialization has none', () => { + const placeholder = createPlaceholder() + delete (placeholder.last_serialization as Partial).size + + const serialized = placeholder.serialize() + + expect(serialized).not.toHaveProperty('size') + }) + + test('keeps the recorded size while collapsed, since flags are replayed from the file', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + placeholder.flags.collapsed = true + placeholder.setSize([80, 30]) + + const serialized = placeholder.serialize() + + expect(serialized.size).toEqual([140, 60]) + expect(serialized.flags).toEqual({ collapsed: false }) + }) }) test('should configure inputs correctly', () => { diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 8a0c4927c91..88b863dd4f4 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1060,13 +1060,24 @@ export class LGraphNode } // special case for when there were errors - if (this.constructor === LGraphNode && this.last_serialization) + if (this.constructor === LGraphNode && this.last_serialization) { + // Only an expanded placeholder whose file recorded a size has a live + // size worth keeping. Vue nodes mode drops the CSS width/height floors + // on collapse, so a collapsed node's size is a measurement of the + // collapsed card, and `flags` is replayed from the file — keeping both + // would pair `collapsed: false` with collapsed dimensions. With no + // recorded size there is no definition to compute a real one from, so + // keeping the live size would invent a dimension the file never had. + const carriesLiveSize = + this.last_serialization.size != null && !this.flags.collapsed + return { ...this.last_serialization, mode: o.mode, pos: o.pos, - size: o.size + ...(carriesLiveSize && { size: o.size }) } + } if (this.inputs) o.inputs = this.inputs.map((input) => inputAsSerialisable(input)) diff --git a/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap b/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap index 15debdecef6..836ad17563b 100644 --- a/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap +++ b/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap @@ -34,10 +34,6 @@ exports[`LGraph > supports schema v0.4 graphs > oldSchemaGraph 1`] = ` 10, 10, ], - "size": [ - 140, - 60, - ], }, ], "revision": 0, From b721b1ccaeb8b5e185373712bc2d065cf27d9680 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 26 Aug 2026 12:31:30 -0700 Subject: [PATCH 4/7] fix: refresh a placeholder's recorded size across collapse/expand collapse() now captures the live size into last_serialization before collapsing, and restores it before expanding, closing a race where an async DOM remeasurement in Vue nodes mode left a stale size to be serialized in the window right after a collapse/expand toggle. --- src/lib/litegraph/src/LGraphNode.test.ts | 33 ++++++++++++++++++++++++ src/lib/litegraph/src/LGraphNode.ts | 21 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/lib/litegraph/src/LGraphNode.test.ts b/src/lib/litegraph/src/LGraphNode.test.ts index 8e0cffb014b..e893a534b97 100644 --- a/src/lib/litegraph/src/LGraphNode.test.ts +++ b/src/lib/litegraph/src/LGraphNode.test.ts @@ -192,6 +192,39 @@ describe('LGraphNode', () => { expect(serialized.size).toEqual([140, 60]) expect(serialized.flags).toEqual({ collapsed: false }) }) + + test('records the size it was collapsed from, so a resize survives collapsing', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + + expect(placeholder.serialize().size).toEqual([777, 666]) + }) + + test('restores the recorded size when expanding, rather than serializing a stale measurement', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + // Simulate the Vue nodes mode race: `size` still measures the + // collapsed card immediately after expanding, before the next + // ResizeObserver tick lands the real measurement. + placeholder.setSize([80, 30]) + placeholder.collapse() + + expect(placeholder.serialize().size).toEqual([777, 666]) + }) + + test('does not invent a recorded size on collapse when the file recorded none', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + delete (placeholder.last_serialization as Partial).size + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + + expect(placeholder.serialize()).not.toHaveProperty('size') + }) }) test('should configure inputs correctly', () => { diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index c2121abf0aa..f4e1863e1cc 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -3743,6 +3743,27 @@ export class LGraphNode if (!this.collapsible && !force) return if (!this.graph) throw new NullGraphError() this.graph.incrementVersion() + + // A missing-node placeholder's live size is the only record of it, so it + // has to track both directions before the flag flips: Vue nodes mode + // measures whichever card is currently rendered, and the other card's + // measurement only lands a frame later, so reading `this.size` after the + // flip risks the card being left. + const recordedSerialization = this.last_serialization + if ( + this.constructor === LGraphNode && + recordedSerialization?.size != null + ) { + if (this.flags.collapsed) { + this.size = recordedSerialization.size + } else { + this.last_serialization = { + ...recordedSerialization, + size: [this.size[0], this.size[1]] + } + } + } + this.flags.collapsed = !this.flags.collapsed this.setDirtyCanvas(true, true) } From c5216d54e9abf0fdceed2b80ac3fc5310b119512 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Thu, 27 Aug 2026 15:40:45 -0700 Subject: [PATCH 5/7] fix: preserve a live title, flags and colour when serializing missing-node placeholders (BE-8848) (#15719) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **STACKED — merging lands on `matt/fe-1817-serialize-placeholder-size` (owned by @mattmillerai, PR #15713), NOT `main`.** Review/merge #15713 first; this PR's diff is only the commit on top. ## ELI-5 If ComfyUI can't find a node's code, it draws a grey stand-in and remembers the node's original text so nothing is lost when you install the missing pack later. You could rename that stand-in, colour it, reshape it, collapse it or pin it — and every one of those edits vanished the next time you opened the workflow, because saving replayed the remembered text verbatim. Now your edits stick, and a stand-in you never touched still saves what it loaded. ## Summary `serialize()`'s missing-node placeholder branch replays `last_serialization` and overrides only `mode`/`pos` (and, on the branch this stacks on, `size`). This extends that override to every user-decoration field — `title`, `flags`, `color`, `bgcolor`, `boxcolor`, `shape` — so a rename, recolour, reshape, collapse or pin on a placeholder survives save + reload. ## Changes - **What**: In the placeholder branch of `LGraphNode.serialize()`, the live node now wins for `title`, `flags`, `color`, `bgcolor`, `boxcolor` and `shape`. `configure()` copies those from the file onto the live node at load, so they can only diverge from the file when the user deliberately edited them — live-wins can never lose information the file had. - **How**: the mirrored keys are `omit`ted from the replayed serialization and the live values spread back over it, so "a cleared decoration cannot resurrect the file's recorded value" holds for every key by construction instead of one `delete` branch at a time. `title` reuses the normal path's `this.title !== this.constructor.title` guard so a file with no title does not gain one on round-trip. - **`flags` is always emitted.** `zComfyNode.flags` is required and `zFlags` is a non-nullable object, so round-tripping the absence of `flags` produced a node the workflow schema rejects — a validation alert, and `tryFixLinks` repair skipped on the next open. `{}` faithfully represents "no flags" and is schema-valid. `o.flags` is `cloneObject(this.flags)`, so `pinned` and `collapsed` ride along and the replayed object no longer aliases `last_serialization.flags`. - **Not changed**: `type`, `inputs`, `outputs`, `properties`, `widgets_values`, `widgets_values_named` still replay from the file — no node definition exists to regenerate them. The `widgets_values` index asymmetry is separately tracked (#15669 / PR #15688) and is not bundled here. - **Breaking**: none for consumers. The one serialization difference for an untouched placeholder is that a file which recorded no `flags` key now round-trips as `"flags": {}` — deliberate, and the reason `LGraph.test.ts.snap`'s v0.4 fixture gains that key. ## Review Focus **Chesterton's-fence check on `flags`.** This flips a field that previously always replayed from the file, so I read the history first. `bdf6d4dea2` ("Allow updating position and mode on missing nodes", #6792, AustinMroz) introduced the replay to keep the "last known good" serialization so the node still works once the missing pack is installed, and added `pos`/`mode` as the "small and safe changes" that should not be discarded. The decoration fields are the same class — pure decoration that cannot affect whether the node resolves when the pack is reinstalled — so extending the same override is consistent with that intent rather than against it. **The `flags`-absence round-trip was dropped after review.** An earlier revision emitted `flags` only when the file had one or the live node had a flag to record, to keep the v0.4 fixture snapshot byte-identical. That is the wrong trade: `flags` is schema-required, so preserving the absence preserves an invalid node. The snapshot now records `"flags": {}` and the placeholder emits a document the schema accepts. **`shape` and `boxcolor` were folded in after review.** They were initially scoped out as a separate call about decoration-vs-geometry. They are serialized by the normal path and user-mutable on a placeholder — `useNodeCustomization.applyShape` (`src/composables/graph/useNodeCustomization.ts:113`) and `LGraphCanvas.onMenuNodeShapes` both act on any selected `LGraphNode` with no `has_errors` gate — so leaving them out kept the exact data-loss class this PR closes. They are decoration by the same Chesterton's-fence argument as the rest. **Known adjacent gap, not fixed here (follow-up proposed).** `last_serialization` is a load-time snapshot that is never refreshed, and two consumers read it directly rather than through `serialize()`: `useNodeReplacement.replaceWithMapping` (`src/platform/nodeReplacement/useNodeReplacement.ts:177`) applies `serialized.title` from it, so a renamed placeholder reverts to the file's title once the missing pack is installed; and resizing an expanded placeholder then collapsing it serializes the stale recorded size. Both need a refresh policy that interacts with #15713's deliberate collapsed-size rule, so they are tracked separately rather than bundled. - Refs #15628 ## Provenance - **Authored by:** agent-work loop - **Verified:** `pnpm vitest run src/lib/litegraph src/platform src/scripts src/composables` — 537 files, 8259 passed, 7 expected-fail, 5 skipped, 0 failed; `pnpm typecheck` — clean; `pnpm lint` — 0 errors (3 pre-existing warnings in unrelated files); `pnpm format` — no changes outside the two edited files. `LGraph.test.ts.snap` intentionally updated (v0.4 fixture gains `"flags": {}`); no other snapshot moved. - **Deviations:** Two decisions from the first revision were reversed on review evidence rather than carried forward — the `flags`-absence guard (it preserved a schema-invalid document) and the exclusion of `shape`/`boxcolor` (they are user-mutable on placeholders, so excluding them left the bug open). No test asserts clearing `shape`, because `LGraphNodeProperties` instruments `shape` as an own data property that shadows the prototype accessor, so `node.shape = 'default'` stores the raw string instead of `undefined`; that is a pre-existing repo-wide quirk of the legacy string API, and the Vue path (`useNodeCustomization`) only ever assigns `RenderShape` enum values, which are all truthy. No screenshots — this is a serialization change with no visual surface. --- src/lib/litegraph/src/LGraphNode.test.ts | 154 +++++++++++++++++- src/lib/litegraph/src/LGraphNode.ts | 60 ++++++- .../src/__snapshots__/LGraph.test.ts.snap | 1 + .../useNodeReplacement.test.ts | 150 +++++++++++++++-- .../nodeReplacement/useNodeReplacement.ts | 22 ++- 5 files changed, 353 insertions(+), 34 deletions(-) diff --git a/src/lib/litegraph/src/LGraphNode.test.ts b/src/lib/litegraph/src/LGraphNode.test.ts index e893a534b97..6adc9c19159 100644 --- a/src/lib/litegraph/src/LGraphNode.test.ts +++ b/src/lib/litegraph/src/LGraphNode.test.ts @@ -9,15 +9,16 @@ import type { } from '@/lib/litegraph/src/litegraph' import type { Rect } from '@/lib/litegraph/src/interfaces' import { layoutStore } from '@/renderer/core/layout/store/layoutStore' -import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' import { BaseWidget } from '@/lib/litegraph/src/widgets/BaseWidget' import { LGraphNode, LiteGraph, LGraph, + LGraphCanvas, NodeInputSlot, - NodeOutputSlot + NodeOutputSlot, + RenderShape } from '@/lib/litegraph/src/litegraph' import { test } from './__fixtures__/testExtensions' @@ -182,15 +183,158 @@ describe('LGraphNode', () => { expect(serialized).not.toHaveProperty('size') }) - test('keeps the recorded size while collapsed, since flags are replayed from the file', () => { + test('keeps the recorded size while collapsed, since a placeholder cannot re-derive an expanded one', () => { const placeholder = createPlaceholder({ flags: { collapsed: false } }) - placeholder.flags.collapsed = true + new LGraph().add(placeholder) + placeholder.collapse(true) placeholder.setSize([80, 30]) const serialized = placeholder.serialize() expect(serialized.size).toEqual([140, 60]) - expect(serialized.flags).toEqual({ collapsed: false }) + expect(serialized.flags).toEqual({ collapsed: true }) + }) + + test('records the size it was collapsed from, so a resize survives collapsing', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + + const serialized = placeholder.serialize() + + expect(serialized.size).toEqual([777, 666]) + expect(serialized.flags).toEqual({ collapsed: true }) + }) + + test('does not invent a recorded size on collapse when the file recorded none', () => { + const placeholder = createPlaceholder() + delete (placeholder.last_serialization as Partial).size + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + + expect(placeholder.serialize()).not.toHaveProperty('size') + }) + + test('restores the recorded size when expanding, rather than serializing the collapsed card measurement', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + placeholder.setSize([80, 30]) + placeholder.collapse() + + expect(placeholder.last_serialization?.size).toEqual([777, 666]) + expect(placeholder.serialize().size).toEqual([777, 666]) + }) + + test('keeps the recorded size through an expand/collapse pair made before the card is re-measured', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + placeholder.setSize([80, 30]) + placeholder.collapse() + placeholder.collapse() + + expect(placeholder.serialize().size).toEqual([777, 666]) + }) + + test('replaces the recorded serialization rather than mutating the object it was configured from', () => { + const placeholder = createPlaceholder({ flags: { collapsed: false } }) + const configuredFrom = placeholder.last_serialization! + new LGraph().add(placeholder) + placeholder.setSize([777, 666]) + placeholder.collapse() + + expect(configuredFrom.size).toEqual([140, 60]) + expect(placeholder.last_serialization?.size).toEqual([777, 666]) + }) + + test('carries a live pin through', () => { + const placeholder = createPlaceholder() + new LGraph().add(placeholder) + placeholder.pin(true) + + expect(placeholder.serialize().flags).toEqual({ pinned: true }) + }) + + test('carries a live rename through', () => { + const placeholder = createPlaceholder({ title: 'Recorded Title' }) + placeholder.title = 'renamed' + + expect(placeholder.serialize().title).toEqual('renamed') + }) + + test('carries a live recolour through, over the recorded colours', () => { + const placeholder = createPlaceholder({ + color: '#111', + bgcolor: '#222' + }) + placeholder.setColorOption(LGraphCanvas.node_colors.red) + + const serialized = placeholder.serialize() + + expect(serialized.color).toEqual(LGraphCanvas.node_colors.red.color) + expect(serialized.bgcolor).toEqual(LGraphCanvas.node_colors.red.bgcolor) + }) + + test('drops the recorded colours when the live colour is cleared', () => { + const placeholder = createPlaceholder({ + color: '#111', + bgcolor: '#222' + }) + placeholder.setColorOption(null) + + const serialized = placeholder.serialize() + + expect(serialized).not.toHaveProperty('color') + expect(serialized).not.toHaveProperty('bgcolor') + }) + + test('carries a live shape and box colour through, over the recorded ones', () => { + const placeholder = createPlaceholder({ + shape: RenderShape.BOX, + boxcolor: '#333' + }) + placeholder.shape = RenderShape.CARD + placeholder.boxcolor = '#444' + + const serialized = placeholder.serialize() + + expect(serialized.shape).toEqual(RenderShape.CARD) + expect(serialized.boxcolor).toEqual('#444') + }) + + test('round-trips an untouched placeholder that recorded decorations', () => { + const recorded = { + title: 'Recorded Title', + flags: { collapsed: true, pinned: true }, + color: '#111', + bgcolor: '#222', + boxcolor: '#333', + shape: RenderShape.CARD + } + const serialized = createPlaceholder(recorded).serialize() + + expect(serialized).toMatchObject(recorded) + }) + + test('round-trips an untouched placeholder that recorded no decorations', () => { + const serialized = createPlaceholder().serialize() + + expect(serialized).not.toHaveProperty('title') + expect(serialized).not.toHaveProperty('color') + expect(serialized).not.toHaveProperty('bgcolor') + expect(serialized.flags).toEqual({}) + }) + + test('emits empty flags when the recorded serialization has none, since the schema requires the key', () => { + const placeholder = createPlaceholder() + delete (placeholder.last_serialization as Partial).flags + + expect(placeholder.serialize().flags).toEqual({}) }) test('records the size it was collapsed from, so a resize survives collapsing', () => { diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index f4e1863e1cc..4c5525fc854 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1,3 +1,4 @@ +import { omit, pickBy } from 'es-toolkit' import { toValue } from 'vue' import { @@ -149,6 +150,18 @@ import type { WidgetTypeMap } from './widgets/widgetMap' export type { NodeProperty } from '@/types/nodeState' +/** + * Serialised keys a missing-node placeholder mirrors from the live node rather + * than replaying from the file it was loaded with. + */ +const PLACEHOLDER_LIVE_DECORATIONS = [ + 'title', + 'color', + 'bgcolor', + 'boxcolor', + 'shape' +] as const satisfies readonly (keyof ISerialisedNode)[] + interface INodePropertyInfo { name?: string type?: string @@ -1224,11 +1237,34 @@ export class LGraphNode const carriesLiveSize = state.lastSerialization.size != null && !state.flags.collapsed + // The live node owns its decorations, so the file's recorded values are + // dropped before whatever is set now is re-applied: skipping them + // instead would let a cleared decoration resurrect the recorded one. + // `title` mirrors the normal path's guard against the class default. + const liveDecorations = pickBy( + { + title: + state.title === this.constructor.title ? undefined : state.title, + color: state.color, + bgcolor: state.bgcolor, + boxcolor: state.boxcolor, + shape: state.shape + }, + Boolean + ) + return { - ...LiteGraph.cloneObject(state.lastSerialization), + ...omit( + LiteGraph.cloneObject(state.lastSerialization), + PLACEHOLDER_LIVE_DECORATIONS + ), mode: o.mode, pos: o.pos, - ...(carriesLiveSize && { size: o.size }) + // Required by the workflow schema, so an empty object rather than a + // missing key represents "no flags". + flags: o.flags ?? {}, + ...(carriesLiveSize && { size: o.size }), + ...liveDecorations } } @@ -3744,11 +3780,18 @@ export class LGraphNode if (!this.graph) throw new NullGraphError() this.graph.incrementVersion() - // A missing-node placeholder's live size is the only record of it, so it - // has to track both directions before the flag flips: Vue nodes mode - // measures whichever card is currently rendered, and the other card's - // measurement only lands a frame later, so reading `this.size` after the - // flip risks the card being left. + // A missing-node placeholder has no definition to re-derive an expanded + // size from, so `last_serialization.size` is the sole record of it and has + // to track the live node in BOTH directions. Both halves run before the + // flag flips, because in Vue nodes mode `size` is a DOM measurement of + // whichever card is currently rendered and the other card's measurement + // only lands a frame later: + // collapsing captures `size` while it still measures the expanded card; + // expanding restores `size`, which still measures the collapsed card, so + // that neither a serialize() inside that window nor an immediate second + // collapse can substitute the collapsed dimensions for the recorded ones. + // A recorded serialization without a size still gets none, matching + // `serialize()`. const recordedSerialization = this.last_serialization if ( this.constructor === LGraphNode && @@ -3757,6 +3800,9 @@ export class LGraphNode if (this.flags.collapsed) { this.size = recordedSerialization.size } else { + // Replaced rather than mutated in place: `LGraph.configure()` assigns + // `last_serialization` by reference straight out of the caller's + // workflow data, which this node does not own. this.last_serialization = { ...recordedSerialization, size: [this.size[0], this.size[1]] diff --git a/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap b/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap index 836ad17563b..48d1df305b5 100644 --- a/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap +++ b/src/lib/litegraph/src/__snapshots__/LGraph.test.ts.snap @@ -28,6 +28,7 @@ exports[`LGraph > supports schema v0.4 graphs > oldSchemaGraph 1`] = ` "links": [], "nodes": [ { + "flags": {}, "id": 1, "mode": 0, "pos": [ diff --git a/src/platform/nodeReplacement/useNodeReplacement.test.ts b/src/platform/nodeReplacement/useNodeReplacement.test.ts index 5cd5bc09408..615c2137dbb 100644 --- a/src/platform/nodeReplacement/useNodeReplacement.test.ts +++ b/src/platform/nodeReplacement/useNodeReplacement.test.ts @@ -1,4 +1,5 @@ import { fromAny } from '@total-typescript/shoehorn' +import { omit, pickBy } from 'es-toolkit' import { beforeEach, describe, expect, it, vi } from 'vitest' import { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' @@ -7,9 +8,13 @@ import { canTransferReplacementOwnership, transferReplacementOwnership } from '@/core/graph/nodeShell/nodeShellState' +import type { Point } from '@/lib/litegraph/src/interfaces' import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' import { LiteGraph } from '@/lib/litegraph/src/litegraph' -import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' +import { + NodeSlotType, + RenderShape +} from '@/lib/litegraph/src/types/globalEnums' import type { PendingWarnings } from '@/platform/workflow/management/stores/comfyWorkflow' import { useLinkStore } from '@/stores/linkStore' import { usePreviewExposureStore } from '@/stores/previewExposureStore' @@ -22,6 +27,15 @@ import { widgetId } from '@/types/widgetId' import type { UUID } from '@/utils/uuid' import type { NodeReplacement } from './types' +/** Mirrors `PLACEHOLDER_LIVE_DECORATIONS` in LGraphNode. */ +const PLACEHOLDER_LIVE_DECORATIONS = [ + 'title', + 'color', + 'bgcolor', + 'boxcolor', + 'shape' +] as const + vi.mock('@/lib/litegraph/src/litegraph', async (importOriginal) => { const actual = await importOriginal>() return { @@ -181,7 +195,7 @@ function createPlaceholderNode( outputs: { name: string; links: number[] | null }[] = [], graph?: LGraph ): LGraphNode { - return fromAny({ + const node = fromAny({ id, type, pos: [100, 200], @@ -204,20 +218,33 @@ function createPlaceholderNode( }, inputs: inputs.map((i) => ({ ...i, type: 'IMAGE' })), outputs: outputs.map((o) => ({ ...o, type: 'IMAGE' })), - graph: graph ?? null, - serialize: vi.fn(() => ({ - id, - type, - pos: [100, 200], - size: [200, 100], - flags: {}, - order: 0, - mode: 0, - inputs: inputs.map((i) => ({ ...i, type: 'IMAGE' })), - outputs: outputs.map((o) => ({ ...o, type: 'IMAGE' })), - widgets_values: [] - })) + graph: graph ?? null }) + + // Mirrors the placeholder branch of LGraphNode.serialize(): the loaded file's + // structural fields replayed verbatim, with the recorded decorations dropped + // before the live ones are re-applied, so a cleared decoration cannot + // resurrect the recorded one. + node.serialize = vi.fn(() => ({ + ...omit(node.last_serialization!, PLACEHOLDER_LIVE_DECORATIONS), + mode: node.mode, + pos: [node.pos[0], node.pos[1]] satisfies Point, + ...pickBy( + { + title: + node.title === (node.constructor as { title?: string }).title + ? undefined + : node.title, + color: node.color, + bgcolor: node.bgcolor, + boxcolor: node.boxcolor, + shape: node.shape + }, + Boolean + ) + })) + + return node } function createNewNode( @@ -1728,5 +1755,98 @@ describe('useNodeReplacement', () => { expect(dispatch).toHaveBeenCalledWith('node:added', { node: newNode }) }) + + it('carries the live title and decorations of a renamed placeholder onto the replacement', () => { + const placeholder = createPlaceholderNode(1, 'OldType') + Object.assign(placeholder.last_serialization!, { + title: 'Title From File', + color: '#000000', + bgcolor: '#111111', + boxcolor: '#222222', + shape: RenderShape.BOX + }) + Object.assign(placeholder, { + title: 'My Rename', + color: '#123456', + bgcolor: '#654321', + boxcolor: '#abcdef', + shape: RenderShape.ROUND + }) + const graph = createMockGraph([placeholder]) + placeholder.graph = graph + Object.assign(app, { rootGraph: graph }) + + vi.mocked(collectAllNodes).mockReturnValue([placeholder]) + + const newNode = createNewNode() + vi.mocked(LiteGraph.createNode).mockReturnValue(newNode) + + const { replaceNodesInPlace } = useNodeReplacement() + replaceNodesInPlace([ + makeMissingNodeType('OldType', { + new_node_id: 'NewType', + old_node_id: 'OldType', + old_widget_ids: null, + input_mapping: null, + output_mapping: null + }) + ]) + + expect(newNode.title).toBe('My Rename') + expect(newNode.color).toBe('#123456') + expect(newNode.bgcolor).toBe('#654321') + expect(newNode.boxcolor).toBe('#abcdef') + expect(newNode.shape).toBe(RenderShape.ROUND) + }) + + it('does not resurrect a file decoration the placeholder no longer carries', () => { + const placeholder = createPlaceholderNode(1, 'OldType') + Object.assign(placeholder.last_serialization!, { + title: 'Title From File', + color: '#000000', + bgcolor: '#111111', + boxcolor: '#222222', + shape: RenderShape.BOX + }) + Object.assign(placeholder, { + title: undefined, + color: undefined, + bgcolor: '', + boxcolor: undefined, + shape: undefined + }) + const graph = createMockGraph([placeholder]) + placeholder.graph = graph + Object.assign(app, { rootGraph: graph }) + + vi.mocked(collectAllNodes).mockReturnValue([placeholder]) + + const newNode = createNewNode() + Object.assign(newNode, { + title: 'New Node', + color: undefined, + bgcolor: undefined, + boxcolor: undefined, + shape: undefined + }) + vi.mocked(LiteGraph.createNode).mockReturnValue(newNode) + + const { replaceNodesInPlace } = useNodeReplacement() + replaceNodesInPlace([ + makeMissingNodeType('OldType', { + new_node_id: 'NewType', + old_node_id: 'OldType', + old_widget_ids: null, + input_mapping: null, + output_mapping: null + }) + ]) + + expect(newNode.title).toBe('New Node') + expect(newNode.color).toBeUndefined() + expect(newNode.bgcolor).toBeUndefined() + expect(newNode.boxcolor).toBeUndefined() + expect(newNode.shape).toBeUndefined() + }) }) }) diff --git a/src/platform/nodeReplacement/useNodeReplacement.ts b/src/platform/nodeReplacement/useNodeReplacement.ts index 10b36390838..6eaa1e59edb 100644 --- a/src/platform/nodeReplacement/useNodeReplacement.ts +++ b/src/platform/nodeReplacement/useNodeReplacement.ts @@ -240,7 +240,8 @@ function replaceWithMapping( newNode: LGraphNode, replacement: NodeReplacement, nodeGraph: LGraph, - idx: number + idx: number, + serialized: ISerialisedNode ): boolean { const order = node.order newNode.id = node.id @@ -259,8 +260,11 @@ function replaceWithMapping( return false } - const serialized = node.last_serialization ?? node.serialize() if (serialized.title != null) newNode.title = serialized.title + if (serialized.color != null) newNode.color = serialized.color + if (serialized.bgcolor != null) newNode.bgcolor = serialized.bgcolor + if (serialized.boxcolor != null) newNode.boxcolor = serialized.boxcolor + if (serialized.shape != null) newNode.shape = serialized.shape if (serialized.properties) { newNode.properties = { ...serialized.properties } if ('Node name for S&R' in newNode.properties) { @@ -475,21 +479,25 @@ export function useNodeReplacement() { replacement.input_mapping != null || replacement.output_mapping != null + // Snapshot the live node before any graph mutation: a placeholder the + // user renamed or recoloured carries those edits only on serialize() + // output, and one snapshot keeps the mapping and the value transfer + // reading the same state. + const serialized = node.serialize() + const effectiveReplacement = hasMapping ? replacement : { ...replacement, - ...generateDefaultMapping( - node.last_serialization ?? node.serialize(), - newNode - ) + ...generateDefaultMapping(serialized, newNode) } const replaced = replaceWithMapping( node, newNode, effectiveReplacement, nodeGraph, - idx + idx, + serialized ) if (!replaced) { replacementFailed = true From a617d2304ab3e0e7248eebd104c1bd51cf53504e Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Mon, 31 Aug 2026 16:00:18 -0700 Subject: [PATCH 6/7] fix: restore recorded size after placeholder error-widget auto-expand Adding the missing-node placeholder's `UNKNOWN` widgets during configure() calls addWidget() -> expandToFitContent(), which floors the node's width at 1.5x NODE_WIDTH whenever it has widgets. That silently widened `this.size` on every load, which serialize()'s new live-size passthrough then persisted, breaking round-trip for an untouched placeholder. --- src/lib/litegraph/src/LGraphNode.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index a7970a5c2e2..0860bab2d0c 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1206,6 +1206,15 @@ export class LGraphNode } finally { useWidgetValueStore().clearNodeWidgetRestoration(graphId, this.id) } + + // The missing-node error UI just added placeholder widgets via + // `onConfigure` above, which auto-expands the node to fit them + // (`addWidget` -> `expandToFitContent`). A placeholder has no + // definition to re-derive a real size from, so the recorded size — + // the sole record `serialize()` has of it — is restored afterward. + if (this.constructor === LGraphNode && info.size) { + this.size = [info.size[0], info.size[1]] + } } /** From 57e5e72462bcec24e846f5257755654d248c1881 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Mon, 31 Aug 2026 16:53:41 -0700 Subject: [PATCH 7/7] test: exercise the real placeholder serialization in the replacement tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `createPlaceholderNode` mocked `serialize()` with a hand-copy of `LGraphNode.serialize()`'s placeholder branch, so a replacement test could pass while the real serialization-to-replacement contract broke. It now builds a real `LGraphNode`, recorded and configured from one serialization object the way `LGraph.configure` builds a placeholder for an unregistered type, and lets production `serialize()` run. Doing so surfaced two places where the fake diverged from production: `NodeId` is a string, so the id assertions now compare against `toNodeId`; and `order` is graph-scoped, so a detached placeholder no longer reports the order the replacement inherited — the handover is asserted directly instead. Also adds the missing regression test for the configure-time auto-expand restore (without it the placeholder serializes 210 rather than the recorded 140), drops three tests the merge with main duplicated, and corrects a comment that still described `flags` as replayed from the file. --- src/lib/litegraph/src/LGraphNode.test.ts | 59 ++++++------- src/lib/litegraph/src/LGraphNode.ts | 6 +- .../useNodeReplacement.test.ts | 86 ++++++------------- 3 files changed, 56 insertions(+), 95 deletions(-) diff --git a/src/lib/litegraph/src/LGraphNode.test.ts b/src/lib/litegraph/src/LGraphNode.test.ts index ed5e130834f..bd760c0ad0b 100644 --- a/src/lib/litegraph/src/LGraphNode.test.ts +++ b/src/lib/litegraph/src/LGraphNode.test.ts @@ -179,6 +179,29 @@ describe('LGraphNode', () => { expect(serialized.widgets_values).toEqual([512]) }) + test('restores the recorded size after configure-time widgets auto-expand the node', () => { + const lastSerialization = getMockISerialisedNode({ + type: 'UninstalledNodeType', + pos: [100, 100], + size: [140, 60], + widgets_values: [512] + }) + const placeholder = new LGraphNode('') + placeholder.last_serialization = lastSerialization + placeholder.has_errors = true + // The missing-node error UI adds one widget per recorded value from + // `onConfigure`, and `addWidget` -> `expandToFitContent` widens the + // node past the size the file recorded. + placeholder.onConfigure = function (this: LGraphNode) { + this.addWidget('number', 'UNKNOWN', 512, () => {}) + } + + placeholder.configure(lastSerialization) + + expect(Array.from(placeholder.size)).toEqual([140, 60]) + expect(placeholder.serialize().size).toEqual([140, 60]) + }) + test('does not invent a size when the recorded serialization has none', () => { const placeholder = createPlaceholder() delete (placeholder.last_serialization as Partial).size @@ -227,6 +250,9 @@ describe('LGraphNode', () => { new LGraph().add(placeholder) placeholder.setSize([777, 666]) placeholder.collapse() + // Simulate the Vue nodes mode race: `size` still measures the collapsed + // card immediately after expanding, before the next ResizeObserver tick + // lands the real measurement. placeholder.setSize([80, 30]) placeholder.collapse() @@ -341,39 +367,6 @@ describe('LGraphNode', () => { expect(placeholder.serialize().flags).toEqual({}) }) - - test('records the size it was collapsed from, so a resize survives collapsing', () => { - const placeholder = createPlaceholder({ flags: { collapsed: false } }) - new LGraph().add(placeholder) - placeholder.setSize([777, 666]) - placeholder.collapse() - - expect(placeholder.serialize().size).toEqual([777, 666]) - }) - - test('restores the recorded size when expanding, rather than serializing a stale measurement', () => { - const placeholder = createPlaceholder({ flags: { collapsed: false } }) - new LGraph().add(placeholder) - placeholder.setSize([777, 666]) - placeholder.collapse() - // Simulate the Vue nodes mode race: `size` still measures the - // collapsed card immediately after expanding, before the next - // ResizeObserver tick lands the real measurement. - placeholder.setSize([80, 30]) - placeholder.collapse() - - expect(placeholder.serialize().size).toEqual([777, 666]) - }) - - test('does not invent a recorded size on collapse when the file recorded none', () => { - const placeholder = createPlaceholder({ flags: { collapsed: false } }) - delete (placeholder.last_serialization as Partial).size - new LGraph().add(placeholder) - placeholder.setSize([777, 666]) - placeholder.collapse() - - expect(placeholder.serialize()).not.toHaveProperty('size') - }) }) test('should configure inputs correctly', () => { diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 0860bab2d0c..9f29ecc1f1e 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -1241,9 +1241,9 @@ export class LGraphNode if (this.constructor === LGraphNode && state.lastSerialization) { // Only an expanded placeholder whose file recorded a size has a live // size worth keeping. Vue nodes mode drops the CSS width/height floors - // on collapse, so a collapsed node's size is a measurement of the - // collapsed card, and `flags` is replayed from the file — keeping both - // would pair `collapsed: false` with collapsed dimensions. With no + // on collapse, so a collapsed node's `size` measures the collapsed card + // rather than the expanded geometry a reload has to restore — which + // `collapse()` has already captured into `last_serialization`. With no // recorded size there is no definition to compute a real one from, so // keeping the live size would invent a dimension the file never had. const carriesLiveSize = diff --git a/src/platform/nodeReplacement/useNodeReplacement.test.ts b/src/platform/nodeReplacement/useNodeReplacement.test.ts index fcf4d476c10..22eca396b0b 100644 --- a/src/platform/nodeReplacement/useNodeReplacement.test.ts +++ b/src/platform/nodeReplacement/useNodeReplacement.test.ts @@ -1,5 +1,4 @@ import { fromAny } from '@total-typescript/shoehorn' -import { omit, pickBy } from 'es-toolkit' import { beforeEach, describe, expect, it, vi } from 'vitest' import { CustomEventTarget } from '@/lib/litegraph/src/infrastructure/CustomEventTarget' @@ -8,9 +7,10 @@ import { canTransferReplacementOwnership, transferReplacementOwnership } from '@/core/graph/nodeShell/nodeShellState' -import type { Point } from '@/lib/litegraph/src/interfaces' -import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' -import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { ISerialisedNode } from '@/lib/litegraph/src/types/serialisation' +import type { Point, Size } from '@/lib/litegraph/src/interfaces' +import type { LGraph } from '@/lib/litegraph/src/litegraph' +import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import { NodeSlotType, RenderShape @@ -27,15 +27,6 @@ import { widgetId } from '@/types/widgetId' import type { UUID } from '@/utils/uuid' import type { NodeReplacement } from './types' -/** Mirrors `PLACEHOLDER_LIVE_DECORATIONS` in LGraphNode. */ -const PLACEHOLDER_LIVE_DECORATIONS = [ - 'title', - 'color', - 'bgcolor', - 'boxcolor', - 'shape' -] as const - vi.mock('@/lib/litegraph/src/litegraph', async (importOriginal) => { const actual = await importOriginal>() return { @@ -48,7 +39,8 @@ vi.mock('@/lib/litegraph/src/litegraph', async (importOriginal) => { } }) -vi.mock('@/core/graph/nodeShell/nodeShellState', () => ({ +vi.mock('@/core/graph/nodeShell/nodeShellState', async (importOriginal) => ({ + ...(await importOriginal>()), canTransferReplacementOwnership: vi.fn(() => true), transferReplacementOwnership: vi.fn( (node: LGraphNode, replacement: LGraphNode) => { @@ -201,54 +193,28 @@ function createPlaceholderNode( outputs: { name: string; links: number[] | null }[] = [], graph?: LGraph ): LGraphNode { - const node = fromAny({ + const lastSerialization = fromAny({ id, type, - pos: [100, 200], - size: [200, 100], + pos: [100, 200] satisfies Point, + size: [200, 100] satisfies Size, + flags: {}, order: 0, mode: 0, - flags: {}, - has_errors: true, - last_serialization: { - id, - type, - pos: [100, 200], - size: [200, 100], - flags: {}, - order: 0, - mode: 0, - inputs: inputs.map((i) => ({ ...i, type: 'IMAGE' })), - outputs: outputs.map((o) => ({ ...o, type: 'IMAGE' })), - widgets_values: [] - }, inputs: inputs.map((i) => ({ ...i, type: 'IMAGE' })), outputs: outputs.map((o) => ({ ...o, type: 'IMAGE' })), - graph: graph ?? null + widgets_values: [] }) - // Mirrors the placeholder branch of LGraphNode.serialize(): the loaded file's - // structural fields replayed verbatim, with the recorded decorations dropped - // before the live ones are re-applied, so a cleared decoration cannot - // resurrect the recorded one. - node.serialize = vi.fn(() => ({ - ...omit(node.last_serialization!, PLACEHOLDER_LIVE_DECORATIONS), - mode: node.mode, - pos: [node.pos[0], node.pos[1]] satisfies Point, - ...pickBy( - { - title: - node.title === (node.constructor as { title?: string }).title - ? undefined - : node.title, - color: node.color, - bgcolor: node.bgcolor, - boxcolor: node.boxcolor, - shape: node.shape - }, - Boolean - ) - })) + // A real node, recorded and configured from one object the way + // `LGraph.configure` builds a placeholder for an unregistered type, so these + // tests exercise the production `serialize()` placeholder branch rather than + // a copy of it. + const node = new LGraphNode('', type) + node.last_serialization = lastSerialization + node.has_errors = true + node.configure(lastSerialization) + node.graph = graph ?? null return node } @@ -334,7 +300,7 @@ describe('useNodeReplacement', () => { expect(result).toEqual(['Load3DAnimation']) expect(newNode.configure).not.toHaveBeenCalled() - expect(newNode.id).toBe(1) + expect(newNode.id).toBe(toNodeId(1)) expect(newNode.has_errors).toBe(false) }) @@ -798,7 +764,7 @@ describe('useNodeReplacement', () => { ]) expect(newNode.widgets![0].value).toBe(512) - expect(setNodeId).toHaveBeenCalledWith(1) + expect(setNodeId).toHaveBeenCalledWith(toNodeId(1)) }) it('should skip replacement when new node type is not registered', () => { @@ -958,14 +924,16 @@ describe('useNodeReplacement', () => { }) ]) - expect(newNode.id).toBe(42) + expect(newNode.id).toBe(toNodeId(42)) expect(replacementGeometryBeforeTransfer).toEqual([ { pos: [0, 0], size: [100, 50] } ]) expect(newNode.pos).toEqual([300, 400]) expect(newNode.size).toEqual([250, 150]) expect(newNode.order).toBe(6) - expect(placeholder.order).toBe(6) + // Order is graph-scoped, and replacement detaches the placeholder, so + // the handover is complete rather than shared. + expect(placeholder.graph).toBeNull() expect(graph._nodes[0]).toBe(newNode) expect(placeholder.onRemoved).toHaveBeenCalledOnce() }) @@ -1112,7 +1080,7 @@ describe('useNodeReplacement', () => { ]) // Default mapping transfers connections and widget values by name - expect(newNode.id).toBe(13) + expect(newNode.id).toBe(toNodeId(13)) expect(link.target_id).toBe(toNodeId(13)) expect(link.target_slot).toBe(0) expect(outLink.origin_id).toBe(toNodeId(13))