@@ -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