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
Stacks sharing a SimpleUndoRedoProvider (the NavigationStackFactory default) lose undo entries or throw NullReferenceException under concurrent navigation #89
SimpleUndoRedoProvider (Navigation/Services/SimpleUndoRedoProvider.cs) wraps an unsynchronized undo/redo service. Its RegisterAction (about line 57), Undo (about line 66) and Redo (about line 92) take no lock.
NavigationStackFactory (Navigation/Services/NavigationStackFactory.cs, about lines 16 and 27) gives every stack it creates the same default provider. NavigationStack.NavigateTo calls RegisterAction under the stack's own lock (about line 355), but that lock does nothing for a provider shared across stacks. provider.Undo() runs outside any stack lock at all.
The README advertises "✅ Thread-safe operations". #57 asked for the same protection on SimpleUndoRedoProvider, but it was closed by #83, which locked only Navigation<T>.
Most runs ended with 9,939 to 9,999 entries, and three threw NullReferenceException. A concurrent provider.Undo() while a single stack navigates hits the same race.
Suggested fix
Add a private lock in SimpleUndoRedoProvider covering RegisterAction, Clear, CanUndo/CanRedo and GetUndoStack/GetRedoStack.
For Undo/Redo, do not run the action while holding the provider lock. action.Undo → RestoreState takes the stack lock, while NavigateTo holds the stack lock and then calls RegisterAction, so that ordering would deadlock. Instead, pop the action and move the position under the lock, release it, run the action, and re-lock to revert if it throws.
Alternatively, if the provider is not meant to be shared across threads, document that, stop sharing a single default instance across factory-created stacks, and qualify the README claim.
Acceptance criteria
The parallel repro always yields 10,000 undo entries with no exception.
A concurrent Undo + NavigateTo test neither deadlocks nor throws.
Priority: High. The default NavigationStackFactory configuration loses undo entries, or throws NullReferenceException, in 20 of 20 concurrent runs, while the README advertises thread-safe operation. Fixing it needs care: running the undo action while holding the provider lock would deadlock against NavigateTo, so follow the pop / release / run / re-lock ordering the issue describes.
Area / suggested assignment: Navigation SimpleUndoRedoProvider and the shared default instance in NavigationStackFactory.
Activity
matt-edmondson commentedon Oct 18, 2026
Triage
NavigationStackFactoryconfiguration loses undo entries, or throwsNullReferenceException, in 20 of 20 concurrent runs, while the README advertises thread-safe operation. Fixing it needs care: running the undo action while holding the provider lock would deadlock againstNavigateTo, so follow the pop / release / run / re-lock ordering the issue describes.SimpleUndoRedoProviderand the shared default instance inNavigationStackFactory.Navigation<T>. Related to NavigationState.FromNavigationStack throws ArgumentOutOfRangeException (or records the wrong position) while another thread navigates or clears #88 (concurrency inNavigationState.FromNavigationStack), a different code path. Not a duplicate.Generated by Claude Code