fix: cancel pending RAFs in resetExecutionState and handleExecuting

Prevents a race condition where:
1. A progress WebSocket event arrives and schedules a RAF
2. An execution-end event fires and clears all state
3. The pending RAF callback fires and writes stale data back

https://github.com/Comfy-Org/ComfyUI_frontend/pull/9303#discussion_r2923324838
This commit is contained in:
bymyself
2026-03-15 22:16:33 -07:00
parent 222845d5bc
commit 69a077241e

View File

@@ -296,6 +296,11 @@ export const useExecutionStore = defineStore('execution', () => {
}
function handleExecuting(e: CustomEvent<NodeId | null>): void {
// Cancel any pending progress RAF before clearing state to prevent
// stale data from being written back on the next frame.
progressBatch.cancel()
_pendingProgress = null
// Clear the current node progress when a new node starts executing
_executingNodeProgress.value = null
@@ -520,6 +525,13 @@ export const useExecutionStore = defineStore('execution', () => {
* Reset execution-related state after a run completes or is stopped.
*/
function resetExecutionState(jobIdParam?: string | null) {
// Cancel pending RAFs before clearing state to prevent stale data
// from being written back on the next frame.
progressBatch.cancel()
_pendingProgress = null
progressStateBatch.cancel()
_pendingProgressState = null
executionIdToLocatorCache.clear()
nodeProgressStates.value = {}
const jobId = jobIdParam ?? activeJobId.value ?? null