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
60 changes: 60 additions & 0 deletions src/lib/litegraph/src/LGraphNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,66 @@ describe('LGraphNode', () => {
expect(Array.from(node.size)).toEqual([70, 80])
})

describe('missing-node placeholder serialization', () => {
function createPlaceholder(
overrides: Partial<ISerialisedNode> = {}
): LGraphNode {
const lastSerialization = getMockISerialisedNode({
type: 'UninstalledNodeType',
pos: [100, 100],
size: [140, 60],
widgets_values: [512],
...overrides
})
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.setPos(999, 888)
placeholder.setSize([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.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<ISerialisedNode>).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', () => {
const node = new LGraphNode('TestNode')
node.configure(
Expand Down
20 changes: 18 additions & 2 deletions src/lib/litegraph/src/LGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,24 @@ 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 }
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,
Comment thread
mattmillerai marked this conversation as resolved.
mode: o.mode,
Comment thread
mattmillerai marked this conversation as resolved.
pos: o.pos,
...(carriesLiveSize && { size: o.size })
}
}

if (this.inputs)
o.inputs = this.inputs.map((input) => inputAsSerialisable(input))
Expand Down
Loading