diff --git a/browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json b/browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json new file mode 100644 index 00000000000..69761f2d08c --- /dev/null +++ b/browser_tests/assets/nodes/sampler_custom_advanced_in_subgraph.json @@ -0,0 +1,136 @@ +{ + "id": "cc111111-2222-4333-8444-000000000002", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "dd999999-8888-4777-a666-555555555556", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": null }], + "title": "Sampler Subgraph", + "properties": {}, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "dd999999-8888-4777-a666-555555555556", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 2, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Sampler Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "ee888888-7777-4666-a555-444444444445", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "SamplerCustomAdvanced", + "pos": [250, 180], + "size": [260, 130], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "noise", + "name": "noise", + "type": "NOISE", + "link": null + }, + { + "localized_name": "guider", + "name": "guider", + "type": "GUIDER", + "link": null + }, + { + "localized_name": "sampler", + "name": "sampler", + "type": "SAMPLER", + "link": null + }, + { + "localized_name": "sigmas", + "name": "sigmas", + "type": "SIGMAS", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "output", + "name": "output", + "type": "LATENT", + "links": [1] + }, + { + "localized_name": "denoised_output", + "name": "denoised_output", + "type": "LATENT", + "links": null + } + ], + "properties": { "Node name for S&R": "SamplerCustomAdvanced" }, + "widgets_values": [] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json b/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json new file mode 100644 index 00000000000..832cfb13722 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-nested-with-live-sampler.json @@ -0,0 +1,184 @@ +{ + "id": "11111111-1111-4111-8111-000000000001", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "22222222-2222-4222-8222-000000000002", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": null }], + "title": "Outer Subgraph", + "properties": { "previewExposures": [] }, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "22222222-2222-4222-8222-000000000002", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 2, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Outer Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "44444444-4444-4444-8444-000000000004", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "33333333-3333-4333-8333-000000000003", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": [1] }], + "title": "Middle Subgraph", + "properties": { "previewExposures": [] }, + "widgets_values": [] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + }, + { + "id": "33333333-3333-4333-8333-000000000003", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 3, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Middle Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "55555555-5555-4555-8555-000000000005", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 3, + "type": "KSampler", + "pos": [250, 120], + "size": [280, 260], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [1] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [1, "increment", 20, 8, "euler", "normal", 1] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 3, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json b/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json new file mode 100644 index 00000000000..9822a903535 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-with-live-sampler-and-committed-output.json @@ -0,0 +1,144 @@ +{ + "id": "66666666-6666-4666-8666-000000000006", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "77777777-7777-4777-8777-000000000007", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [{ "name": "output", "type": "LATENT", "links": null }], + "title": "Sampler And Preview Subgraph", + "properties": { "previewExposures": [] }, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "77777777-7777-4777-8777-000000000007", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 3, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Sampler And Preview Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "88888888-8888-4888-8888-000000000008", + "name": "output", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 220 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "KSampler", + "pos": [250, 120], + "size": [280, 260], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [1] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [1, "increment", 20, 8, "euler", "normal", 1] + }, + { + "id": 3, + "type": "PreviewImage", + "pos": [250, 420], + "size": [220, 260], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "images", + "name": "images", + "type": "IMAGE", + "link": null + } + ], + "outputs": [], + "properties": { "Node name for S&R": "PreviewImage" }, + "widgets_values": [] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json b/browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json new file mode 100644 index 00000000000..c049ee4dd96 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-with-two-live-samplers.json @@ -0,0 +1,195 @@ +{ + "id": "aa111111-2222-4333-8444-000000000001", + "revision": 0, + "last_node_id": 1, + "last_link_id": 0, + "nodes": [ + { + "id": 1, + "type": "bb222222-3333-4444-8555-000000000002", + "pos": [400, 200], + "size": [400, 200], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { "name": "output_a", "type": "LATENT", "links": null }, + { "name": "output_b", "type": "LATENT", "links": null } + ], + "title": "Two Sampler Subgraph", + "properties": { + "previewExposures": [ + { + "name": "$$canvas-image-preview", + "sourceNodeId": "2", + "sourcePreviewName": "$$canvas-image-preview" + } + ] + }, + "widgets_values": [] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "bb222222-3333-4444-8555-000000000002", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 3, + "lastLinkId": 2, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "Two Sampler Subgraph", + "inputNode": { + "id": -10, + "bounding": [50, 200, 120, 60] + }, + "outputNode": { + "id": -20, + "bounding": [900, 200, 120, 60] + }, + "inputs": [], + "outputs": [ + { + "id": "cc333333-4444-4555-8666-000000000003", + "name": "output_a", + "type": "LATENT", + "linkIds": [1], + "pos": { "0": 920, "1": 190 } + }, + { + "id": "dd444444-5555-4666-8777-000000000004", + "name": "output_b", + "type": "LATENT", + "linkIds": [2], + "pos": { "0": 920, "1": 250 } + } + ], + "widgets": [], + "nodes": [ + { + "id": 2, + "type": "KSampler", + "pos": [250, 120], + "size": [280, 260], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [1] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [1, "increment", 20, 8, "euler", "normal", 1] + }, + { + "id": 3, + "type": "KSampler", + "pos": [250, 420], + "size": [280, 260], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": null + }, + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "link": null + }, + { + "localized_name": "latent_image", + "name": "latent_image", + "type": "LATENT", + "link": null + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": [2] + } + ], + "properties": { "Node name for S&R": "KSampler" }, + "widgets_values": [2, "increment", 20, 8, "euler", "normal", 1] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": 2, + "origin_slot": 0, + "target_id": -20, + "target_slot": 0, + "type": "LATENT" + }, + { + "id": 2, + "origin_id": 3, + "origin_slot": 0, + "target_id": -20, + "target_slot": 1, + "type": "LATENT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "ds": { "offset": [0, 0], "scale": 1 } + }, + "version": 0.4 +} diff --git a/browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts b/browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts new file mode 100644 index 00000000000..29086486bb2 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphAmbientCommittedOutputIsolation.spec.ts @@ -0,0 +1,60 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const SUBGRAPH_NODE_ID = '1' +const SUBGRAPH_NODE_TITLE = 'Sampler And Preview Subgraph' +// Neither interior node has a `previewExposures` entry: the sampler (2) is +// only ever surfaced by the ambient rollup, and the PreviewImage node (3) +// only ever receives a committed `executed` output, never a streaming +// preview frame. +const SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:2` +const PREVIEW_IMAGE_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:3` + +test.describe( + 'Subgraph ambient preview vs. committed output isolation (regression)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-live-sampler-and-committed-output' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('a committed (non-live) interior output never counts as an ambient preview, and does not mask or duplicate the live one', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = + comfyPage.vueNodes.getNodeByTitle(SUBGRAPH_NODE_TITLE) + const previewImages = subgraphNode.locator('img[src^="blob:"]') + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + + await test.step('a committed output from the unexposed PreviewImage node does not surface as an ambient preview', async () => { + exec.executed(jobId, PREVIEW_IMAGE_EXECUTION_ID, { + images: [{ filename: 'example.png', type: 'input' }] + }) + await comfyPage.nextFrame() + await expect(previewImages).toHaveCount(0) + }) + + await test.step('the live sampler preview still surfaces ambiently afterward, unaffected by the earlier committed output', async () => { + exec.latentPreview(jobId, SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(1) + }) + }) + } +) diff --git a/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts new file mode 100644 index 00000000000..25d05c32fe6 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphConcurrentPreviews.spec.ts @@ -0,0 +1,114 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const SUBGRAPH_NODE_ID = '1' +const SUBGRAPH_NODE_TITLE = 'Two Sampler Subgraph' +// Node 3 has no `properties.previewExposures` entry, simulating a KSampler +// added to the subgraph after the one-shot auto-expose already ran. +const FIRST_SAMPLER_ID = '2' +const SECOND_SAMPLER_ID = '3' +const FIRST_SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${FIRST_SAMPLER_ID}` +const SECOND_SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${SECOND_SAMPLER_ID}` + +test.describe( + 'Subgraph concurrent preview outputs', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-two-live-samplers' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('shows live previews from both concurrently-executing interior samplers, not just the exposed one', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = + comfyPage.vueNodes.getNodeByTitle(SUBGRAPH_NODE_TITLE) + const previewImages = subgraphNode.locator('img[src^="blob:"]') + + await test.step('no preview is present before execution', async () => { + await expect(previewImages).toHaveCount(0) + }) + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + + await test.step('the exposed sampler (node 2) shows its live preview', async () => { + exec.latentPreview(jobId, FIRST_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(1) + }) + + await test.step('the second, unexposed sampler (node 3) also shows its live preview, appended rather than overwriting the first', async () => { + exec.latentPreview(jobId, SECOND_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(2) + }) + + await test.step('both previews remain distinct as new frames arrive for each', async () => { + const firstSrcBefore = await previewImages.nth(0).getAttribute('src') + const secondSrcBefore = await previewImages.nth(1).getAttribute('src') + + exec.latentPreview(jobId, SECOND_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(2) + + await expect(previewImages.nth(0)).toHaveAttribute( + 'src', + firstSrcBefore! + ) + await expect(previewImages.nth(1)).not.toHaveAttribute( + 'src', + secondSrcBefore! + ) + }) + }) + + // Regression coverage for `mergeSubgraphPreviews`: it excludes an + // ambient preview only while its source node is in the host's *current* + // exposure set, not permanently at merge time. Un-promoting a still-live + // sampler's `$$canvas-image-preview` must not blank it — the ambient + // rollup immediately takes back over for any interior node that's still + // producing preview frames. + test('un-promoting a still-live sampler falls back to its ambient preview instead of disappearing', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = + comfyPage.vueNodes.getNodeByTitle(SUBGRAPH_NODE_TITLE) + const previewImages = subgraphNode.locator('img[src^="blob:"]') + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + + await test.step('the exposed sampler shows its live preview', async () => { + exec.latentPreview(jobId, FIRST_SAMPLER_EXECUTION_ID) + await expect(previewImages).toHaveCount(1) + }) + + await test.step('un-promoting its canvas image preview keeps it visible via the ambient rollup', async () => { + await comfyPage.subgraph.editor.togglePromotion(subgraphNode, { + nodeId: FIRST_SAMPLER_ID, + widgetName: '$$canvas-image-preview', + toState: false + }) + + await expect(previewImages).toHaveCount(1) + }) + }) + } +) diff --git a/browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts b/browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts new file mode 100644 index 00000000000..4255da24199 --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphNestedAmbientPreviewScope.spec.ts @@ -0,0 +1,62 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const OUTER_HOST_ID = '1' +const OUTER_HOST_TITLE = 'Outer Subgraph' +// `Middle Subgraph` (node 2, interior to the outer host) wraps the live +// sampler one level further down. Neither host has a `previewExposures` +// entry, so this fixture only passes if the ambient rollup — not the +// exposure/promotion system — is what surfaces the preview. +const MIDDLE_HOST_TITLE = 'Middle Subgraph' +const SAMPLER_EXECUTION_ID = `${OUTER_HOST_ID}:2:3` + +test.describe( + 'Subgraph ambient preview nesting scope (regression)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-nested-with-live-sampler' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('an ambient preview two levels deep bubbles to its immediate host only, not the outermost host', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const outerHost = comfyPage.vueNodes.getNodeByTitle(OUTER_HOST_TITLE) + const outerPreviewImages = outerHost.locator('img[src^="blob:"]') + + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + exec.latentPreview(jobId, SAMPLER_EXECUTION_ID) + + await test.step('the outermost host shows no preview: ambient rollup does not recurse past its immediate interior nodes', async () => { + // `useAmbientSubgraphPreviews` explicitly skips interior nodes that + // are themselves `SubgraphNode`s, so `Middle Subgraph` never + // contributes its own interior sampler's preview to `Outer Subgraph`. + await comfyPage.nextFrame() + await expect(outerPreviewImages).toHaveCount(0) + }) + + await test.step('entering the outer subgraph shows the preview on the immediate (middle) host', async () => { + await comfyPage.vueNodes.enterSubgraph(OUTER_HOST_ID) + + const middleHost = comfyPage.vueNodes.getNodeByTitle(MIDDLE_HOST_TITLE) + await expect(middleHost.locator('img[src^="blob:"]')).toHaveCount(1) + }) + }) + } +) diff --git a/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts b/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts new file mode 100644 index 00000000000..55242dc74cf --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphPreviewAllowlistGap.spec.ts @@ -0,0 +1,54 @@ +import { mergeTests } from '@playwright/test' + +import { + comfyPageFixture, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' +import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper' +import { webSocketFixture } from '@e2e/fixtures/ws' + +const test = mergeTests(comfyPageFixture, webSocketFixture) + +const SUBGRAPH_NODE_ID = '1' +// `SamplerCustomAdvanced` isn't in `CANVAS_IMAGE_PREVIEW_NODE_TYPES`, so it +// never gets a persisted `previewExposures` entry — this fixture only +// passes if the ambient rollup surfaces a live preview independent of node +// type. +const INTERIOR_SAMPLER_NODE_ID = '2' +const SAMPLER_EXECUTION_ID = `${SUBGRAPH_NODE_ID}:${INTERIOR_SAMPLER_NODE_ID}` + +test.describe( + 'Subgraph preview promotion allowlist gap (regression)', + { tag: ['@vue-nodes', '@subgraph'] }, + () => { + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow( + 'nodes/sampler_custom_advanced_in_subgraph' + ) + await comfyPage.vueNodes.waitForNodes(1) + }) + + test('promotes a mid-execution preview from a non-allowlisted interior node onto the outer SubgraphNode', async ({ + comfyPage, + getWebSocket + }) => { + const ws = await getWebSocket() + const exec = new ExecutionHelper(comfyPage, ws) + const subgraphNode = comfyPage.vueNodes.getNodeLocator(SUBGRAPH_NODE_ID) + const previewImage = subgraphNode.locator('img[src^="blob:"]') + + await test.step('no preview is present before execution', async () => { + await expect(previewImage).toHaveCount(0) + }) + + await test.step('a mid-execution preview promotes onto the outer SubgraphNode', async () => { + const jobId = await exec.run() + await comfyPage.nextFrame() + exec.executionStart(jobId) + exec.latentPreview(jobId, SAMPLER_EXECUTION_ID) + + await expect(previewImage).toBeVisible() + }) + }) + } +) diff --git a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts index 88fc034fb52..a1d36e5319c 100644 --- a/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts +++ b/browser_tests/tests/vueNodes/interactions/node/imagePreview.spec.ts @@ -181,6 +181,51 @@ test.describe('Vue Nodes Image Preview', { tag: '@vue-nodes' }, () => { await expect(subgraphNode.imagePreview.locator('img')).toHaveCount(1) } ) + + wstest( + 'Promotes a live sampler preview from inside a subgraph to the outer SubgraphNode', + async ({ comfyPage, getWebSocket }) => { + // Expected-fail until the `!lgraphNode?.isSubgraphNode()` guard in + // LGraphNode.vue is relaxed to allow rendering previews on subgraph + // nodes. Keep this test (don't delete) so it flips green automatically + // once that guard changes. + // incident-94: waiting on LGraphNode.vue:172's `!lgraphNode?.isSubgraphNode()` guard. + test.fail() + + const execution = new ExecutionHelper(comfyPage, await getWebSocket()) + const samplerNode = new VueNodeFixture( + comfyPage.vueNodes.getNodeByTitle('KSampler') + ) + const subgraphNode = new VueNodeFixture( + comfyPage.vueNodes.getNodeByTitle('New Subgraph') + ) + + await test.step('Add node', async () => { + await comfyPage.menu.topbar.newWorkflowButton.click() + await comfyPage.nextFrame() + + await comfyPage.searchBoxV2.addNode('KSampler') + await expect(samplerNode.root).toBeVisible() + }) + + await test.step('Create subgraph', async () => { + await samplerNode.title.click() + await comfyPage.page.keyboard.press('Control+Shift+e') + await expect(subgraphNode.root).toBeVisible() + }) + + await test.step('Fire live preview for the nested sampler', async () => { + const jobId = await execution.run() + execution.executionStart(jobId) + execution.executing(jobId, '2:1') + execution.latentPreview(jobId, '2:1') + }) + + await expect( + subgraphNode.root.getByAltText('Live sampling preview') + ).toBeVisible() + } + ) }) async function countColumns(locator: Locator) { diff --git a/src/composables/node/mergeSubgraphPreviews.test.ts b/src/composables/node/mergeSubgraphPreviews.test.ts new file mode 100644 index 00000000000..db2d3f36462 --- /dev/null +++ b/src/composables/node/mergeSubgraphPreviews.test.ts @@ -0,0 +1,102 @@ +import { describe, expect, it } from 'vitest' + +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' +import { + getPreviewExposureHostLocator, + usePreviewExposureStore +} from '@/stores/previewExposureStore' +import { toNodeId } from '@/types/nodeId' + +import { + getHostExposedSourceNodeIds, + mergeSubgraphPreviews +} from './mergeSubgraphPreviews' +import type { PromotedPreview } from './usePromotedPreviews' + +function preview( + sourceNodeId: number | string, + overrides: Partial = {} +): PromotedPreview { + return { + sourceNodeId: toNodeId(sourceNodeId), + sourceWidgetName: 'preview', + type: 'image', + urls: ['/view?filename=test.png'], + ...overrides + } +} + +describe(mergeSubgraphPreviews, () => { + it('returns both when there is no overlap', () => { + const promoted = [preview(1)] + const ambient = [preview(2)] + + const result = mergeSubgraphPreviews(promoted, ambient, [toNodeId(1)]) + + expect(result).toEqual([preview(1), preview(2)]) + }) + + it('drops the ambient entry for a node the host has exposed, keeping the exposure', () => { + const promoted = [preview(3, { sourceWidgetName: 'exposed-name' })] + const ambient = [preview(3, { sourceWidgetName: '$$ambient-preview' })] + + const result = mergeSubgraphPreviews(promoted, ambient, [toNodeId(3)]) + + expect(result).toEqual([preview(3, { sourceWidgetName: 'exposed-name' })]) + }) + + it('does not drop an ambient node whose id only collides with a nested exposure leaf id', () => { + // `promoted` resolved through a nested subgraph to leaf id 3 in that + // nested graph's id space. The host's own exposures (what actually + // shares this host's id space) don't include node 3, so the host's own + // interior node 3 must still surface ambiently instead of being + // suppressed by the unrelated leaf id. + const promoted = [preview(3, { sourceWidgetName: 'nested-exposure' })] + const ambient = [preview(3, { sourceWidgetName: '$$ambient-preview' })] + const hostsOwnExposedIds = [toNodeId(7)] + + const result = mergeSubgraphPreviews(promoted, ambient, hostsOwnExposedIds) + + expect(result).toEqual([ + preview(3, { sourceWidgetName: 'nested-exposure' }), + preview(3, { sourceWidgetName: '$$ambient-preview' }) + ]) + }) + + it('returns promoted unchanged when there are no ambient previews', () => { + const promoted = [preview(1)] + + const result = mergeSubgraphPreviews(promoted, [], []) + + expect(result).toEqual(promoted) + }) +}) + +describe(getHostExposedSourceNodeIds, () => { + it("finds a nested host's own exposures under its instance locator, not its bare id", () => { + const outerSubgraph = createTestSubgraph() + const innerSubgraph = createTestSubgraph() + const innerHost = createTestSubgraphNode(innerSubgraph, { id: 5 }) + outerSubgraph.add(innerHost) + const outerHost = createTestSubgraphNode(outerSubgraph, { id: 1 }) + outerSubgraph.rootGraph.add(outerHost) + + // `SubgraphNode._hydratePreviewExposures` stores a nested host's + // exposures under its instance-scoped locator (definition UUID + bare + // id), never under the bare id alone. + const instanceLocator = getPreviewExposureHostLocator(innerHost) + expect(instanceLocator).not.toBe(String(innerHost.id)) + if (!instanceLocator) return + + const store = usePreviewExposureStore() + store.addExposure(innerHost.rootGraph.id, instanceLocator, { + sourceNodeId: '3', + sourcePreviewName: 'exposure' + }) + + expect(getHostExposedSourceNodeIds(innerHost)).toEqual([toNodeId(3)]) + }) +}) diff --git a/src/composables/node/mergeSubgraphPreviews.ts b/src/composables/node/mergeSubgraphPreviews.ts new file mode 100644 index 00000000000..549cd49e22c --- /dev/null +++ b/src/composables/node/mergeSubgraphPreviews.ts @@ -0,0 +1,50 @@ +import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' +import { + getPreviewExposureHostLocator, + usePreviewExposureStore +} from '@/stores/previewExposureStore' +import type { NodeId } from '@/types/nodeId' + +import type { PromotedPreview } from './usePromotedPreviews' + +/** + * A host's own first-hop exposures, keyed the same way + * {@link getPreviewExposureHostLocator} stores them — i.e. by the host's + * instance-scoped locator, not its bare `node.id`. The two only coincide for + * root-level hosts; a nested host's exposures live under its definition- + * scoped locator, so looking them up by bare id silently finds nothing. + */ +export function getHostExposedSourceNodeIds(node: SubgraphNode): NodeId[] { + const hostLocator = getPreviewExposureHostLocator(node) + if (!hostLocator) return [] + return usePreviewExposureStore() + .getExposures(node.rootGraph.id, hostLocator) + .map((exposure) => exposure.sourceNodeId) +} + +/** + * Merges a subgraph host's exposure-promoted previews with its ambient + * previews, keeping the promoted entry whenever both cover the same + * interior node. + * + * `exposedSourceNodeIds` must be the host's own first-hop exposures (e.g. + * from `previewExposureStore.getExposures(rootGraphId, hostLocator)`), not + * `promoted`'s resolved `sourceNodeId`s. A promoted preview's `sourceNodeId` + * can be a leaf id resolved through a nested subgraph, which lives in a + * different `LGraph`'s id space than `ambient`'s immediate-interior ids — + * deduping against it can drop an unrelated ambient node that happens to + * share the same numeric id one level down. + */ +export function mergeSubgraphPreviews( + promoted: readonly PromotedPreview[], + ambient: readonly PromotedPreview[], + exposedSourceNodeIds: readonly NodeId[] +): PromotedPreview[] { + if (!ambient.length) return [...promoted] + + const exposed = new Set(exposedSourceNodeIds.map(String)) + const unexposed = ambient.filter( + (preview) => !exposed.has(String(preview.sourceNodeId)) + ) + return [...promoted, ...unexposed] +} diff --git a/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts b/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts new file mode 100644 index 00000000000..49f8440be59 --- /dev/null +++ b/src/composables/node/useAmbientSubgraphPreviews.sharedInstance.test.ts @@ -0,0 +1,134 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import type { LGraphNode as LGraphNodeType } from '@/lib/litegraph/src/litegraph' +import { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' +import { app } from '@/scripts/app' +import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { toNodeId } from '@/types/nodeId' +import { + createNodeExecutionId, + createNodeLocatorId +} from '@/types/nodeIdentification' +import { isSubgraph } from '@/utils/typeGuardUtil' + +import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' + +// Deliberately left unmocked: `@/utils/graphTraversalUtil`. The whole point +// of this regression is exercising the real `executionIdToNodeLocatorId` +// collapse — two instances of the same subgraph definition resolve to the +// same `NodeLocatorId` — rather than a mock that pretends instances stay +// distinct at the storage layer. +vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ + useWorkflowStore: vi.fn(() => ({ + nodeIdToNodeLocatorId: vi.fn((id: string | number) => + createNodeLocatorId(null, toNodeId(id)) + ), + nodeToNodeLocatorId: vi.fn((node: LGraphNodeType) => + isSubgraph(node.graph) + ? createNodeLocatorId(node.graph.id, node.id) + : createNodeLocatorId(null, node.id) + ) + })) +})) + +describe('useAmbientSubgraphPreviews with a shared subgraph definition', () => { + beforeEach(() => { + app.nodeOutputs = {} + app.nodePreviewImages = {} + }) + + it('keeps each host instance showing only its own live preview frame', () => { + const subgraph = createTestSubgraph() + const interiorNode = new LGraphNode('test') + interiorNode.id = toNodeId(10) + interiorNode.previewMediaType = 'image' + subgraph.add(interiorNode) + + const rootGraph = subgraph.rootGraph + const firstHost = createTestSubgraphNode(subgraph, { id: 11 }) + const secondHost = createTestSubgraphNode(subgraph, { id: 12 }) + rootGraph.add(firstHost) + rootGraph.add(secondHost) + + vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(rootGraph) + + const nodeOutputStore = useNodeOutputStore() + nodeOutputStore.setNodePreviewsByExecutionId( + createNodeExecutionId([toNodeId(11), toNodeId(10)]), + ['blob:first'] + ) + nodeOutputStore.setNodePreviewsByExecutionId( + createNodeExecutionId([toNodeId(12), toNodeId(10)]), + ['blob:second'] + ) + + const firstHostPreviews = useAmbientSubgraphPreviews( + () => firstHost + ).ambientPreviews + const secondHostPreviews = useAmbientSubgraphPreviews( + () => secondHost + ).ambientPreviews + + expect(firstHostPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: toNodeId(10), + urls: ['blob:first'] + }) + ]) + expect(secondHostPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: toNodeId(10), + urls: ['blob:second'] + }) + ]) + }) +}) + +describe('useAmbientSubgraphPreviews for a host nested inside another subgraph', () => { + beforeEach(() => { + app.nodeOutputs = {} + app.nodePreviewImages = {} + }) + + it('surfaces a live preview for its own interior node', () => { + const innerSubgraph = createTestSubgraph() + const interiorSampler = new LGraphNode('test') + interiorSampler.id = toNodeId(11) + interiorSampler.previewMediaType = 'image' + innerSubgraph.add(interiorSampler) + + const outerSubgraph = createTestSubgraph() + const innerHost = createTestSubgraphNode(innerSubgraph, { id: 10 }) + outerSubgraph.add(innerHost) + + const rootGraph = outerSubgraph.rootGraph + const outerHost = createTestSubgraphNode(outerSubgraph, { id: 9 }) + rootGraph.add(outerHost) + + vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(rootGraph) + + const nodeOutputStore = useNodeOutputStore() + // Mirrors production ancestor fan-out (`app.ts`'s `b_preview_with_metadata` + // handler), which writes the frame at every prefix of the full path. + for (const executionId of [ + createNodeExecutionId([toNodeId(9)]), + createNodeExecutionId([toNodeId(9), toNodeId(10)]), + createNodeExecutionId([toNodeId(9), toNodeId(10), toNodeId(11)]) + ]) { + nodeOutputStore.setNodePreviewsByExecutionId(executionId, ['blob:nested']) + } + + const { ambientPreviews } = useAmbientSubgraphPreviews(() => innerHost) + + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: toNodeId(11), + urls: ['blob:nested'] + }) + ]) + }) +}) diff --git a/src/composables/node/useAmbientSubgraphPreviews.test.ts b/src/composables/node/useAmbientSubgraphPreviews.test.ts new file mode 100644 index 00000000000..b40f803a8df --- /dev/null +++ b/src/composables/node/useAmbientSubgraphPreviews.test.ts @@ -0,0 +1,316 @@ +import { createTestingPinia } from '@pinia/testing' +import { setActivePinia } from 'pinia' +import { reactive } from 'vue' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { + createTestSubgraph, + createTestSubgraphNode +} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' +import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { toNodeId } from '@/types/nodeId' + +import { getPreviewMediaType } from './usePromotedPreviews' +import { useAmbientSubgraphPreviews } from './useAmbientSubgraphPreviews' + +type MockNodeOutputStore = Pick< + ReturnType, + | 'nodeOutputs' + | 'nodePreviewImages' + | 'getNodeImageUrls' + | 'getNodePreviewImagesByExecutionId' + | 'getNodeImageUrlsByExecutionId' +> + +vi.mock('@/stores/nodeOutputStore', () => { + // Reused (keyed by `NodeExecutionId` strings, not `NodeLocatorId`s) as the + // backing store for `getNodePreviewImagesByExecutionId` below, so seeding + // it stays a plain reactive write — see "Mocking Composables with Reactive + // State" in docs/testing/unit-testing.md. + const nodePreviewImages = reactive( + {} + ) + const store: MockNodeOutputStore = { + nodeOutputs: reactive({}), + nodePreviewImages, + getNodeImageUrls: vi.fn(), + getNodePreviewImagesByExecutionId: vi.fn( + (executionId: string) => nodePreviewImages[executionId] + ), + getNodeImageUrlsByExecutionId: vi.fn() + } + return { useNodeOutputStore: () => store } +}) + +function clearMockNodeOutputStore() { + const { nodeOutputs, nodePreviewImages } = useNodeOutputStore() + for (const key of Object.keys(nodeOutputs)) delete nodeOutputs[key] + for (const key of Object.keys(nodePreviewImages)) + delete nodePreviewImages[key] +} + +function createSetup() { + const subgraph = createTestSubgraph() + const subgraphNode = createTestSubgraphNode(subgraph) + return { subgraph, subgraphNode } +} + +function addInteriorNode( + setup: ReturnType, + options: { + id: number + previewMediaType?: 'image' | 'video' | 'audio' | 'model' + } +): LGraphNode { + const node = new LGraphNode('test') + node.id = toNodeId(options.id) + if (options.previewMediaType) { + node.previewMediaType = options.previewMediaType + } + setup.subgraph.add(node) + return node +} + +/** + * Seeds a live preview frame for an interior node, keyed the same way + * production writes it: `:`. + */ +function seedOutputs(hostId: number | string, nodeIds: Array) { + const { nodePreviewImages } = useNodeOutputStore() + for (const nodeId of nodeIds) { + nodePreviewImages[`${hostId}:${nodeId}`] = ['seeded-preview-url'] + } +} + +describe(useAmbientSubgraphPreviews, () => { + beforeEach(() => { + setActivePinia(createTestingPinia({ stubActions: false })) + clearMockNodeOutputStore() + }) + + it('returns empty array for non-SubgraphNode', () => { + const node = new LGraphNode('test') + const { ambientPreviews } = useAmbientSubgraphPreviews(() => node) + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns empty array for null node', () => { + const { ambientPreviews } = useAmbientSubgraphPreviews(() => null) + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns empty array (does not throw) when SubgraphNode is detached', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraphNode.id, [10]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) + + const parentGraph = setup.subgraphNode.graph! + parentGraph.add(setup.subgraphNode) + parentGraph.remove(setup.subgraphNode) + + expect(setup.subgraphNode.graph).toBeNull() + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(() => ambientPreviews.value).not.toThrow() + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns empty array when no interior node has produced output', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10 }) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + it('returns a preview for an interior node with live output, without any exposure', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraphNode.id, [10]) + const urls = ['/view?filename=output.png'] + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? urls : undefined)) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ + sourceNodeId: '10', + type: getPreviewMediaType(node), + urls + }) + ]) + }) + + it.for([ + ['video', '/view?filename=output.webm'], + ['audio', '/view?filename=output.mp3'] + ] as const)( + 'derives %s type from previewMediaType, same as the promoted path', + ([mediaType, url]) => { + const setup = createSetup() + addInteriorNode(setup, { + id: 10, + previewMediaType: mediaType + }) + seedOutputs(setup.subgraphNode.id, [10]) + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? [url] : undefined)) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ sourceNodeId: '10', type: mediaType }) + ]) + } + ) + + it('returns separate entries for two concurrently-executing interior nodes', () => { + const setup = createSetup() + addInteriorNode(setup, { + id: 10, + previewMediaType: 'image' + }) + addInteriorNode(setup, { + id: 20, + previewMediaType: 'image' + }) + seedOutputs(setup.subgraphNode.id, [10, 20]) + const hostId = setup.subgraphNode.id + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((executionId) => { + if (executionId === `${hostId}:10`) return ['/view?a=1'] + if (executionId === `${hostId}:20`) return ['/view?b=2'] + return undefined + }) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toHaveLength(2) + const urlsBySourceNodeId = new Map( + ambientPreviews.value.map((p) => [p.sourceNodeId, p.urls]) + ) + expect(urlsBySourceNodeId.get(toNodeId(10))).toEqual(['/view?a=1']) + expect(urlsBySourceNodeId.get(toNodeId(20))).toEqual(['/view?b=2']) + }) + + it('skips interior nodes when getNodeImageUrlsByExecutionId returns no urls despite a preview entry', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraphNode.id, [10]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(undefined) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + // Regression coverage for narrowing the gate to a live streaming preview + // frame only: a committed output must never surface ambiently, even when + // an image url is otherwise resolvable — otherwise demoting an exposure + // becomes a no-op and every interior output node stacks a permanent + // preview on the host after every run. + it('does not surface a committed output that was never a streaming preview', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + it('recomputes when outputs are populated after first evaluation', () => { + const setup = createSetup() + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + + seedOutputs(setup.subgraphNode.id, [10]) + const urls = ['/view?filename=output.png'] + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? urls : undefined)) + + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ sourceNodeId: '10', urls }) + ]) + }) + + it('self-heals once an interior node added after the first evaluation gets its first preview frame', () => { + const setup = createSetup() + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + + addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + seedOutputs(setup.subgraphNode.id, [10]) + const urls = ['/view?filename=output.png'] + const executionId = `${setup.subgraphNode.id}:10` + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockImplementation((id) => (id === executionId ? urls : undefined)) + + expect(ambientPreviews.value).toEqual([ + expect.objectContaining({ sourceNodeId: '10', urls }) + ]) + }) + + it('skips nested SubgraphNode interior nodes (they derive their own previews)', () => { + const setup = createSetup() + const nestedSubgraph = createTestSubgraph() + const nestedHost = createTestSubgraphNode(nestedSubgraph, { id: 30 }) + setup.subgraph.add(nestedHost) + seedOutputs(setup.subgraphNode.id, [30]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) + + it('skips interior nodes with hideOutputImages set', () => { + const setup = createSetup() + const node = addInteriorNode(setup, { id: 10, previewMediaType: 'image' }) + node.hideOutputImages = true + seedOutputs(setup.subgraphNode.id, [10]) + vi.mocked( + useNodeOutputStore().getNodeImageUrlsByExecutionId + ).mockReturnValue(['/view?filename=output.png']) + + const { ambientPreviews } = useAmbientSubgraphPreviews( + () => setup.subgraphNode + ) + expect(ambientPreviews.value).toEqual([]) + }) +}) diff --git a/src/composables/node/useAmbientSubgraphPreviews.ts b/src/composables/node/useAmbientSubgraphPreviews.ts new file mode 100644 index 00000000000..189444a8f27 --- /dev/null +++ b/src/composables/node/useAmbientSubgraphPreviews.ts @@ -0,0 +1,115 @@ +import type { MaybeRefOrGetter, Ref } from 'vue' +import { computed, ref, toValue } from 'vue' + +import { useChainCallback } from '@/composables/functional/useChainCallback' +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { Subgraph } from '@/lib/litegraph/src/litegraph' +import { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' +import { useNodeOutputStore } from '@/stores/nodeOutputStore' +import { appendNodeExecutionId } from '@/types/nodeIdentification' +import { getExecutionIdByNode } from '@/utils/graphTraversalUtil' + +import type { PromotedPreview } from './usePromotedPreviews' +import { getPreviewMediaType } from './usePromotedPreviews' + +/** + * One shared, ever-incrementing version `ref` per {@link Subgraph}, bumped + * whenever an interior node is added or removed. `subgraph.nodes` itself is + * a plain, non-reactive array, so {@link useAmbientSubgraphPreviews} reads + * this alongside it purely to give Vue something reactive to invalidate on. + */ +const topologyVersions = new WeakMap>() + +function useSubgraphTopologyVersion(subgraph: Subgraph): Ref { + const existing = topologyVersions.get(subgraph) + if (existing) return existing + + const version = ref(0) + subgraph.onNodeAdded = useChainCallback(subgraph.onNodeAdded, () => { + version.value++ + }) + subgraph.onNodeRemoved = useChainCallback(subgraph.onNodeRemoved, () => { + version.value++ + }) + topologyVersions.set(subgraph, version) + return version +} + +/** + * Synthetic `sourceWidgetName` for ambient previews, so they share + * {@link PromotedPreview}'s shape (and the render list's dedup/key logic) + * without implying a real promoted widget exists. + */ +const AMBIENT_PREVIEW_NAME = '$$ambient-preview' + +/** + * Live-execution previews for a SubgraphNode host, derived directly from + * each interior node's own streaming preview state. + * + * Deliberately independent of `previewExposureStore` and the link-promotion + * system: it exists so any interior node currently producing a live preview + * (e.g. a second KSampler nobody promoted) still shows on the expanded host, + * loosely analogous to how `nodeLocationProgressStates` bubbles up execution + * progress regardless of promotion — though unlike that store, this only + * looks at the host's immediate interior nodes and does not recurse into + * nested subgraphs. + */ +export function useAmbientSubgraphPreviews( + lgraphNode: MaybeRefOrGetter +) { + const nodeOutputStore = useNodeOutputStore() + + const ambientPreviews = computed((): PromotedPreview[] => { + const node = toValue(lgraphNode) + if (!(node instanceof SubgraphNode)) return [] + if (node.isDetached) return [] + + const { subgraph } = node + void useSubgraphTopologyVersion(subgraph).value + + // The host's own root-relative execution id (e.g. `9:10` for a host + // nested one level deep), not just its bare local id — otherwise a + // nested host looks up its interior previews under the wrong key and + // never finds the frames `app.ts`'s ancestor fan-out already wrote for + // it. Scoping interior lookups to this instance's own execution path, + // rather than the subgraph definition's shared `NodeLocatorId`, is also + // what keeps two hosts of the same definition from displaying each + // other's preview. + const hostExecutionId = getExecutionIdByNode(node.rootGraph, node) + if (!hostExecutionId) return [] + + return subgraph.nodes.flatMap((interiorNode): PromotedPreview[] => { + // Nested subgraph hosts derive their own previews independently. + if (interiorNode instanceof SubgraphNode) return [] + if (interiorNode.hideOutputImages) return [] + + const executionId = appendNodeExecutionId( + hostExecutionId, + interiorNode.id + ) + if (!executionId) return [] + + if ( + !nodeOutputStore.getNodePreviewImagesByExecutionId(executionId)?.length + ) + return [] + + const urls = nodeOutputStore.getNodeImageUrlsByExecutionId( + executionId, + interiorNode + ) + if (!urls?.length) return [] + + return [ + { + sourceNodeId: interiorNode.id, + sourceWidgetName: AMBIENT_PREVIEW_NAME, + type: getPreviewMediaType(interiorNode), + urls + } + ] + }) + }) + + return { ambientPreviews } +} diff --git a/src/composables/node/usePromotedPreviews.ts b/src/composables/node/usePromotedPreviews.ts index 45c91925030..2a030a642da 100644 --- a/src/composables/node/usePromotedPreviews.ts +++ b/src/composables/node/usePromotedPreviews.ts @@ -16,7 +16,7 @@ import { } from '@/types/nodeIdentification' import type { NodeExecutionId } from '@/types/nodeIdentification' -interface PromotedPreview { +export interface PromotedPreview { sourceNodeId: NodeId sourceWidgetName: string type: 'image' | 'video' | 'audio' @@ -28,7 +28,8 @@ const PREVIEW_TYPES_BY_MEDIA = { audio: 'audio' } as const satisfies Partial> -function getPreviewMediaType(node: LGraphNode): PromotedPreview['type'] { +/** Shared with {@link useAmbientSubgraphPreviews} so both derive media type identically. */ +export function getPreviewMediaType(node: LGraphNode): PromotedPreview['type'] { const media = node.previewMediaType if (media && media in PREVIEW_TYPES_BY_MEDIA) { return PREVIEW_TYPES_BY_MEDIA[media as keyof typeof PREVIEW_TYPES_BY_MEDIA] diff --git a/src/core/graph/subgraph/promotionUtils.test.ts b/src/core/graph/subgraph/promotionUtils.test.ts index 16bafeb8283..0d8b011aa53 100644 --- a/src/core/graph/subgraph/promotionUtils.test.ts +++ b/src/core/graph/subgraph/promotionUtils.test.ts @@ -1,3 +1,6 @@ +import fs from 'node:fs' +import path from 'node:path' + import { fromPartial } from '@total-typescript/shoehorn' import { describe, expect, it, vi } from 'vitest' @@ -456,6 +459,60 @@ describe('autoExposeKnownPreviewNodes', () => { }) }) +describe('e2e ambient-preview fixtures stay ambient-only', () => { + // These fixtures back subgraphNestedAmbientPreviewScope.spec.ts and + // subgraphAmbientCommittedOutputIsolation.spec.ts, both of which assert a + // live preview appears on a subgraph host with no promoted exposure for + // it. If a host's `previewExposures` property is left undefined, the + // one-shot `autoExposeKnownPreviewNodes` gate above runs on load and + // auto-promotes the interior KSampler, so the e2e assertion passes via the + // promotion path even with the ambient composable stubbed out — the exact + // gap this test guards against. + const hostFixtures = [ + { + file: 'subgraph-nested-with-live-sampler.json', + hostTitles: ['Outer Subgraph', 'Middle Subgraph'] + }, + { + file: 'subgraph-with-live-sampler-and-committed-output.json', + hostTitles: ['Sampler And Preview Subgraph'] + } + ] + + function loadFixtureNodes(fileName: string) { + const fullPath = path.resolve( + __dirname, + `../../../../browser_tests/assets/subgraphs/${fileName}` + ) + const workflow = JSON.parse(fs.readFileSync(fullPath, 'utf-8')) as { + nodes: Array<{ title?: string; properties?: Record }> + definitions?: { + subgraphs?: Array<{ + nodes: Array<{ + title?: string + properties?: Record + }> + }> + } + } + return [ + ...workflow.nodes, + ...(workflow.definitions?.subgraphs?.flatMap((sg) => sg.nodes) ?? []) + ] + } + + it.for(hostFixtures)( + 'declares an empty previewExposures on every host in $file', + ({ file, hostTitles }) => { + const nodes = loadFixtureNodes(file) + for (const title of hostTitles) { + const host = nodes.find((n) => n.title === title) + expect(host?.properties?.previewExposures).toEqual([]) + } + } + ) +}) + describe('hasUnpromotedWidgets', () => { it('returns true when subgraph has at least one enabled unpromoted widget', () => { const subgraph = createTestSubgraph() diff --git a/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts b/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts index eeebacb5e64..d7ce92ea81e 100644 --- a/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts +++ b/src/lib/litegraph/src/subgraph/subgraphDeduplication.test.ts @@ -133,6 +133,77 @@ describe('deduplicateSubgraphNodeIds', () => { }) }) +describe('deduplicateSubgraphNodeIds - previewExposures', () => { + function makeSubgraphWithNodeId( + id: string, + nodeId: number + ): ExportedSubgraph { + const subgraph = makeSubgraph(id, ['KSampler']) + const node = subgraph.nodes?.[0] + if (node) node.id = nodeId + return subgraph + } + + function makeHost( + id: number, + type: string, + previewExposures?: { + name: string + sourceNodeId: string + sourcePreviewName: string + }[] + ) { + return { + id, + type, + pos: [0, 0] as [number, number], + size: [100, 100] as [number, number], + flags: {}, + order: id, + mode: 0, + inputs: [], + outputs: [], + properties: previewExposures ? { previewExposures } : {} + } + } + + it('remaps a host previewExposures entry when its interior node id is reassigned', () => { + // Both definitions use interior node id 3, so whichever loads second gets + // its node 3 remapped to a fresh id. + const subgraphA = makeSubgraphWithNodeId('sg-a', 3) + const subgraphB = makeSubgraphWithNodeId('sg-b', 3) + const hostA = makeHost(1, 'sg-a', [ + { + name: '$$canvas-image-preview', + sourceNodeId: '3', + sourcePreviewName: '$$canvas-image-preview' + } + ]) + const hostB = makeHost(2, 'sg-b') + const state = freshState() + + const result = deduplicateSubgraphNodeIds( + [subgraphB, subgraphA], + new Set([1, 2]), + state, + [hostB, hostA] as unknown as Parameters< + typeof deduplicateSubgraphNodeIds + >[3] + ) + + const remappedHostA = result.rootNodes?.find((node) => node.type === 'sg-a') + const defA = result.subgraphs.find((subgraph) => subgraph.id === 'sg-a') + const interiorId = String(defA?.nodes?.[0]?.id) + + const exposures = remappedHostA?.properties?.previewExposures as + | { sourceNodeId: string }[] + | undefined + + expect(interiorId).not.toBe('3') + expect(exposures?.[0]?.sourceNodeId).toBe(interiorId) + }) +}) + describe('deduplicateSubgraphLinkIds', () => { it('patches every reference to a remapped regular link', () => { const subgraph = makeSubgraph('sg', ['dummy']) diff --git a/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts b/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts index 49793a7ed1a..23bc3322701 100644 --- a/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts +++ b/src/lib/litegraph/src/subgraph/subgraphDeduplication.ts @@ -226,10 +226,12 @@ function deduplicateClonedSubgraphNodeIds( for (const subgraph of clonedSubgraphs) { patchProxyWidgets(subgraph.nodes ?? [], subgraphIdSet, remapBySubgraph) + patchPreviewExposures(subgraph.nodes ?? [], subgraphIdSet, remapBySubgraph) } if (clonedRootNodes) { patchProxyWidgets(clonedRootNodes, subgraphIdSet, remapBySubgraph) + patchPreviewExposures(clonedRootNodes, subgraphIdSet, remapBySubgraph) } } @@ -552,6 +554,32 @@ export function topologicalSortSubgraphs( return sorted } +/** Patches `properties.previewExposures[].sourceNodeId` for a remapped interior node. */ +function patchPreviewExposures( + hostNodes: ISerialisedNode[], + subgraphIdSet: Set, + remapBySubgraph: Map> +): void { + for (const node of hostNodes) { + if (!subgraphIdSet.has(node.type)) continue + const remappedIds = remapBySubgraph.get(node.type) + if (!remappedIds) continue + + const previewExposures = node.properties?.previewExposures + if (!Array.isArray(previewExposures)) continue + + for (const exposure of previewExposures) { + if (!exposure || typeof exposure !== 'object') continue + const { sourceNodeId } = exposure as { sourceNodeId?: unknown } + if (typeof sourceNodeId !== 'string') continue + const newId = remappedIds.get(toNodeId(sourceNodeId)) + if (newId !== undefined) { + ;(exposure as { sourceNodeId: string }).sourceNodeId = String(newId) + } + } + } +} + /** Patches legacy proxyWidgets in root-level SubgraphNode instances. */ function patchProxyWidgets( rootNodes: ISerialisedNode[], diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts index c84930e085b..bfa95b6957b 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.test.ts @@ -9,6 +9,7 @@ import type { NodeError } from '@/schemas/apiSchema' import { useExecutionErrorStore } from '@/stores/executionErrorStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import { toNodeId } from '@/types/nodeId' +import { createNodeLocatorId } from '@/types/nodeIdentification' import { widgetId } from '@/types/widgetId' import { computed, nextTick, ref } from 'vue' import type { ComponentProps } from 'vue-component-type-helpers' @@ -21,6 +22,7 @@ import { import type { NodeState } from '@/types/nodeState' import LGraphNode from '@/renderer/extensions/vueNodes/components/LGraphNode.vue' import { useVueElementTracking } from '@/renderer/extensions/vueNodes/composables/useVueNodeResizeTracking' +import { useNodePreviewState } from '@/renderer/extensions/vueNodes/preview/useNodePreviewState' import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' import { useSettingStore } from '@/platform/settings/settingStore' import { app } from '@/scripts/app' @@ -547,4 +549,26 @@ describe('LGraphNode', () => { expect(app.dragOverNode).toBe(mockData.mockLgraphNode) }) }) + + describe('Subgraph live preview promotion', () => { + // Expected-fail until the `!lgraphNode?.isSubgraphNode()` guard in + // LGraphNode.vue is relaxed to allow rendering previews on subgraph + // nodes. Keep this test (don't delete) so it flips green automatically + // once that guard changes. + // incident-94: waiting on LGraphNode.vue:172's `!lgraphNode?.isSubgraphNode()` guard. + it.fails('renders the live preview image on a subgraph node with a populated preview', () => { + mockData.mockLgraphNode = { isSubgraphNode: () => true } + vi.mocked(useNodePreviewState).mockReturnValue({ + locatorId: computed(() => createNodeLocatorId(null, mockNodeData.id)), + previewUrls: computed(() => ['blob:preview-url']), + hasPreview: computed(() => true), + latestPreviewUrl: computed(() => 'blob:preview-url'), + shouldShowPreviewImg: computed(() => true) + }) + + renderLGraphNode({ nodeData: mockNodeData }) + + expect(screen.getByRole('img')).toHaveAttribute('src', 'blob:preview-url') + }) + }) }) diff --git a/src/renderer/extensions/vueNodes/components/LGraphNode.vue b/src/renderer/extensions/vueNodes/components/LGraphNode.vue index 554b81d4d42..351a34b62b6 100644 --- a/src/renderer/extensions/vueNodes/components/LGraphNode.vue +++ b/src/renderer/extensions/vueNodes/components/LGraphNode.vue @@ -162,7 +162,7 @@
{ - if (promotedPreviews.value.length > 0) return true + if (subgraphPreviews.value.length > 0) return true return !!nodeMedia.value && nodeMedia.value.urls.length > 0 }) @@ -630,6 +635,18 @@ const lgraphNode = computed(resolveLGraphNode) // TODO: Surface subgraph info more cleanly in NodeState instead of // reaching through lgraphNode for promoted preview resolution. const { promotedPreviews } = usePromotedPreviews(lgraphNode) +const { ambientPreviews } = useAmbientSubgraphPreviews(lgraphNode) + +const subgraphPreviews = computed(() => { + const node = lgraphNode.value + const exposedSourceNodeIds = + node instanceof SubgraphNode ? getHostExposedSourceNodeIds(node) : [] + return mergeSubgraphPreviews( + promotedPreviews.value, + ambientPreviews.value, + exposedSourceNodeIds + ) +}) const { hideExecutedOutput } = useGLSLPreview(lgraphNode) diff --git a/src/stores/nodeOutputStore.ts b/src/stores/nodeOutputStore.ts index caf26fd5c5a..0d5755e13ba 100644 --- a/src/stores/nodeOutputStore.ts +++ b/src/stores/nodeOutputStore.ts @@ -54,6 +54,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { const workflowStore = useWorkflowStore() const { nodeIdToNodeLocatorId, nodeToNodeLocatorId } = workflowStore const scheduledRevoke: Record void }> = {} + const scheduledRevokeByExecutionId: Record void }> = {} const latestPreview = ref([]) /** * Previews belonging to open-but-inactive workflows, keyed by workflow path. @@ -61,15 +62,19 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { */ const stashedPreviews = new Map>() - function scheduleRevoke(locator: NodeLocatorId, cb: () => void) { - scheduledRevoke[locator]?.stop() + function scheduleRevoke( + tracker: Record void }>, + key: string, + cb: () => void + ) { + tracker[key]?.stop() const { stop } = useTimeoutFn(() => { - delete scheduledRevoke[locator] + delete tracker[key] cb() }, PREVIEW_REVOKE_DELAY_MS) - scheduledRevoke[locator] = { stop } + tracker[key] = { stop } } const nodeOutputs = ref>({ @@ -83,6 +88,16 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { ]) ) ) + /** + * Preview frames keyed by the writer's own `NodeExecutionId`, distinct from + * `nodePreviewImages`'s `NodeLocatorId` keying: `NodeLocatorId` is + * definition-scoped by design, so multiple instances of one subgraph + * definition collapse to the same key there. Live preview frames are + * instance-scoped — two instances executing concurrently must not overwrite + * each other's frame — so `getNodePreviewImagesByExecutionId` reads this + * map instead. + */ + const nodePreviewImagesByExecutionId = ref>({}) function getNodeOutputs( node: LGraphNode @@ -153,9 +168,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { function getNodePreviewImagesByExecutionId( executionId: NodeExecutionId ): string[] | undefined { - const locatorId = executionIdToNodeLocatorId(app.rootGraph, executionId) - if (!locatorId) return undefined - return nodePreviewImages.value[locatorId] + return nodePreviewImagesByExecutionId.value[executionId] } function getNodeImageUrlsByExecutionId( @@ -289,9 +302,34 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { const nodeLocatorId = executionIdToNodeLocatorId(app.rootGraph, executionId) if (!nodeLocatorId) return setNodePreviewsByLocatorId(nodeLocatorId, previewImages) + setInstancePreviewImages(executionId, previewImages) latestPreview.value = [...previewImages] } + function setInstancePreviewImages( + executionId: NodeExecutionId, + previewImages: string[] + ) { + const existing = nodePreviewImagesByExecutionId.value[executionId] + if (scheduledRevokeByExecutionId[executionId]) { + scheduledRevokeByExecutionId[executionId].stop() + delete scheduledRevokeByExecutionId[executionId] + } + if (existing?.[Symbol.iterator]) { + for (const url of existing) releaseSharedObjectUrl(url) + } + for (const url of previewImages) retainSharedObjectUrl(url) + nodePreviewImagesByExecutionId.value[executionId] = [...previewImages] + } + + function revokeInstancePreviewImages(executionId: NodeExecutionId) { + const previews = nodePreviewImagesByExecutionId.value[executionId] + if (!previews?.[Symbol.iterator]) return + + for (const url of previews) releaseSharedObjectUrl(url) + delete nodePreviewImagesByExecutionId.value[executionId] + } + function setNodePreviewsByLocatorId( nodeLocatorId: NodeLocatorId, previewImages: string[] @@ -319,9 +357,13 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { function revokePreviewsByExecutionId(executionId: NodeExecutionId) { const nodeLocatorId = executionIdToNodeLocatorId(app.rootGraph, executionId) - if (!nodeLocatorId) return - scheduleRevoke(nodeLocatorId, () => - revokePreviewsByLocatorId(nodeLocatorId) + if (nodeLocatorId) { + scheduleRevoke(scheduledRevoke, nodeLocatorId, () => + revokePreviewsByLocatorId(nodeLocatorId) + ) + } + scheduleRevoke(scheduledRevokeByExecutionId, executionId, () => + revokeInstancePreviewImages(executionId) ) } @@ -350,6 +392,14 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => { function revokeAllPreviews() { releasePreviewUrls(nodePreviewImages.value) nodePreviewImages.value = {} + + for (const executionId of Object.keys( + nodePreviewImagesByExecutionId.value + )) { + const previews = nodePreviewImagesByExecutionId.value[executionId] + for (const url of previews) releaseSharedObjectUrl(url) + } + nodePreviewImagesByExecutionId.value = {} app.nodePreviewImages = {} }