Repository navigation
fix(assets): capture canvas state after an image upload commits #15069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bed706e
test: add failing repro for uploads not reaching the workflow draft
de3c37a
fix(assets): capture canvas state after an image upload commits
dd5f0cc
test: wait on the draft holding the new value instead of the draft index
388bd2a
test: enable workflow persistence and raise the timeout
3659c5b
test: wait for the upload to commit before reading the widget value
a190c11
fix: capture canvas state whenever an upload commits
72e8ac3
test: recompute isModified after re-baselining the change tracker
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /** | ||
| * FE-1425: dropping an image on a Load Image node must survive a browser | ||
| * reload without an explicit save. `Comfy.Workflow.Persist` defaults to true | ||
| * and writes a localStorage draft on every `graphChanged`, but the upload | ||
| * commit never nudged the change tracker — and HTML5 drag-and-drop emits no | ||
| * mouseup for its global hook to catch — so the draft kept the previous image. | ||
| */ | ||
| import { expect } from '@playwright/test' | ||
|
|
||
| import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' | ||
|
|
||
| const DROPPED_FILE = 'image64x64.webp' | ||
|
|
||
| test.describe('Load Image upload persistence', () => { | ||
| test('keeps a dropped image across a reload without saving', async ({ | ||
| comfyPage, | ||
| comfyFiles | ||
| }) => { | ||
| test.setTimeout(60000) | ||
|
|
||
| await comfyPage.settings.setSetting('Comfy.Workflow.Persist', true) | ||
| await comfyPage.nodeOps.clearGraph() | ||
| await comfyPage.searchBoxV2.addNode('Load Image') | ||
|
|
||
| const [loadImageNode] = | ||
| await comfyPage.nodeOps.getNodeRefsByType('LoadImage') | ||
| const { x, y } = await loadImageNode.getPosition() | ||
|
|
||
| const readImageWidgetValue = () => | ||
| comfyPage.page.evaluate( | ||
| () => | ||
| window.app?.graph?.nodes | ||
| .find((node) => node.type === 'LoadImage') | ||
| ?.widgets?.find((widget) => widget.name === 'image')?.value | ||
| ) | ||
|
|
||
| // The server keeps the filename when the same bytes are uploaded again, so | ||
| // asserting on the name rather than on "the value changed" keeps this test | ||
| // correct whether or not a previous run already left the file behind. | ||
| await comfyPage.dragDrop.dragAndDropFile(DROPPED_FILE, { | ||
| dropPosition: { x, y }, | ||
| waitForUpload: true | ||
| }) | ||
| comfyFiles.deleteAfterTest({ filename: DROPPED_FILE, type: 'input' }) | ||
|
|
||
| await expect.poll(readImageWidgetValue).toBe(DROPPED_FILE) | ||
|
|
||
| // The draft carrying the new value is what survives the reload, so waiting | ||
| // on it also covers the 512ms persist debounce. | ||
| await expect | ||
| .poll( | ||
| () => | ||
| comfyPage.page.evaluate((expected) => { | ||
| for (let i = 0; i < window.localStorage.length; i++) { | ||
| const key = window.localStorage.key(i) | ||
| if (!key?.startsWith('Comfy.Workflow.Draft.v2:')) continue | ||
| if (window.localStorage.getItem(key)?.includes(expected)) | ||
| return true | ||
| } | ||
| return false | ||
| }, DROPPED_FILE), | ||
| { timeout: 10_000 } | ||
| ) | ||
| .toBe(true) | ||
|
|
||
| await comfyPage.workflow.reloadAndWaitForApp() | ||
|
|
||
| await expect.poll(readImageWidgetValue).toBe(DROPPED_FILE) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,16 @@ const mocks = vi.hoisted(() => ({ | |
| capturedUploadOptions: undefined as CapturedImageUploadOptions | undefined, | ||
| openFileSelection: vi.fn(), | ||
| setNodeOutputs: vi.fn(), | ||
| showPreview: vi.fn() | ||
| showPreview: vi.fn(), | ||
| captureCanvasState: vi.fn() | ||
| })) | ||
|
|
||
| vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ | ||
| useWorkflowStore: () => ({ | ||
| activeWorkflow: { | ||
| changeTracker: { captureCanvasState: mocks.captureCanvasState } | ||
| } | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/composables/node/useNodeImage', () => ({ | ||
|
|
@@ -96,6 +105,7 @@ const outputFolderCases: { | |
| describe('useImageUploadWidget', () => { | ||
| beforeEach(() => { | ||
| mocks.capturedUploadOptions = undefined | ||
| mocks.captureCanvasState.mockClear() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: this line is redundant — |
||
| vi.stubGlobal('requestAnimationFrame', vi.fn()) | ||
| }) | ||
|
|
||
|
|
@@ -149,4 +159,47 @@ describe('useImageUploadWidget', () => { | |
|
|
||
| expect(fileComboWidget.value).toBe(expected) | ||
| }) | ||
|
|
||
| it('captures canvas state after upload so the draft persists the new value', () => { | ||
| const { fileComboWidget, node } = createUploadNode() | ||
| const constructor = useImageUploadWidget() | ||
|
|
||
| constructor( | ||
| node, | ||
| 'upload', | ||
| [ | ||
| 'IMAGEUPLOAD', | ||
| { imageInputName: 'image', image_upload: true } | ||
| ] as InputSpec, | ||
| fromPartial({}) | ||
| ) | ||
|
|
||
| mocks.capturedUploadOptions?.onUploadComplete(['uploaded.png']) | ||
|
|
||
| expect(fileComboWidget.value).toBe('uploaded.png') | ||
| expect(mocks.captureCanvasState).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('captures canvas state when the server keeps the optimistic filename', () => { | ||
| const { fileComboWidget, node } = createUploadNode() | ||
| const constructor = useImageUploadWidget() | ||
|
|
||
| constructor( | ||
| node, | ||
| 'upload', | ||
| [ | ||
| 'IMAGEUPLOAD', | ||
| { imageInputName: 'image', image_upload: true } | ||
| ] as InputSpec, | ||
| fromPartial({}) | ||
| ) | ||
|
|
||
| mocks.capturedUploadOptions?.onUploadStart?.([ | ||
| new File([], 'uploaded.png', { type: 'image/png' }) | ||
| ]) | ||
| mocks.capturedUploadOptions?.onUploadComplete(['uploaded.png']) | ||
|
|
||
| expect(fileComboWidget.value).toBe('uploaded.png') | ||
| expect(mocks.captureCanvasState).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: drop this
deleteAfterTestcall.image64x64.webpis a shared fixture uploaded by six other specs (imagePreview,glslPreview,subgraphPromotion,maskEditorLoadSave,load3d,assetDeleteClearsLoadImage), and CI runsfullyParallelwith 2 workers — deleting it from the server-global input folder mid-run can 404 another worker's preview-image fetch. The comment above already notes this test stays correct whether or not the file is left behind, so the deletion buys nothing here.