Fix race when creating loader node to handle pasted media (#2799)

This commit is contained in:
bymyself
2025-03-02 08:49:09 -07:00
committed by GitHub
parent b1713b4c80
commit 0aef39ceee
2 changed files with 8 additions and 3 deletions

View File

@@ -20,6 +20,11 @@ interface NodePreviewOptions<T extends MediaElement> {
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 = <T extends MediaElement>(
/**
* 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) => {

View File

@@ -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 }