Skip to content

[go_router] Keep pushed routes in onEnter's next state on refresh - #13770

Open
yeegz wants to merge 1 commit into
flutter:mainfrom
yeegz:fix/179216-onenter-next-state-on-refresh
Open

yeegz wants to merge 1 commit into
flutter:mainfrom
yeegz:fix/179216-onenter-next-state-on-refresh

Conversation

@yeegz

@yeegz yeegz commented Nov 23, 2026

Copy link
Copy Markdown

After a push, the URL stays on the base route (for example /home with /login pushed on top). When refreshListenable fires, the router gets a restore of /home that carries the pushed match list. _updateRouteMatchList keeps that list because the URI didn't change, so navigation is fine, but the top-level onEnter built nextState from findMatch('/home'), so the guard saw /home as the next page while currentState was /login.

For a restore to the same URI, onEnter now gets the base match list as nextState, the same list navigation keeps. Nothing else uses that value, so navigation itself is unchanged.

Added a test in on_enter_test.dart: push /login, fire refreshListenable, and check both states are /login. It fails on main (next is /home) and passes with the change. All go_router tests pass.

Fixes flutter/flutter#179216

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

After a push the URL stays on the base route, so a refresh comes back as
a restore of that URI. Navigation keeps the current match list in that
case, but onEnter built nextState from the URI alone and lost the pushed
route.

Fixes flutter/flutter#179216

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the _OnEnterHandler in parser.dart to reuse the restoreBase match list when restoring to the same URI, addressing an issue where the top-level onEnter callback receives the incorrect nextState when refreshListenable fires after a push. A corresponding widget test has been added to verify this behavior. The review feedback suggests comparing Uri objects directly using == instead of converting them to strings via toString() for better efficiency and idiomatic Dart code.

Comment on lines +409 to +411
if (infoState.type == NavigatingType.restore &&
restoreBase != null &&
restoreBase.uri.toString() == incomingMatches.uri.toString()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Comparing Uri objects directly using == is more efficient and idiomatic in Dart than converting them to strings first via toString(). Since Uri overrides operator == to compare all its components (scheme, host, path, query, fragment, etc.), direct comparison is semantically equivalent and avoids unnecessary string allocations.

Suggested change
if (infoState.type == NavigatingType.restore &&
restoreBase != null &&
restoreBase.uri.toString() == incomingMatches.uri.toString()) {
if (infoState.type == NavigatingType.restore &&
restoreBase != null &&
restoreBase.uri == incomingMatches.uri) {

@github-actions github-actions Bot added p: go_router P2 Important issues not at the top of the work list labels Nov 23, 2026
@loic-sharma
loic-sharma requested a review from Piinks November 24, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: go_router P2 Important issues not at the top of the work list

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] new top-level onEnter callback nextState problem

1 participant