Remove Object URL usage for image previews

This commit is contained in:
Austin Mroz
2025-11-01 16:39:18 -07:00
parent dffb07c745
commit a7e8f948a6
3 changed files with 15 additions and 17 deletions

View File

@@ -177,10 +177,12 @@ const formatTime = (time?: number) => {
const onProgressPreviewReceived = async ({ detail }: CustomEvent) => {
if (props.task.displayStatus === TaskItemDisplayStatus.Running) {
if (progressPreviewBlobUrl.value) {
URL.revokeObjectURL(progressPreviewBlobUrl.value)
const reader = new FileReader()
reader.onloadend = () => {
if (typeof reader.result !== 'string') return
progressPreviewBlobUrl.value = reader.result
}
progressPreviewBlobUrl.value = URL.createObjectURL(detail)
reader.readAsDataURL(detail)
}
}

View File

@@ -719,18 +719,18 @@ export class ComfyApp {
api.addEventListener('b_preview_with_metadata', ({ detail }) => {
// Enhanced preview with explicit node context
const { blob, displayNodeId } = detail
const { setNodePreviewsByExecutionId, revokePreviewsByExecutionId } =
useNodeOutputStore()
// Ensure clean up if `executing` event is missed.
revokePreviewsByExecutionId(displayNodeId)
const blobUrl = URL.createObjectURL(blob)
// Preview cleanup is handled in progress_state event to support multiple concurrent previews
const { setNodePreviewsByExecutionId } = useNodeOutputStore()
const reader = new FileReader()
const nodeParents = displayNodeId.split(':')
for (let i = 1; i <= nodeParents.length; i++) {
setNodePreviewsByExecutionId(nodeParents.slice(0, i).join(':'), [
blobUrl
])
reader.onloadend = () => {
if (typeof reader.result !== 'string') return
for (let i = 1; i <= nodeParents.length; i++) {
setNodePreviewsByExecutionId(nodeParents.slice(0, i).join(':'), [
reader.result
])
}
}
reader.readAsDataURL(blob)
})
api.init()

View File

@@ -261,10 +261,6 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
const previews = app.nodePreviewImages[nodeLocatorId]
if (!previews?.[Symbol.iterator]) return
for (const url of previews) {
URL.revokeObjectURL(url)
}
delete app.nodePreviewImages[nodeLocatorId]
delete nodePreviewImages.value[nodeLocatorId]
}