[go_router] Fix: guard empty matches in _findCurrentNavigators and popRoute#11911
[go_router] Fix: guard empty matches in _findCurrentNavigators and popRoute#11911abhaysaqi wants to merge 5 commits into
Conversation
When currentConfiguration.matches is empty (e.g. during startup before first route resolves), calling popRoute() crashed with 'Bad state: No element' from matches.last. Added the same isEmpty guard that canPop() already uses, in both _findCurrentNavigators() and the popRoute() onExit fallback. Fixes #187616
There was a problem hiding this comment.
Code Review
This pull request adds checks to GoRouterDelegate to prevent 'Bad state: No element' errors when currentConfiguration is empty, along with a corresponding widget test. The review feedback suggests using the more idiomatic currentConfiguration.isEmpty instead of checking currentConfiguration.matches.isEmpty directly.
….matches.isEmpty Use more idiomatic `currentConfiguration.isEmpty` consistent with other parts of the codebase such as `currentConfiguration.isNotEmpty` instead of accessing `matches.isEmpty` directly.
|
Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review. |
i don't know what i do now. could u share me with steps .i fixed issue and write fixed issue test case only. |
There was a problem hiding this comment.
Code Review
This pull request introduces checks in GoRouterDelegate to handle cases where currentConfiguration or its matches are empty, preventing potential 'Bad state' exceptions, and adds a test to verify this behavior. The review feedback recommends using currentConfiguration.isEmpty instead of currentConfiguration.matches.isEmpty in the navigator states builder for consistency.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
That is what the checklist is: a set of steps you need to follow.
You need to do all of the steps in the checklist. |
sure |
…b.com/abhaysaqi/packages into fix-go-router-pop-route-empty-matches
abhaysaqi
left a comment
There was a problem hiding this comment.
All checklist items are now complete:
Updated PR title to start with [go_router]
Ran auto-formatter on changed files
Updated CHANGELOG.md with bug fix entry following repository style
Bumped version to 17.3.1 following semantic versioning (patch bump for bug fix)
Updated currentConfiguration.matches.isEmpty to currentConfiguration.isEmpty for consistency with the rest of the codebase
All 27 existing and new tests passing
When currentConfiguration.matches is empty (e.g. during startup before first route resolves), calling popRoute() crashed with 'Bad state: No element' from matches.last.
Added the same isEmpty guard that canPop() already uses, in both _findCurrentNavigators() and the popRoute() onExit fallback.
Fixes #187616
Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. You must list at least one issue.
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.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