Skip to content

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

Open

Description

@matt-edmondson

What's wrong

#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.

Activity

  1. added
    bug
    on Oct 31, 2026
  2. matt-edmondson commented on Nov 1, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions