From 6dc4a3ed1e8141e1e66d9a9061eee8a0c9d83e9c Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 4 Mar 2026 20:03:26 -0800 Subject: [PATCH] refactor(changeTracker): use shared clone util and centralize nodeOutputs snapshot (#9387) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Follow-up to #9380. Replaces local `clone()` with shared util and centralizes output snapshotting. ## Changes - **What**: Replaced local `JSON.parse(JSON.stringify)` clone in `changeTracker.ts` with shared `clone()` from `@/scripts/utils` (prefers `structuredClone` with JSON fallback). Added `snapshotOutputs()` to `useNodeOutputStore` as symmetric counterpart to existing `restoreOutputs()`, and wired `changeTracker.store()` to use it. - **Breaking**: None ## Review Focus Symmetry between `snapshotOutputs()` and `restoreOutputs()` in the node output store. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9387-refactor-changeTracker-use-shared-clone-util-and-centralize-nodeOutputs-snapshot-3196d73d365081a289c3cb414f57929e) by [Unito](https://www.unito.io) --- src/scripts/changeTracker.ts | 2 +- src/stores/imagePreviewStore.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/scripts/changeTracker.ts b/src/scripts/changeTracker.ts index 0331079cd9..d098ce763b 100644 --- a/src/scripts/changeTracker.ts +++ b/src/scripts/changeTracker.ts @@ -77,7 +77,7 @@ export class ChangeTracker { scale: app.canvas.ds.scale, offset: [app.canvas.ds.offset[0], app.canvas.ds.offset[1]] } - this.nodeOutputs = clone(app.nodeOutputs) + this.nodeOutputs = useNodeOutputStore().snapshotOutputs() const navigation = useSubgraphNavigationStore().exportState() // Always store the navigation state, even if empty (root level) this.subgraphState = { navigation } diff --git a/src/stores/imagePreviewStore.ts b/src/stores/imagePreviewStore.ts index a01ccfe8a9..8ef589694a 100644 --- a/src/stores/imagePreviewStore.ts +++ b/src/stores/imagePreviewStore.ts @@ -13,6 +13,7 @@ import type { import { appendCloudResParam } from '@/platform/distribution/cloudPreviewUtil' import { api } from '@/scripts/api' import { app } from '@/scripts/app' +import { clone } from '@/scripts/utils' import type { NodeLocatorId } from '@/types/nodeIdentification' import { parseFilePath } from '@/utils/formatUtil' import { isAnimatedOutput, isVideoNode } from '@/utils/litegraphUtil' @@ -365,6 +366,10 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { return hadOutputs } + function snapshotOutputs(): Record { + return clone(app.nodeOutputs) + } + function restoreOutputs( outputs: Record ) { @@ -455,6 +460,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { revokeAllPreviews, revokeSubgraphPreviews, removeNodeOutputs, + snapshotOutputs, restoreOutputs, resetAllOutputsAndPreviews,