From 62d278c5e64dcaa90dc0c06279c9de2db88f1b52 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 13 Dec 2025 02:41:19 -0800 Subject: [PATCH] fix: add error handling and race condition guard to syncNodeImgs --- src/stores/imagePreviewStore.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/stores/imagePreviewStore.ts b/src/stores/imagePreviewStore.ts index 44d84d100..b984151f9 100644 --- a/src/stores/imagePreviewStore.ts +++ b/src/stores/imagePreviewStore.ts @@ -43,6 +43,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { const { executionIdToNodeLocatorId } = useExecutionStore() const scheduledRevoke: Record void }> = {} const latestOutput = ref([]) + const nodeLoadIds = new WeakMap() function scheduleRevoke(locator: NodeLocatorId, cb: () => void) { scheduledRevoke[locator]?.stop() @@ -174,11 +175,21 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { const node = app.canvas?.graph?.getNodeById(nodeId) if (!node) return + const loadId = (nodeLoadIds.get(node) ?? 0) + 1 + nodeLoadIds.set(node, loadId) + const img = new Image() img.onload = () => { + if (nodeLoadIds.get(node) !== loadId) return node.imgs = [img] node.imageIndex = 0 } + img.onerror = () => { + if (nodeLoadIds.get(node) !== loadId) return + node.imgs = [] + node.imageIndex = 0 + console.warn(`[ImagePreview] Failed to load image for node ${nodeId}`) + } img.src = imageUrls[0] }