From ca25ba382a550c714f207deffdda8747b2de03dc Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Fri, 29 May 2026 22:46:03 +0200 Subject: [PATCH] Improve initial URN local match refresh handling Modify scheduleInitialUrnLocalMatchRefresh to accept container and data parameters, track refresh tasks as an array of async functions, and use Promise.allSettled to wait for all tasks before updating the UI. This ensures that the missing models browser is refreshed only after all initial URN local match refreshes have completed, preventing UI updates during ongoing async operations. Also adjust renderMissingModel to conditionally render known download panels based on downloadSource availability. --- web/linker.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/web/linker.js b/web/linker.js index 0bf7a6d..a99a259 100644 --- a/web/linker.js +++ b/web/linker.js @@ -1276,21 +1276,31 @@ class LinkerManagerDialog extends ComfyDialog { } } - scheduleInitialUrnLocalMatchRefresh(missingModels = []) { + scheduleInitialUrnLocalMatchRefresh(missingModels = [], container = null, data = null) { + const refreshTasks = []; + missingModels.forEach((missing) => { if (!missing?.is_urn || missing.__urnLocalRefreshQueued) return; if (this.getBestLocalMatch(missing, 70)) return; missing.__urnLocalRefreshQueued = true; - setTimeout(async () => { + const task = (async () => { try { await this.resolveUrnDataForMissing(missing); await this.refreshUrnLocalMatches(missing); } catch (error) { - missing.__urnLocalRefreshQueued = false; + missing.__urnLocalRefreshFailed = true; console.error('Model Linker: initial URN local match refresh error:', error); } - }, 0); + })(); + refreshTasks.push(task); + }); + + if (!refreshTasks.length || !container || !data) return; + + Promise.allSettled(refreshTasks).then(() => { + if (!container.isConnected || this.activeTab !== 'missing') return; + this.displayMissingModels(container, data); }); } @@ -5638,7 +5648,7 @@ class LinkerManagerDialog extends ComfyDialog { hasAny100Match ); this.wireMissingModelsBrowser(container, data, sortedMissingModels); - this.scheduleInitialUrnLocalMatchRefresh(sortedMissingModels); + this.scheduleInitialUrnLocalMatchRefresh(sortedMissingModels, container, data); } renderMissingModel(missing, missingIndex = 0) { @@ -5755,15 +5765,15 @@ class LinkerManagerDialog extends ComfyDialog { const downloadSource = missing.download_source; const urnDownloadId = `urn-download-${missing.node_id}-${missing.widget_index}`; - if (perfectMatches.length > 0) { + if (downloadSource && downloadSource.url) { + html += this.renderKnownDownloadPanel(missing, downloadSource); + } else if (perfectMatches.length > 0) { // Has perfect local match - download not needed, but allow online re-check. html += `
`; html += this.renderSearchControls(missing, { buttonText: 'Search Online' }); html += this.renderDownloadTargetControls(missing, missing.category || 'checkpoints'); html += `
`; html += `
`; - } else if (downloadSource && downloadSource.url) { - html += this.renderKnownDownloadPanel(missing, downloadSource); } else if (missing.is_urn) { html += `
`; html += `
Resolving CivitAI download for this URN...
`;