Skip to content

Saving then loading restores the wrong position when the current page also appears earlier in history #54

Closed

Description

@matt-edmondson

What's wrong

NavigationState<T>.FromNavigationStack (Navigation/Models/NavigationState.cs, ~line 63) rebuilds the current index with FindIndex(item => item.Id == current.Id), which returns the first entry with that Id. When a page appears twice in history (Home → About → Home), the saved index points at the first Home.

Repro

With InMemoryPersistenceProvider: navigate to Home, About, then a new NavigationItem("home", "Home"). Save, then LoadStateAsync() into a new Navigation.

before save: count=3 canBack=True  canFwd=False back=[Home,About]
after load:  count=3 canBack=False canFwd=True  back=[]  fwd=[About,Home]

Expected: the state after load matches the state before save.

Reproduced against the current main build.

Why it matters

Revisiting a page is the normal case in navigation (returning to Home, a dashboard, or a list view). After a restart the user lands at the start of their history, Back is disabled, and Forward replays pages they had already left.

Suggested fix

Save the real index instead of searching for it:

  • Expose it through INavigation<T>, for example a CurrentIndex property, and use it in FromNavigationStack.
  • Without an interface change: GetBackStack().Count gives the index when Current is not null, since the back stack is _items.Take(_currentIndex).

Acceptance criteria

  • The repro restores canBack=True, canFwd=False, back=[Home,About].
  • A regression test with a repeated page.

Activity

  1. matt-edmondson commented on Sep 26, 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

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions