Skip to content

[go_router] Fix: guard empty matches in _findCurrentNavigators and popRoute#11911

Draft
abhaysaqi wants to merge 5 commits into
flutter:mainfrom
abhaysaqi:fix-go-router-pop-route-empty-matches
Draft

[go_router] Fix: guard empty matches in _findCurrentNavigators and popRoute#11911
abhaysaqi wants to merge 5 commits into
flutter:mainfrom
abhaysaqi:fix-go-router-pop-route-empty-matches

Conversation

@abhaysaqi

@abhaysaqi abhaysaqi commented Jun 16, 2026

Copy link
Copy Markdown

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

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-assist bot 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

  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

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
@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Jun 16, 2026

@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 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.

Comment thread packages/go_router/lib/src/delegate.dart Outdated
Comment thread packages/go_router/lib/src/delegate.dart Outdated
….matches.isEmpty

Use more idiomatic `currentConfiguration.isEmpty` consistent with
other parts of the codebase such as `currentConfiguration.isNotEmpty`
instead of accessing `matches.isEmpty` directly.
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

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.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft June 16, 2026 10:11
@abhaysaqi

Copy link
Copy Markdown
Author

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.

@abhaysaqi abhaysaqi changed the title Fix: guard empty matches in _findCurrentNavigators and popRoute [go_router] Fix: guard empty matches in _findCurrentNavigators and popRoute Jun 16, 2026
@abhaysaqi abhaysaqi marked this pull request as ready for review June 16, 2026 14:25

@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 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.

Comment thread packages/go_router/lib/src/delegate.dart Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@abhaysaqi abhaysaqi left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed issue

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

i don't know what i do now. could u share me with steps

That is what the checklist is: a set of steps you need to follow.

i fixed issue and write fixed issue test case only.

You need to do all of the steps in the checklist.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft June 17, 2026 02:32
@abhaysaqi

Copy link
Copy Markdown
Author

i don't know what i do now. could u share me with steps

That is what the checklist is: a set of steps you need to follow.

i fixed issue and write fixed issue test case only.

You need to do all of the steps in the checklist.

sure

@abhaysaqi abhaysaqi left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: go_router triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants