fix: add error handling and race condition guard to syncNodeImgs

This commit is contained in:
bymyself
2025-12-13 02:41:19 -08:00
parent 45ec11cdbe
commit 62d278c5e6

View File

@@ -43,6 +43,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
const { executionIdToNodeLocatorId } = useExecutionStore()
const scheduledRevoke: Record<NodeLocatorId, { stop: () => void }> = {}
const latestOutput = ref<string[]>([])
const nodeLoadIds = new WeakMap<LGraphNode, number>()
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]
}