fix(ui): an undo in the same tick as a rebase steps back to a rebased snapshot

rebase updated the state only, so the mirror the callbacks read still held the removed
row and an undo right after it wrote that row back for a moment.
This commit is contained in:
2026-10-04 04:16:52 +02:00
parent d1df76e8e5
commit 7dbda60815
2 changed files with 26 additions and 4 deletions
+11
View File
@@ -26,4 +26,15 @@ describe("useUndoable", () => {
act(() => result.current.undo());
expect(result.current.value).toEqual([2]);
});
it("undoes to a rebased snapshot when the undo comes in the same tick as the rebase", () => {
const { result } = renderHook(() => useUndoable<number[]>([1, 2]));
act(() => result.current.set([2, 1]));
act(() => {
result.current.rebase((xs) => xs.filter((x) => x !== 2)); // a row removed
result.current.undo();
});
expect(result.current.value).toEqual([1]);
expect(result.current.canRedo).toBe(true);
});
});