From 0aef39ceee9a8251c35bbcb7a31e55120a2a2dd7 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 2 Mar 2025 08:49:09 -0700 Subject: [PATCH] Fix race when creating loader node to handle pasted media (#2799) --- src/composables/node/useNodeImage.ts | 9 +++++++-- src/composables/widgets/useImageUploadWidget.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/composables/node/useNodeImage.ts b/src/composables/node/useNodeImage.ts index 84e187a25..724675c8d 100644 --- a/src/composables/node/useNodeImage.ts +++ b/src/composables/node/useNodeImage.ts @@ -20,6 +20,11 @@ interface NodePreviewOptions { onFailedLoading?: () => void } +interface ShowPreviewOptions { + /** If true, blocks new loading operations until the current operation is complete. */ + block?: boolean +} + const createContainer = () => { const container = document.createElement('div') container.classList.add('comfy-img-preview') @@ -58,13 +63,13 @@ export const useNodePreview = ( /** * Displays media element(s) on the node. */ - function showPreview() { + function showPreview(options: ShowPreviewOptions = {}) { if (node.isLoading) return const outputUrls = nodeOutputStore.getNodeImageUrls(node) if (!outputUrls?.length) return - node.isLoading = true + if (options?.block) node.isLoading = true loadElements(outputUrls) .then((elements) => { diff --git a/src/composables/widgets/useImageUploadWidget.ts b/src/composables/widgets/useImageUploadWidget.ts index 4466fdb57..20804fd5e 100644 --- a/src/composables/widgets/useImageUploadWidget.ts +++ b/src/composables/widgets/useImageUploadWidget.ts @@ -106,7 +106,7 @@ export const useImageUploadWidget = () => { // No change callbacks seem to be fired on initial setting of the value requestAnimationFrame(() => { nodeOutputStore.setNodeOutputs(node, fileComboWidget.value) - showPreview() + showPreview({ block: false }) }) return { widget: uploadWidget }