mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user