Skip to content

Commit fb5b4a6

Browse files
authored
Fix mask editor sometimes showing wrong image (#12413)
Mask editor checks `node.images` to determine the image which is edited. If the user generates an output image in litegraph mode, swaps to vue mode, then generates a new image, the mask editor will incorrectly display the image last shown in litegraph mode. This is resolved by having `syncLegacyNodeImgs` also synchronize node outputs to `node.images`.
1 parent cb62604 commit fb5b4a6

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

browser_tests/tests/maskEditor.spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { expect } from '@playwright/test'
1+
import { expect, mergeTests } from '@playwright/test'
22

3+
import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper'
34
import { maskEditorTest as test } from '@e2e/fixtures/helpers/MaskEditorHelper'
5+
import { webSocketFixture } from '@e2e/fixtures/ws'
6+
7+
const wstest = mergeTests(test, webSocketFixture)
48

59
test.describe('Mask Editor', { tag: '@vue-nodes' }, () => {
610
test(
@@ -301,3 +305,39 @@ test.describe('Mask Editor', { tag: '@vue-nodes' }, () => {
301305
}
302306
)
303307
})
308+
309+
wstest(
310+
'Will not use stale litegraph previews',
311+
async ({ comfyPage, getWebSocket }) => {
312+
const executionHelper = new ExecutionHelper(comfyPage, await getWebSocket())
313+
await comfyPage.menu.topbar.newWorkflowButton.click()
314+
await comfyPage.searchBoxV2.addNode('Preview Image')
315+
316+
async function getNodeOutput() {
317+
return await comfyPage.page.evaluate(
318+
() => graph!.getNodeById('1')!.images?.[0]?.filename
319+
)
320+
}
321+
322+
executionHelper.executed('', '1', { images: [{ filename: 'test1.png' }] })
323+
await comfyPage.page.evaluate(() => app!.canvas.setDirty(true))
324+
await expect.poll(getNodeOutput).toBe('test1.png')
325+
326+
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
327+
328+
const resolvableFile = { filename: 'example.png', type: 'input' }
329+
executionHelper.executed('', '1', { images: [resolvableFile] })
330+
await expect.poll(getNodeOutput).toBe('example.png')
331+
332+
const node = await comfyPage.vueNodes.getFixtureByTitle('Preview Image')
333+
await node.imagePreview.hover()
334+
await node.imagePreview
335+
.getByRole('button', { name: 'Edit or mask image' })
336+
.click()
337+
338+
// On previous versions, attempting to open the mask editor here would
339+
// incorrectly reference the non-existant test1.png
340+
// This causes the mask editor to throw in setup and not display
341+
await expect(comfyPage.page.locator('.mask-editor-dialog')).toBeVisible()
342+
}
343+
)

src/stores/nodeOutputStore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
473473

474474
node.imgs = [element]
475475
node.imageIndex = activeIndex
476+
477+
const outputs = getNodeOutputs(node)
478+
if (outputs?.images) node.images = outputs.images
476479
}
477480

478481
return {

0 commit comments

Comments
 (0)