[go_router] Fix popRoute crash when a shell route's navigator is not mounted#12111
Open
brotoo25 wants to merge 1 commit into
Open
[go_router] Fix popRoute crash when a shell route's navigator is not mounted#12111brotoo25 wants to merge 1 commit into
brotoo25 wants to merge 1 commit into
Conversation
…mounted GoRouterDelegate._findCurrentNavigators force-unwraps each shell navigator's state while walking the current configuration. When the system back button is pressed while the configuration references a shell route whose navigator is not mounted (e.g. mid-redirect away from the shell, or while resuming from background), popRoute throws 'Null check operator used on a null value'. Stop walking when a shell navigator is not mounted, matching the null-tolerant handling canPop already uses for the same state. Fixes flutter/flutter#188993
Contributor
There was a problem hiding this comment.
Code Review
This pull request addresses a potential crash in popRoute() within GoRouterDelegate when a shell route's navigator is not mounted. The implementation replaces a force-unwrap operator with a null check, breaking the traversal loop if the navigator state is null. A widget test simulating this scenario has been added to prevent regressions, and a pending changelog entry has been created. There are no review comments, and I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GoRouterDelegate._findCurrentNavigators()force-unwraps each shell navigator's state (walker.navigatorKey.currentState!) while walking the current configuration. When the system back button is pressed whilecurrentConfigurationreferences aShellRoutewhose navigator is not mounted — a transient state during redirects away from a shell or when resuming from background —popRoute()throwsNull check operator used on a null valueand crashes the app (observed in production via crash reporting on go_router 17.3.0, Android).This applies the same null-tolerant handling that
canPop()in the same file already uses for this state: if a shell navigator along the chain is not mounted, stop walking — nothing below it can be mounted either. This mirrors the existing early-breakfor pageless routes in the same loop, and the root navigator in this method is already null-guarded in the same way.The added regression test pins the transient state deterministically (configuration pointing at a shell route while the widget tree shows a non-shell route) and fails on
mainwith the exact production stack trace before this change.Related to, but distinct from, flutter/flutter#187616 and #11911: those cover
currentConfiguration.matchesbeing empty (Bad state: No element); this PR fixes the non-empty case where a shell navigator is unmounted. The two changes are independent and compatible.Fixes flutter/flutter#188993
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