Skip to content

[go_router] Add BlockedInitialNavigationException for blocked initial deep links - #12213

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
davidmigloz:upstream-blocked-initial-navigation-exception
Jul 29, 2026
Merged

[go_router] Add BlockedInitialNavigationException for blocked initial deep links#12213
auto-submit[bot] merged 2 commits into
flutter:mainfrom
davidmigloz:upstream-blocked-initial-navigation-exception

Conversation

@davidmigloz

Copy link
Copy Markdown
Contributor

When onEnter returns Block.stop() on the very first navigation attempt (e.g. a deep link on web, before any route has been committed), the parser's onCanNotEnter path has no prior configuration to restore and reports a generic GoException. Apps handling this in onException can't tell "initial deep link blocked" apart from other routing errors (unmatched routes, redirect loops) without string matching on the exception message.

This adds BlockedInitialNavigationException extends GoException, raised specifically in that no-prior-route path. It only refines the exception type — no change to when or whether an exception is thrown, and existing is GoException checks keep working. Apps can now write if (state.error is BlockedInitialNavigationException) in onException and, for example, redirect to a loading screen with the deep link preserved instead of treating it as a 404.

Test: widget test in on_enter_test.dart — initial navigation blocked by Block.stop() with an onException handler; asserts the captured state.error is a BlockedInitialNavigationException (and still a GoException).

Fixes flutter/flutter#189581

Pre-Review Checklist

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

… deep links

When Block.stop() is returned from onEnter with no prior route
configuration (e.g. an initial deep link), the parser now raises a
typed BlockedInitialNavigationException instead of a generic
GoException, so apps can distinguish this case in onException without
string matching.
@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Jul 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 introduces BlockedInitialNavigationException, a subtype of GoException, which is raised when initial navigation is blocked by onEnter without a prior route to restore. The parser is updated to throw this new exception, and a test case is added to verify this behavior. Feedback suggests removing the square brackets around Block in the documentation comments of BlockedInitialNavigationException to avoid unresolved doc reference warnings, since Block is not in scope in errors.dart.

Comment thread packages/go_router/lib/src/misc/errors.dart Outdated
@davidmigloz

davidmigloz commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Heads-up: the onException recovery pattern this exception enables (redirecting away from a blocked initial deep link) only works end-to-end once #12216 lands, that one fixes an assertion crash when onException fires on the initial navigation (flutter/flutter#189582). The two are mergeable independently; landing #12216 first just means the typed exception ships with a working recovery path from day one.

@hannah-hyj hannah-hyj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A new exception type sounds good to me

@hannah-hyj
hannah-hyj requested a review from chunhtai July 28, 2026 22:46
@chunhtai chunhtai added the CICD Run CI/CD label Jul 29, 2026

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

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 29, 2026
@auto-submit
auto-submit Bot merged commit 1448f08 into flutter:main Jul 29, 2026
14 checks passed
navaronbracke pushed a commit to navaronbracke/flutter that referenced this pull request Jul 29, 2026
…er#190216)

flutter/packages@3e63635...dd11626

2026-07-29 stuartmorgan@google.com [pigeon] Clean up legacy registrant
code (flutter/packages#12205)
2026-07-29 me@davidmiguel.com [go_router] Add
BlockedInitialNavigationException for blocked initial deep links
(flutter/packages#12213)
2026-07-28 stuartmorgan@google.com [file_selector] Switch to Swift
Testing (flutter/packages#12235)
2026-07-28 269567208+reidbaker-agent@users.noreply.github.com Exempt
evals directories from version checks (flutter/packages#12299)
2026-07-28 dkwingsmt@users.noreply.github.com [material_ui,
cupertino_ui] Migrate macros that contain `@tool`
(flutter/packages#12271)
2026-07-28 katelovett@google.com [material_ui, cupertino_ui] Fix API doc
references (flutter/packages#12274)
2026-07-28 43054281+camsim99@users.noreply.github.com
[camera_android_camerax] Delete `GeneratedCameraxLibrary.java`
(flutter/packages#12294)
2026-07-28 engine-flutter-autoroll@skia.org Roll Flutter from
9988960 to 0f02463 (16 revisions) (flutter/packages#12300)
2026-07-28 developeryusuf@icloud.com [vector_graphics_compiler] Ignore
unrecognized font-weight values (flutter/packages#12199)
2026-07-28 stuartmorgan@google.com [tool] Support promoting to 1.0 in
batch releases (flutter/packages#12262)
2026-07-28 1063596+reidbaker@users.noreply.github.com ci: Fix Zizmor
github-env failure in install_flutter action (flutter/packages#12298)

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 flutter-ecosystem@google.com 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
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] Cannot distinguish a blocked initial deep link from other routing errors in onException

3 participants