Skip to content

Commit

Permalink
Reset FileInput value after load
Browse files Browse the repository at this point in the history
When a file is browsed for, the fileInput remains associated with the
chosen file even after the associated workflow is loaded. If a user
attempts to load the same file again, the onchange event does not fire
and loading fails silently. This is fixed by clearing the fileInput
after the workflow has been loaded.

Out of an abundance of caution, the onchange is made async to ensure the
fileInput isn't cleared until after the workflow has loaded.

Add a test to check if the same workflow file can be loaded
consecutively.
  • Loading branch information
AustinMroz committed Sep 25, 2024
1 parent c2a3f36 commit b8ebfcd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions browser_tests/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,23 @@ test.describe('Load workflow', () => {
await expect(comfyPage.canvas).toHaveScreenshot('string_node_id.png')
})
})

test.describe('Load duplicate workflow', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.UseNewMenu', 'Floating')
})

test.afterEach(async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.UseNewMenu', 'Disabled')
})

test('A workflow can be loaded multiple times in a row', async ({
comfyPage
}) => {
await comfyPage.loadWorkflow('single_ksampler')
await comfyPage.menu.workflowsTab.open()
await comfyPage.menu.workflowsTab.newBlankWorkflowButton.click()
await comfyPage.loadWorkflow('single_ksampler')
expect(await comfyPage.getGraphNodesCount()).toBe(1)
})
})
5 changes: 3 additions & 2 deletions src/scripts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ export class ComfyUI {
accept: '.json,image/png,.latent,.safetensors,image/webp,audio/flac',
style: { display: 'none' },
parent: document.body,
onchange: () => {
app.handleFile(fileInput.files[0])
onchange: async () => {
await app.handleFile(fileInput.files[0])
fileInput.value = ''
}
})

Expand Down

0 comments on commit b8ebfcd

Please sign in to comment.