Skip to content

[go_router] Clarify onEnter/redirect ordering, add regression test - #12337

Merged
auto-submit[bot] merged 14 commits into
flutter:mainfrom
developerashkan:docs/onenter-redirect-chain-visibility
Aug 24, 2026
Merged

auto-submit[bot] merged 14 commits into
flutter:mainfrom
developerashkan:docs/onenter-redirect-chain-visibility

Conversation

@developerashkan

@developerashkan developerashkan commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Clarifies the onEnter doc comment on RoutingConfig to explicitly warn
that onEnter is evaluated once, against the literal navigated-to URI,
and is never re-invoked for locations reached only through a redirect:
chain. Adds a regression test locking in this behavior for the exact
scenario reported in flutter/flutter#188014, plus a second test
demonstrating the correct workaround (putting the guard inside
redirect: instead of onEnter).

Why

flutter/flutter#188014 reports what looks like a bug: an onEnter guard
checking for an intermediate redirect target (/a, reached via a
redirect: on /) never fires. Tracing the pipeline shows this is
actually intended, existing behavior — see the
'onEnter called once when top-level redirect chains' test (written for
the related #178984), which asserts the same ordering. The docs didn't
make this ordering/visibility gap explicit though, so it's an easy trap.
This PR closes that documentation gap and adds test coverage so the
behavior can't silently change without a test failing.

Related

Fixes flutter/flutter#188014 (as a documentation clarification, not a
behavior change — see discussion on the issue).

Pre-Review Checklist

Important

This PR was prepared with assistance from an AI agent (Claude). The
code, doc comment, and tests have been reviewed by the author, who
understands the change and takes responsibility for it.

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

@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Aug 1, 2026
@google-cla

google-cla Bot commented Aug 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 documentation for RoutingConfig.onEnter in go_router to clarify that onEnter is evaluated exactly once per navigation against the literal target URI, strictly before redirects run. It also adds regression tests in on_enter_test.dart to verify this behavior and demonstrate how to guard redirect targets. Feedback on the changes suggests simplifying a test route definition by removing an unused builder callback on a route that always redirects.

Comment thread packages/go_router/test/on_enter_test.dart
@developerashkan

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

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

Hey @developerashkan thanks for contributing!

Comment thread packages/go_router/lib/src/router.dart Outdated
Comment thread packages/go_router/test/on_enter_test.dart Outdated
Comment thread packages/go_router/test/on_enter_test.dart
@developerashkan
developerashkan requested a review from Piinks August 7, 2026 06:29
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Because of the volume of PRs we receive, we require that new contributors use our checklist to guide them through critical steps in creating a Flutter PR. This PR's description is missing that checklist, and is missing required elements from the checklist.

Please edit the PR description to add the checklist, then ensure that you have completed all of the steps. If you need help, consider asking for advice on the #hackers-new channel on Discord.

@Piinks Piinks added the CICD Run CI/CD label Aug 7, 2026
@developerashkan developerashkan changed the title go_router: clarify onEnter/redirect ordering, add regression test [go_router] Clarify onEnter/redirect ordering, add regression test Aug 12, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 12, 2026
@developerashkan
developerashkan deleted the docs/onenter-redirect-chain-visibility branch August 14, 2026 04:40
@developerashkan
developerashkan restored the docs/onenter-redirect-chain-visibility branch August 14, 2026 04:41
@fluttergithubbot

Copy link
Copy Markdown
Contributor

An existing Git SHA, d245a32e94e7e4fec0f698bab08316257a7045b4, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

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

LGTM

@Piinks Piinks added the CICD Run CI/CD label Aug 19, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 21, 2026
@developerashkan
developerashkan requested a review from Piinks August 23, 2026 05:55
@Piinks Piinks added the CICD Run CI/CD label Aug 24, 2026

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

Re-LGTM

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 24, 2026
@auto-submit
auto-submit Bot merged commit b16aef1 into flutter:main Aug 24, 2026
14 checks passed
zijiehe-google-com pushed a commit to zijiehe-google-com/flutter that referenced this pull request Aug 25, 2026
…er#191734)

flutter/packages@df2ba94...740f093

2026-08-25 [email protected] [cupertino_ui] Remove unused parameters
from constructors of generic classes. (flutter/packages#12457)
2026-08-25 [email protected] [material_ui] Remove unused parameters
from constructors of generic classes. (flutter/packages#12458)
2026-08-25 [email protected] Ignore shared code
for iOS platform implementation of Google Maps plugin
(flutter/packages#12529)
2026-08-25 [email protected] [cross_file]
fixed `readAsString` decoding in-memory bytes as UTF-16
(flutter/packages#12479)
2026-08-25 [email protected] [cupertino_ui] Remove two items assert to
allow CupertinoTabBar to have one tab (flutter/packages#12546)
2026-08-25 [email protected] [cupertino_ui] Fix covered sheet revealing
root route through top gap (flutter/packages#12530)
2026-08-25 [email protected] Sync release-go_router-18.0.0 to
main (flutter/packages#12575)
2026-08-25 [email protected] Sync release-material_ui-1.1.0 to
main (flutter/packages#12577)
2026-08-25 [email protected] Sync release-cupertino_ui-1.0.1 to
main (flutter/packages#12576)
2026-08-24 [email protected]
[quick_actions_ios]unskip XCUITests (flutter/packages#12436)
2026-08-24 [email protected] Fix RangeSlider thumb overlay
remains visible after touch interaction ends (flutter/packages#12560)
2026-08-24 [email protected] [google_sign_in] Increase iOS
coverage tests (flutter/packages#12484)
2026-08-24 [email protected]
[camera_android_camerax] Migrate from dart_skills_lint to skills_lint
(flutter/packages#12543)
2026-08-24 [email protected] [go_router]
Clarify onEnter/redirect ordering, add regression test
(flutter/packages#12337)
2026-08-24 [email protected] [material_ui] Port
flutter/flutter flutter#185149 "Slider label clips the screen"
(flutter/packages#12572)
2026-08-24 [email protected] Roll Flutter from
65c9a8d to 9a82789 (17 revisions) (flutter/packages#12578)
2026-08-24 [email protected] [tool] Fix dart_test.yaml parsing
(flutter/packages#12574)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
jagadeesh8682 pushed a commit to jagadeesh8682/packages that referenced this pull request Sep 2, 2026
…lutter#12337)

## What this does

Clarifies the `onEnter` doc comment on `RoutingConfig` to explicitly warn
that `onEnter` is evaluated once, against the literal navigated-to URI,
and is never re-invoked for locations reached only through a `redirect:`
chain. Adds a regression test locking in this behavior for the exact
scenario reported in flutter/flutter#188014, plus a second test
demonstrating the correct workaround (putting the guard inside
`redirect:` instead of `onEnter`).

## Why

flutter/flutter#188014 reports what looks like a bug: an `onEnter` guard
checking for an intermediate redirect target (`/a`, reached via a
`redirect:` on `/`) never fires. Tracing the pipeline shows this is
actually intended, existing behavior — see the
`'onEnter called once when top-level redirect chains'` test (written for
the related #178984), which asserts the same ordering. The docs didn't
make this ordering/visibility gap explicit though, so it's an easy trap.
This PR closes that documentation gap and adds test coverage so the
behavior can't silently change without a test failing.

## Related

Fixes flutter/flutter#188014 (as a documentation clarification, not a
behavior change — see discussion on the issue).

## Pre-Review Checklist

> [!IMPORTANT]
> This PR was prepared with assistance from an AI agent (Claude). The
> code, doc comment, and tests have been reviewed by the author, who
> understands the change and takes responsibility for it.

[^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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD 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.

[go_router] onEnter only triggers once (no recursive redirection)

5 participants