Repository navigation
Conversation
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
There was a problem hiding this comment.
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.
| if (infoState.type == NavigatingType.restore && | ||
| restoreBase != null && | ||
| restoreBase.uri.toString() == incomingMatches.uri.toString()) { |
There was a problem hiding this comment.
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.
| if (infoState.type == NavigatingType.restore && | |
| restoreBase != null && | |
| restoreBase.uri.toString() == incomingMatches.uri.toString()) { | |
| if (infoState.type == NavigatingType.restore && | |
| restoreBase != null && | |
| restoreBase.uri == incomingMatches.uri) { |
After a
push, the URL stays on the base route (for example/homewith/loginpushed on top). WhenrefreshListenablefires, the router gets a restore of/homethat carries the pushed match list._updateRouteMatchListkeeps that list because the URI didn't change, so navigation is fine, but the top-levelonEnterbuiltnextStatefromfindMatch('/home'), so the guard saw/homeas the next page whilecurrentStatewas/login.For a restore to the same URI,
onEnternow gets the base match list asnextState, 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, firerefreshListenable, and check both states are/login. It fails on main (nextis/home) and passes with the change. All go_router tests pass.Fixes flutter/flutter#179216
Pre-Review Checklist
[shared_preferences]///).Footnotes
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