Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions browser_tests/tests/workflowPersistence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,42 @@ test.describe('Workflow Persistence', () => {
await expect(comfyPage.toast.toastErrors).toHaveCount(0)
})

test('Flushes a pending draft edit before an immediate reload', async ({
comfyPage
}) => {
test.info().annotations.push({
type: 'regression',
description:
'FE-1484 — refreshing inside the persistence debounce window lost the latest workflow edit'
})

await comfyPage.settings.setSetting('Comfy.Workflow.Persist', true)
await comfyPage.workflow.loadWorkflow('nodes/single_ksampler')
await fitToViewInstant(comfyPage)

const firstNode = await getRequiredFirstNodeRef(
comfyPage,
'First node should be available after loading single_ksampler'
)
await firstNode.centerOnNode()

const baselineSaveStartedAt = Date.now()
await firstNode.toggleCollapse()
await expect.poll(() => firstNode.isCollapsed()).toBe(true)
await comfyPage.workflow.waitForDraftIndexUpdatedSince(
baselineSaveStartedAt
)

await firstNode.toggleCollapse()
await comfyPage.workflow.reloadAndWaitForApp()

const restoredNode = await getRequiredFirstNodeRef(
comfyPage,
'First node should be restored after the immediate reload'
)
await expect.poll(() => restoredNode.isCollapsed()).toBe(false)
})

test('Closing an inactive tab with save preserves its own content', async ({
comfyPage
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,57 @@ describe('useWorkflowPersistenceV2', () => {
})
})

it('flushes a pending workflow edit when the page is unloaded', async () => {
const workflowStore = useWorkflowStore()
const workflow = await workflowStore.createTemporary('Draft.json').load()
workflowStore.activeWorkflow = workflow
mountWorkflowPersistence()
await nextTick()

mocks.state.currentGraph = {
nodes: [],
extra: { marker: 'final-edit' }
}
mocks.state.graphChangedHandler?.()

const payloadKey = StorageKeys.draftPayload(workflow.path, 'personal')
expect(localStorage.getItem(payloadKey)).toBeNull()

window.dispatchEvent(new PageTransitionEvent('pagehide'))

const payload = JSON.parse(localStorage.getItem(payloadKey)!)
expect(JSON.parse(payload.data)).toEqual({
nodes: [],
extra: { marker: 'final-edit' }
})
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it('does not flush a pending workflow edit after disposal', async () => {
const workflowStore = useWorkflowStore()
const workflow = await workflowStore.createTemporary('Draft.json').load()
workflowStore.activeWorkflow = workflow
mountWorkflowPersistence()

mocks.state.currentGraph = { nodes: [] }
const graphChangedHandler = mocks.state.graphChangedHandler
if (!graphChangedHandler) {
throw new Error('Graph change handler was not registered')
}
graphChangedHandler()

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const mounted = mountedApps.pop()
if (!mounted) throw new Error('Failed to find mounted persistence app')
mounted.app.unmount()
mounted.container.remove()

window.dispatchEvent(new PageTransitionEvent('pagehide'))
await vi.runAllTimersAsync()

expect(
localStorage.getItem(StorageKeys.draftPayload(workflow.path, 'personal'))
).toBeNull()
})

it('flushes the final source-workspace edit before blocking transition writes', async () => {
const sourceWorkspaceId = 'workspace-a'
const destinationWorkspaceId = 'workspace-b'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@ export function useWorkflowPersistenceV2() {

// Debounced version for graphChanged events
const debouncedPersist = debounce(persistCurrentWorkflow, PERSIST_DEBOUNCE_MS)
const unregisterPersistenceFlush = registerWorkflowPersistenceFlush(() =>

function flushPendingPersistence() {
debouncedPersist.flush()
}

const unregisterPersistenceFlush = registerWorkflowPersistenceFlush(
flushPendingPersistence
)
window.addEventListener('pagehide', flushPendingPersistence)

const loadPreviousWorkflowFromStorage = async () => {
const sessionPath = tabState.getActivePath()
Expand Down Expand Up @@ -259,6 +265,7 @@ export function useWorkflowPersistenceV2() {
// Clean up event listener when component unmounts
tryOnScopeDispose(() => {
api.removeEventListener('graphChanged', debouncedPersist)
window.removeEventListener('pagehide', flushPendingPersistence)
unregisterPersistenceFlush()
debouncedPersist.cancel()
})
Expand Down
Loading