Skip to content

Commit 865a5bb

Browse files
committed
fix debounce flush
1 parent bd827d4 commit 865a5bb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apps/sim/hooks/use-code-undo-redo.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,25 @@ export function useCodeUndoRedo({
186186

187187
const undo = useCallback(() => {
188188
if (!activeWorkflowId || !isEnabled) return
189+
if (pendingBeforeRef.current !== null) {
190+
flushPending()
191+
}
189192
const entry = useCodeUndoRedoStore.getState().undo(activeWorkflowId, blockId, subBlockId)
190193
if (!entry) return
191194
logger.debug('Undo code edit', { blockId, subBlockId })
192195
applyValue(entry.before)
193-
}, [activeWorkflowId, applyValue, blockId, isEnabled, subBlockId])
196+
}, [activeWorkflowId, applyValue, blockId, flushPending, isEnabled, subBlockId])
194197

195198
const redo = useCallback(() => {
196199
if (!activeWorkflowId || !isEnabled) return
200+
if (pendingBeforeRef.current !== null) {
201+
flushPending()
202+
}
197203
const entry = useCodeUndoRedoStore.getState().redo(activeWorkflowId, blockId, subBlockId)
198204
if (!entry) return
199205
logger.debug('Redo code edit', { blockId, subBlockId })
200206
applyValue(entry.after)
201-
}, [activeWorkflowId, applyValue, blockId, isEnabled, subBlockId])
207+
}, [activeWorkflowId, applyValue, blockId, flushPending, isEnabled, subBlockId])
202208

203209
useEffect(() => {
204210
if (isApplyingRef.current) return

0 commit comments

Comments
 (0)