mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-22 13:32:11 +00:00
## Summary When a socket disconnects messages can be missed and lead to a stale UI state, this updates the state on reconnect and clears the active job if it is no longer running ## Changes - **What**: - add call to update queue on reconnect - clear active job if job not in queue response - tests ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-12067-fix-clear-active-job-on-reconnect-if-no-longer-in-queue-3596d73d365081f79d42d73966420c50) by [Unito](https://www.unito.io)
26 lines
966 B
TypeScript
26 lines
966 B
TypeScript
import { useExecutionStore } from '@/stores/executionStore'
|
|
import { useQueueStore } from '@/stores/queueStore'
|
|
|
|
/**
|
|
* After a WebSocket reconnect, refresh the queue from the server and clear
|
|
* any active job that finished during the disconnect window. Returns the
|
|
* handler so the caller can wire it to the `reconnected` api event.
|
|
*
|
|
* `update()` preserves the previous queue snapshot when the fetch fails, so
|
|
* if the network is still flaky we reconcile against the last known good
|
|
* state rather than an empty (and falsely "stale") set.
|
|
*/
|
|
export function useReconnectQueueRefresh() {
|
|
const queueStore = useQueueStore()
|
|
const executionStore = useExecutionStore()
|
|
|
|
return async function refreshOnReconnect() {
|
|
await queueStore.update()
|
|
const activeJobIds = new Set([
|
|
...queueStore.runningTasks.map((t) => t.jobId),
|
|
...queueStore.pendingTasks.map((t) => t.jobId)
|
|
])
|
|
executionStore.clearActiveJobIfStale(activeJobIds)
|
|
}
|
|
}
|