You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undo still wipes the redo history when a NavigationChanged handler navigates a second stack sharing the provider (#95 only guards the stack being undone) #101
#95 stopped a NavigationChanged handler that navigates during an undo or redo from being recorded as a new action. The guard, though, is per stack. _restoringThreads (Navigation/Services/NavigationStack.cs:35) is an instance field, set in RestoreState (:330-349) and checked in RegisterUndo (:384). So it only suppresses recording on the stack being restored.
NavigationStackFactory gives every stack it creates the same default undo/redo provider (NavigationStackFactory.cs:274/:304), and docs/Usage.md:215-216 documents sharing one provider. When a handler on stack A navigates stack B during A's undo, B records an action into the shared provider while Undo() is still running. That truncates the redo stack.
Repro
Run on main, as a scratch MSTest. Two stacks come from new NavigationStackFactory(new SimpleUndoRedoProvider()): master and detail. Master's NavigationChanged handler calls detail.NavigateTo(...), a detail pane that follows the selection. Navigate master to a, b, c, then undo:
start master=a,b,c detail=d-a,d-b,d-c undo=6 redo=0
Undo True: master=a,b,c cur=c detail=d-a,d-b undo=5 redo=1
Undo True: master=a,b cur=b detail=d-a,d-b,d-b undo=5 redo=0 <- redo wiped, bogus "Navigate to D b" recorded
Undo True: master=a,b cur=b detail=d-a,d-b undo=4 redo=1 <- undo with no visible change to master
Undo True: master=a,b cur=b detail=d-a undo=3 redo=2
Redo True: master=a,b cur=b <- master can never get back to c
Why it matters
This is the failure #95 fixed, reached through a sibling stack. Master/detail panes that follow the selection are an ordinary use of the factory's default shared provider. The user loses redo history for good and is left with phantom undo steps.
Suggested fix / acceptance criteria
Track "applying an undo/redo" per provider, not per stack. Options:
SimpleUndoRedoProvider keeps a per-thread flag while Undo/Redo run and ignores RegisterAction from that thread.
To cover third-party providers too, NavigationStack tracks restoring threads per provider, for example in a static ConditionalWeakTable<IUndoRedoProvider, …> guarded by a lock, and RegisterUndo checks it.
Regression test: the master/detail repro above has redo available after the first undo, and Redo returns master to c.
Category: Bug (undo/redo correctness, concurrency of shared providers)
Priority: High. The default NavigationStackFactory setup shares one provider across stacks, and a master/detail handler is an ordinary use of it. Once this triggers, redo history is lost for good and phantom undo steps are left behind, with no error raised.
Suggested assignment: Navigation maintainer, area Services/NavigationStack + SimpleUndoRedoProvider.
Next step: Take the issue's second option, tracking restoring threads per provider in NavigationStack, so third-party providers are covered too. Then add the master/detail repro as a regression test that expects Redo to return master to c.
Activity
matt-edmondson commentedon Nov 1, 2026
Triage
NavigationStackFactorysetup shares one provider across stacks, and a master/detail handler is an ordinary use of it. Once this triggers, redo history is lost for good and phantom undo steps are left behind, with no error raised.Services/NavigationStack+SimpleUndoRedoProvider.SimpleUndoRedoProviderlose entries under concurrency) and When a NavigationChanged handler throws during Undo, the stack is already undone but the provider records the action as not undone, so Redo is disabled #75 (handler throwing during Undo). Worth designing the per-provider "restoring" guard together with Stacks sharing a SimpleUndoRedoProvider (the NavigationStackFactory default) lose undo entries or throw NullReferenceException under concurrent navigation #89 so the shared-provider story is fixed once.NavigationStack, so third-party providers are covered too. Then add the master/detail repro as a regression test that expects Redo to return master toc.Generated by Claude Code