go_router: clarify onEnter/redirect ordering, add regression test - #12337
go_router: clarify onEnter/redirect ordering, add regression test#12337developerashkan wants to merge 5 commits into
Conversation
|
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. |
There was a problem hiding this comment.
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.
|
@googlebot I signed it! |
Piinks
left a comment
There was a problem hiding this comment.
Hey @developerashkan thanks for contributing!
Co-authored-by: Kate Lovett <katelovett@google.com>
|
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. |
What this does
Clarifies the
onEnterdoc comment onRoutingConfigto explicitly warnthat
onEnteris 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 ofonEnter).Why
flutter/flutter#188014 reports what looks like a bug: an
onEnterguardchecking for an intermediate redirect target (
/a, reached via aredirect:on/) never fires. Tracing the pipeline shows this isactually intended, existing behavior — see the
'onEnter called once when top-level redirect chains'test (written forthe 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).