Skip to content

[web] do not send SemanticsAction.focus inside frame#162554

Merged
yjbanov merged 3 commits intoflutter:masterfrom
yjbanov:semantic-action-inside-frame
Feb 4, 2025
Merged

[web] do not send SemanticsAction.focus inside frame#162554
yjbanov merged 3 commits intoflutter:masterfrom
yjbanov:semantic-action-inside-frame

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Feb 1, 2025

When a SemanticsAction fires while rendering a frame, delay it by a zero-length timer.

Explanation

A concrete situation where this happens is when a semantics update causes DOM focus shift. DOM focus events are delivered synchronously when induced programmatically. We want to notify the framework about the shift. Since it wasn't the framework that decided where the focus moved, the framework may end up out-of-sync with the engine about which widget is currently focused. However, if the framework is still in the middle of rendering a frame, the notification may induce an illegal setState. We have to wait until the framework is done before delivering the notification.

How

  • Introduce FrameService and consolidate all frame scheduling logic into it (this also makes it way more testable).
  • Update all code that needs to schedule frames to use FrameService.
  • Introduce isRenderingFrame boolean that can be used to tell if a frame is being rendered.
  • Change invokeOnSemanticsAction to use isRenderingFrame to decide if the action can be delivered immediately, or delayed by a zero-length timer.

Fixes #162472

@yjbanov yjbanov requested review from goderbauer and mdebbar February 1, 2025 01:18
@github-actions github-actions bot added engine flutter/engine related. See also e: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) platform-web Web applications specifically labels Feb 1, 2025
///
/// Used for debugging only.
int debugFrameNumber = 1;
// TODO(yjbanov): this file should be deleted as part of https://github.com/flutter/flutter/issues/145954
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch! I think it's better if we moved the file so that it gets deleted with the html code: #162608

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving it sgtm

/// implementation.
///
/// This is intended for tests only.
static void debugOverrideFrameService(FrameService? mock) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static void debugOverrideFrameService(FrameService? mock) {
@visibleForTesting
static void debugOverrideFrameService(FrameService? mock) {

/// DOM event handlers whose notifications to the framework result in state
/// changes may want to delay their notifications, e.g. by scheduling them in
/// a timer.
bool get isUpdatingSemanticsTree => _isUpdatingSemanticsTree;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this is leftover from a previous iteration? It's not being used anywhere.

Copy link
Contributor Author

@yjbanov yjbanov Feb 3, 2025

Choose a reason for hiding this comment

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

Yep! Thanks for catching. Cleaning up.

@github-actions github-actions bot removed the a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) label Feb 3, 2025
@yjbanov yjbanov force-pushed the semantic-action-inside-frame branch from 49bf60b to 06e4f2c Compare February 3, 2025 18:26
@yjbanov yjbanov added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 3, 2025

autosubmit label was removed for flutter/flutter/162554, because - The status or check suite Linux linux_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@yjbanov yjbanov added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 3, 2025

autosubmit label was removed for flutter/flutter/162554, because - The status or check suite Mac tool_integration_tests_1_5 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@yjbanov yjbanov added this pull request to the merge queue Feb 4, 2025
Merged via the queue into flutter:master with commit 3c43a99 Feb 4, 2025
174 of 175 checks passed
@yjbanov yjbanov deleted the semantic-action-inside-frame branch February 4, 2025 03:20
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 6, 2025
Fix the issue with the first frame not rendering, introduced in
#162554.

Nobody filed an issue yet. I found it while testing something else.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web engine must not send SemanticsAction during Frame

2 participants