Clear cached directional focus history on a non-directional focus request #187957
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to invalidate cached focus traversal policy data when focus shifts outside of an active traversal action, such as during an explicit focus request. It tracks active directional traversals within FocusTraversalGroup and triggers scope invalidation accordingly, supported by a new regression test. The feedback suggests modifying the invalidation logic in _maybeInvalidatePolicyData to use a Set to track and prevent redundant invalidations of the same policy when walking up the focus tree.
justinmc
left a comment
There was a problem hiding this comment.
Thanks for taking a shot at this old and very visible issue.
By the way, what's your setup for creating the gifs with text on them??
358e15c to
66aa9c6
Compare
I use the Giphy Capture app which lets you add captions to a gif |
chunhtai
left a comment
There was a problem hiding this comment.
my latest comment #187957 (comment)
Thanks! Have not had a chance to get back to this yet, will respond once I do! |
08a5d7a to
32a1b2b
Compare
chunhtai
left a comment
There was a problem hiding this comment.
LGTM, left a minor comment.
though this is slightly more fragile than the other approach for example we now relies on defaultTraversalRequestFocusCallback to call request focus on the node. but I can't think of a better way without introducing new API.
cb823b1 to
deaa668
Compare
deaa668 to
c36ce32
Compare
flutter/flutter@1ac2e82...2a2a79d 2026-07-22 [email protected] Clear cached directional focus history on a non-directional focus request (flutter/flutter#187957) 2026-07-22 [email protected] ci: Include root pubspec.yaml in pub cache key (flutter/flutter#189826) 2026-07-22 [email protected] Remove codecov badge from README (flutter/flutter#189728) 2026-07-22 [email protected] Clean android engine/embedding tests (flutter/flutter#189276) 2026-07-22 [email protected] Add barrierBuilder support to showDialog and showGeneralDialog (flutter/flutter#187992) 2026-07-22 [email protected] Fix Mockito dynamic agent loading warnings in Robolectric tests (flutter/flutter#189804) 2026-07-22 [email protected] [iOS] Remove dead RasterThreadMerger plumbing from platform views (flutter/flutter#189753) 2026-07-22 [email protected] Add OverlayPortal.overlayChildLayoutBuilder sample (flutter/flutter#188930) 2026-07-22 [email protected] Automate recurring tasks via workflows - localizations (flutter/flutter#189750) 2026-07-21 [email protected] [iOS] Remove dead parameters and no-op overrides (flutter/flutter#189754) 2026-07-21 [email protected] [iOS] Inject DisplayLinkManager into FlutterViewController (flutter/flutter#189764) 2026-07-21 [email protected] Support custom BoxBorder animation in BoxDecoration (flutter/flutter#186348) 2026-07-21 [email protected] Rename CpuArch.x86_64 to CpuArch.x64 (flutter/flutter#189478) 2026-07-21 [email protected] Roll Skia from 569534e9fa59 to 5e183e5aeac5 (3 revisions) (flutter/flutter#189795) 2026-07-21 [email protected] Roll Dart SDK from 3b2f5ad7718d to 1e65011ee004 (4 revisions) (flutter/flutter#189791) 2026-07-21 [email protected] Run delete-bot-branches.yaml on `pull_request_target` instead of `pull_request` so that we can access secrets. (flutter/flutter#189793) 2026-07-21 [email protected] Batch release directory correction (flutter/flutter#189738) 2026-07-21 [email protected] [flutter_test][Test cross imports] Move TestWidgetsApp to flutter_test (flutter/flutter#189435) 2026-07-21 [email protected] Fix null-deref/double-dispose in StretchingOverscrollIndicator (#189589) (flutter/flutter#189667) 2026-07-21 [email protected] Roll Packages from 611899b to 8260a1e (10 revisions) (flutter/flutter#189782) 2026-07-21 [email protected] [iOS] Inject DisplayLinkManager into FlutterMetalLayer (flutter/flutter#189752) 2026-07-21 [email protected] Derive the SkImage size used by ImageEncodingImpeller::ConvertDlImageToSkImage from the size of the underlying texture, not the size of the DlImage (flutter/flutter#189739) 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 Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
Fixes #85941
When a user traverses focus nodes directionally (e.g. using
up,downarrow keys), we maintain a history stack of visited nodes (calledpolicyData). This allows us to avoid hysteresis when a user switches direction (i.e. switching fromdowntoup) - meaning, the forward traversal path and the reversed traversal path should match.However, before this change, we were not detecting when a focus request occurred due to some outside event (e.g. a direct focus request from a tap on the screen). That means when a user switched direction, we would include the node they had tapped on in the history stack, and unexpectedly visit it.
We now clear the stack (see method
propagateFocusRequest) if a node is focused on outside of a directional navigation event.Before:
With fix:
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot 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.