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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user