Skip to content

Commit e7b5a01

Browse files
committed
fix(tables): make runWithoutRecording async-aware so undoRedoInProgress covers full undo execution
1 parent e3f2da4 commit e7b5a01

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

apps/sim/hooks/use-table-undo.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const storeState = {
5050

5151
vi.mock('@/stores/table/store', () => ({
5252
useTableUndoStore: vi.fn((selector: (s: typeof storeState) => unknown) => selector(storeState)),
53-
runWithoutRecording: (fn: () => void) => fn(),
53+
runWithoutRecording: (fn: () => unknown) => Promise.resolve(fn()),
5454
}))
5555

5656
import { useTableUndo } from '@/hooks/use-table-undo'

apps/sim/hooks/use-table-undo.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,19 +355,13 @@ export function useTableUndo({
355355
const undo = useCallback(() => {
356356
const entry = popUndo(tableId)
357357
if (!entry) return
358-
359-
runWithoutRecording(() => {
360-
void executeAction(entry.action, 'undo')
361-
})
358+
void runWithoutRecording(() => executeAction(entry.action, 'undo'))
362359
}, [popUndo, tableId, executeAction])
363360

364361
const redo = useCallback(() => {
365362
const entry = popRedo(tableId)
366363
if (!entry) return
367-
368-
runWithoutRecording(() => {
369-
void executeAction(entry.action, 'redo')
370-
})
364+
void runWithoutRecording(() => executeAction(entry.action, 'redo'))
371365
}, [popRedo, tableId, executeAction])
372366

373367
return { pushUndo, undo, redo, canUndo, canRedo }

apps/sim/stores/table/store.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ function patchRowIdInEntry(entry: UndoEntry, oldRowId: string, newRowId: string)
8181
}
8282

8383
/**
84-
* Run a function without recording undo entries.
85-
* Used by the hook when executing undo/redo mutations to prevent recursive recording.
84+
* Run a function without recording undo entries. Supports async functions —
85+
* `undoRedoInProgress` stays true until the returned Promise settles, so
86+
* mutations inside `executeAction` don't accidentally push new undo entries.
8687
*/
87-
export function runWithoutRecording<T>(fn: () => T): T {
88+
export async function runWithoutRecording<T>(fn: () => T | Promise<T>): Promise<T> {
8889
undoRedoInProgress = true
8990
try {
90-
return fn()
91+
return await fn()
9192
} finally {
9293
undoRedoInProgress = false
9394
}

0 commit comments

Comments
 (0)