Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/lib/litegraph/src/LGraphNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,63 @@ describe('LGraphNode', () => {
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<ISerialisedNode>).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)
Expand Down
31 changes: 31 additions & 0 deletions src/lib/litegraph/src/LGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3695,6 +3695,37 @@ export class LGraphNode
if (!this.collapsible && !force) return
if (!this.graph) throw new NullGraphError()
this.graph.incrementVersion()

// 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 &&
recordedSerialization?.size != null
) {
Comment thread
mattmillerai marked this conversation as resolved.
Comment thread
mattmillerai marked this conversation as resolved.
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]]
}
}
}

this.flags.collapsed = !this.flags.collapsed
this.setDirtyCanvas(true, true)
}
Expand Down
Loading