Skip to content

[go_router] Keep web autocomplete focused in shell routes - #13348

Merged
flutter-zl merged 3 commits into
flutter:mainfrom
agpdl:fix/go-router-shell-autocomplete-focus
Oct 22, 2026
Merged

flutter-zl merged 3 commits into
flutter:mainfrom
agpdl:fix/go-router-shell-autocomplete-focus

Conversation

@agpdl

@agpdl agpdl commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes flutter/flutter#194873. Opening an Autocomplete overlay inside a ShellRoute can add a semantics parent above the focused field. On Flutter web, that detaches the field's DOM input and drops focus.

 ShellRoute navigator semantics
-  Semantics(container: true, child: navigator)
+  Semantics(container: true, explicitChildNodes: true, child: navigator)

The change keeps the field's semantics ancestry stable while retaining the shell navigator boundary added to preserve shell chrome semantics. It includes a regression test and a pending patch changelog entry for the batched release workflow.

Evidence

  • Before: The regression test fails on unmodified main: the focused field's semantics ancestor IDs change from [6, 4, 3, 2, 1, 0] to [6, 4, 7, 3, 2, 1, 0] when options open. In a Chrome release web repro with published go_router 18.1.1, typing t, e, x leaves the field empty and browser focus leaves the input.
  • After: The regression test passes. In the same Chrome repro with the patched package, the field retains browser focus and contains tex; shell navigation remains in the semantics tree.
  • Checks: format, analyze, dart-test, validate, and publish-check through flutter_plugin_tools pass for go_router. The package and example tests pass.

Merge Danger

Door: Two-way. The patch can be reverted without data migration.

Blast Radius: ShellRoute semantics trees. Explicit child nodes can affect accessibility traversal and announcements for routed content; existing shell chrome semantics tests and the new overlay regression test pass. Human review should include accessibility behavior on supported platforms.

Pre-Review Checklist

No public API or doc comments changed; the bug fix does not introduce a new API. go_router uses pending changelog files for batched releases; this PR adds a patch entry there. This PR was prepared with AI assistance and reviewed by the contributor.

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

@google-cla

google-cla Bot commented Oct 20, 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.

The shell navigator semantics boundary added in 18.0.2 can reparent a focused autocomplete field when its options overlay opens. On web, moving the semantic input in the DOM blurs it before the user can type.

Require explicit child semantics nodes within the shell boundary. Add a regression test for the field parent and retain the existing shell chrome tests.
@agpdl
agpdl force-pushed the fix/go-router-shell-autocomplete-focus branch from dac4c98 to 54d384e Compare October 20, 2026 16:37
@agpdl
agpdl marked this pull request as ready for review October 20, 2026 16:37

@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 configures the Semantics widget in the shell navigator to use explicitChildNodes, which prevents web text fields from losing focus when an autocomplete overlay opens. A test has been added to verify this behavior. The review feedback recommends using addTearDown for disposing of the SemanticsHandle in the new test to ensure robust cleanup, and removing the manual disposal call.

testWidgets('Opening autocomplete options does not reparent the focused field', (
WidgetTester tester,
) async {
final SemanticsHandle semantics = tester.ensureSemantics();

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.

medium

Using addTearDown(semantics.dispose) is a safer and more robust pattern than manual disposal. If an assertion fails during the test execution, manual disposal at the end of the test will be skipped, potentially leaking the semantics handle and causing subsequent tests to fail or behave unexpectedly.

Suggested change
final SemanticsHandle semantics = tester.ensureSemantics();
final SemanticsHandle semantics = tester.ensureSemantics();
addTearDown(semantics.dispose);

agpdl added 2 commits October 20, 2026 13:46
The widget test framework checks for leaked semantics handles before addTearDown callbacks run. Use try/finally so the regression test closes its handle even when an assertion fails.
@flutter-zl flutter-zl added the CICD Run CI/CD label Oct 21, 2026
@flutter-zl
flutter-zl self-requested a review October 21, 2026 17:33

@flutter-zl flutter-zl 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, thanks for the fix and the clear writeup.

I verified this independently on Flutter 3.47.5 with a Chrome repro: with published go_router 18.1.1 the first click into the Autocomplete field blurs the semantics <input> as soon as the options overlay opens, because the navigator subtree gets forked into a new semantics node and the route node is re-parented under it. With this branch the ancestor chain of the focused field stays identical before and after the overlay opens, and typing works.

Before: https://flutter-demo-78-before.web.app
After: https://flutter-demo-78-after.web.app

@flutter-zl flutter-zl added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 22, 2026
@flutter-zl
flutter-zl merged commit e872aea into flutter:main Oct 22, 2026
14 checks passed
bkonyi pushed a commit to bkonyi/flutter that referenced this pull request Oct 23, 2026
flutter/packages@93baed9...108dad0

2026-10-22 [email protected] [material_ui]
Migrate M3 IconButton template to use new gen_defaults
(flutter/packages#12922)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationBar template to use new gen_defaults
(flutter/packages#13067)
2026-10-22 [email protected] [material_ui]
Remove obsolete `SurfaceTint` defaults template (flutter/packages#13276)
2026-10-22 [email protected] [material_ui]
Migrate M3 Radio template to use new gen_defaults
(flutter/packages#13210)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationDrawer template to use new gen_defaults
(flutter/packages#13068)
2026-10-22 [email protected] [image_picker_ios] PR 3/5 Split
SPM packaging and migrate the plugin class to Swift
(flutter/packages#13235)
2026-10-22 [email protected] [ci] Increase check-discovery timeout
in release workflows (flutter/packages#13392)
2026-10-22 [email protected] [material_ui]
Migrate M3 `Switch` template to use new gen_defaults
(flutter/packages#13274)
2026-10-22 [email protected] [material_ui]
Migrate M3 PopupMenu template to use new gen_defaults
(flutter/packages#13209)
2026-10-22 [email protected] [material_ui] Add day and weekday
builders to CalendarDatePicker and showDatePicker
(flutter/packages#12587)
2026-10-22 [email protected] [material_ui]
Migrate M3 `SearchView` template to use new gen_defaults
(flutter/packages#13272)
2026-10-22 [email protected] [material_ui]
Migrate M3 `TextField` template to use new gen_defaults
(flutter/packages#13275)
2026-10-22 [email protected] [material_ui]
Migrate M3 RangeSlider template to use new gen_defaults
(flutter/packages#13215)
2026-10-22 [email protected] [go_router] Keep web
autocomplete focused in shell routes (flutter/packages#13348)
2026-10-22 [email protected] [shared_preferences_android] Fix web
compilation of apps that import the package (flutter/packages#13380)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationRail template to use new gen_defaults
(flutter/packages#13069)
2026-10-22 [email protected] [material_ui]
Migrate M3 SearchBar template to use new gen_defaults
(flutter/packages#13216)
2026-10-22 [email protected] [material_ui] Fix for time picker error
in locales that do not use Latin digits (flutter/packages#13035)
2026-10-22 [email protected] [material_ui]
Fix MenuAnchor scrollbar safe-area padding (flutter/packages#12470)
2026-10-22 [email protected] [material_ui] Document Material 3
fallback for Divider.color and VerticalDivider.color
(flutter/packages#12967)
2026-10-22 [email protected]
[material_ui] Migrate M3 tabs template to use new gen_defaults
(flutter/packages#13139)
2026-10-22 [email protected] [material_ui]
Migrate M3 progress indicator defaults to new gen_defaults
(flutter/packages#13026)
2026-10-22 [email protected] [google_sign_in] Convert the iOS
example app and UI tests to Swift (flutter/packages#13271)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode 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
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@93baed9...108dad0

2026-10-22 [email protected] [material_ui]
Migrate M3 IconButton template to use new gen_defaults
(flutter/packages#12922)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationBar template to use new gen_defaults
(flutter/packages#13067)
2026-10-22 [email protected] [material_ui]
Remove obsolete `SurfaceTint` defaults template (flutter/packages#13276)
2026-10-22 [email protected] [material_ui]
Migrate M3 Radio template to use new gen_defaults
(flutter/packages#13210)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationDrawer template to use new gen_defaults
(flutter/packages#13068)
2026-10-22 [email protected] [image_picker_ios] PR 3/5 Split
SPM packaging and migrate the plugin class to Swift
(flutter/packages#13235)
2026-10-22 [email protected] [ci] Increase check-discovery timeout
in release workflows (flutter/packages#13392)
2026-10-22 [email protected] [material_ui]
Migrate M3 `Switch` template to use new gen_defaults
(flutter/packages#13274)
2026-10-22 [email protected] [material_ui]
Migrate M3 PopupMenu template to use new gen_defaults
(flutter/packages#13209)
2026-10-22 [email protected] [material_ui] Add day and weekday
builders to CalendarDatePicker and showDatePicker
(flutter/packages#12587)
2026-10-22 [email protected] [material_ui]
Migrate M3 `SearchView` template to use new gen_defaults
(flutter/packages#13272)
2026-10-22 [email protected] [material_ui]
Migrate M3 `TextField` template to use new gen_defaults
(flutter/packages#13275)
2026-10-22 [email protected] [material_ui]
Migrate M3 RangeSlider template to use new gen_defaults
(flutter/packages#13215)
2026-10-22 [email protected] [go_router] Keep web
autocomplete focused in shell routes (flutter/packages#13348)
2026-10-22 [email protected] [shared_preferences_android] Fix web
compilation of apps that import the package (flutter/packages#13380)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationRail template to use new gen_defaults
(flutter/packages#13069)
2026-10-22 [email protected] [material_ui]
Migrate M3 SearchBar template to use new gen_defaults
(flutter/packages#13216)
2026-10-22 [email protected] [material_ui] Fix for time picker error
in locales that do not use Latin digits (flutter/packages#13035)
2026-10-22 [email protected] [material_ui]
Fix MenuAnchor scrollbar safe-area padding (flutter/packages#12470)
2026-10-22 [email protected] [material_ui] Document Material 3
fallback for Divider.color and VerticalDivider.color
(flutter/packages#12967)
2026-10-22 [email protected]
[material_ui] Migrate M3 tabs template to use new gen_defaults
(flutter/packages#13139)
2026-10-22 [email protected] [material_ui]
Migrate M3 progress indicator defaults to new gen_defaults
(flutter/packages#13026)
2026-10-22 [email protected] [google_sign_in] Convert the iOS
example app and UI tests to Swift (flutter/packages#13271)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode 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
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router][web] Autocomplete field loses focus in ShellRoute with semantics enabled

2 participants