mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 23:50:08 +00:00
fix: add error handling and race condition guard to syncNodeImgs
This commit is contained in:
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user