Skip to content

Commit 6777c3b

Browse files
committed
fix: clear stores under incoming graph ids
Amp-Thread-ID: https://ampcode.com/threads/T-01a02705-02f3-70c9-ae5b-8ea6c2a3cac2
1 parent 17fb304 commit 6777c3b

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/lib/litegraph/src/LGraph.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,47 @@ describe('Graph Clearing and Callbacks', () => {
886886
[]
887887
)
888888
})
889+
890+
test('configure clears state already stored under the incoming graph id', () => {
891+
const incoming = new LGraph()
892+
const incomingId = 'graph-configure-cleanup' as UUID
893+
incoming.id = incomingId
894+
const data = incoming.asSerialisable()
895+
const staleNodeId = toNodeId(77)
896+
const staleWidgetId = widgetId(incomingId, staleNodeId, 'seed')
897+
useWidgetValueStore().registerWidget(staleWidgetId, {
898+
type: 'number',
899+
value: 1,
900+
options: {}
901+
})
902+
usePreviewExposureStore().addExposure(incomingId, String(staleNodeId), {
903+
sourceNodeId: '10',
904+
sourcePreviewName: '$$canvas-image-preview'
905+
})
906+
layoutStore.applyOperation({
907+
type: 'createNode',
908+
graphId: incomingId,
909+
nodeId: staleNodeId,
910+
layout: {
911+
id: staleNodeId,
912+
position: { x: 0, y: 0 },
913+
size: { width: 100, height: 100 },
914+
zIndex: 1,
915+
visible: true,
916+
bounds: { x: 0, y: 0, width: 100, height: 100 }
917+
},
918+
timestamp: Date.now(),
919+
source: LayoutSource.Canvas
920+
})
921+
922+
new LGraph().configure(data)
923+
924+
expect(useWidgetValueStore().getWidget(staleWidgetId)).toBeUndefined()
925+
expect(
926+
usePreviewExposureStore().getExposures(incomingId, String(staleNodeId))
927+
).toEqual([])
928+
expect(layoutStore.getNodeLayout(incomingId, staleNodeId)).toBeNull()
929+
})
889930
})
890931

891932
describe('node:before-removed event', () => {

src/lib/litegraph/src/LGraph.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,9 +2817,12 @@ export class LGraph
28172817
if (options.clearGraph) {
28182818
const topologyScope = graphScopeOf(this)
28192819
if (this.isRootGraph) {
2820+
usePreviewExposureStore().clearGraph(this.id)
2821+
useWidgetValueStore().clearGraph(this.id)
28202822
useLinkStore().clearGraph(topologyScope.rootGraphId)
28212823
useRerouteStore().clearGraph(topologyScope.rootGraphId)
28222824
useNodeDataStore().clearGraph(this.id)
2825+
layoutStore.clearGraph(this.id)
28232826
} else {
28242827
useLinkStore().clearOwner(topologyScope)
28252828
useRerouteStore().clearOwner(topologyScope)

0 commit comments

Comments
 (0)