Skip to content

Make the focus fixup rule more explicit - #8392

Merged
domenic merged 2 commits into
mainfrom
focus-fixup-rule
Jan 27, 2023
Merged

domenic merged 2 commits into
mainfrom
focus-fixup-rule

Conversation

@domenic

@domenic domenic commented Oct 16, 2022 •

Copy link
Copy Markdown
Member
  • Split it into two variants: one which runs synchronously on HTML element removal, and one which runs during "update the rendering". Closes Define timing of focus fixup rule precisely when triggered by style changes. #8225.

  • After this split, only the "update the rendering" variant causes the normal focus algorithms to run, and thus blur and change events to fire.

  • Delete the confusing "somehow unfocused without another element being explicitly focused" sentence.

Fixes #3847. Fixes #6729.

(See WHATWG Working Mode: Changes for more details.)


/infrastructure.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/webappapis.html ( diff )

@domenic domenic added topic: events Event handlers, their content and IDL attributes, and the events HTML fires topic: focus Focus, sequential focus navigation, tabindex, autofocus and inert agenda+ To be discussed at a triage meeting labels Oct 16, 2022
@emilio

emilio commented Oct 16, 2022

Copy link
Copy Markdown
Contributor

Are you sure we don't want blur etc events to fire? In my implementation in Gecko we'd still fire the blur event. Also, Blink at least fires the blur event on node removal (unclear what the timing there is tho, see https://bugzilla.mozilla.org/show_bug.cgi?id=559561).

Cc @EdgarChen

@domenic

domenic commented Oct 17, 2022 •

Copy link
Copy Markdown
Member Author

Yeah, I think you are right, at least for the animation-frame case. I will update the patch for that case at least.

For the node removal case, I am less sure. We have several developers complaining about Chrome's behavior there, and I guess no other browsers do it currently. Also, there is no great timing at which to fire the events; synchronously firing has the same problems as mutation events, and anything else seems pretty weird. So my preference (without yet consulting with other Chrome team members) would be to avoid firing the events for removal.

@devongovett

Copy link
Copy Markdown

I would like to strongly advocate for blur events to be fired on element removal. Without this, it is nearly impossible to build a working focus trap. If the focused element is removed, focus is moved to the body with no event, so no way for JS to handle this and move focus elsewhere (e.g. an adjacent element).

My team recently commented on the Firefox bug (13 years old!) linked above advocating for this. We also opened a WebKit issue asking for the same thing, but it was closed with no explanation. Currently, Chrome is the only browser that implements this as we would expect.

At the moment, we may have to do a very hacky workaround involving a MutationObserver on the whole document. This is unfortunately quite performance intensive, as it is impossible to observe when a particular element is removed - you have to observe the whole tree and get notified of many unrelated changes. Also, this is not even entirely working because these events fire asynchronously, which can cause other downstream issues. Firing a blur event in the browser just before the focused element is removed seems like to only way to truly fix this.

@emilio

emilio commented Oct 17, 2022

Copy link
Copy Markdown
Contributor

@devongovett the problem with firing blur event on removal is timing.

We generally don't want to run sync stuff when DOM is mutated, because it can change stuff like insertion validity checks etc. So whatever we do on removal, if we decide to fire the event, needs to be very precise on when it runs, and probably won't be perfect (since the script running could move the DOM node around etc).

I wonder, why do you need a mutation observer for the whole document? Can't you just capture focus / blur and use a mutation observer for the current activeElement? Seems that should be a bit less terrible, performance-wise?

@devongovett

Copy link
Copy Markdown

The problem then is if an ancestor element of the active element is removed, we wouldn't get an event. That leads to listening on the whole document.

If firing a blur on the active element is not possible, would an alternative be to fire focus on the body? We just need some event to know that focus moved, it doesn't necessarily need to be on the removed element in our case.

@past past removed the agenda+ To be discussed at a triage meeting label Oct 27, 2022
@smfr

smfr commented Nov 2, 2022

Copy link
Copy Markdown

What was the reasoning to run the focus fixup step after rAF callbacks, but before intersection observer and resize observer callbacks?

nt1m added a commit to nt1m/WebKit that referenced this pull request Nov 3, 2022
https://bugs.webkit.org/show_bug.cgi?id=237273
rdar://89902824

Reviewed by NOBODY (OOPS!).

It's currently specced at whatwg/html#8392 as a rendering step after requestAnimationFrame callbacks.

* LayoutTests/imported/w3c/web-platform-tests/inert/dynamic-inert-on-focused-element-expected.txt:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::updateRendering):
(WebCore::operator<<):
* Source/WebCore/page/Page.h:
@emilio

emilio commented Nov 3, 2022

Copy link
Copy Markdown
Contributor

@smfr @domenic I was thinking this should probably run after ResizeObserver, that's when the page is done doing changes to the page for this frame, and it avoids a potentially extra layout update.

@domenic

domenic commented Nov 4, 2022

Copy link
Copy Markdown
Member Author

Thanks! I've switched it to run after ResizeObserver.

Still unsure what to do about blur/focus/change events on sync removal. I guess our choices are:

  1. No events. (Simplest, but hurts developer use cases like @devongovett's)
  2. Sync events. (Like MutationEvents. Ick.)
  3. Queue a task to run them.
  4. Delay them until update-the-rendering timing. (Would probably involve somewhat-complicated tracking infrastructure or a custom queue, especially if we want to consolidate to handle multiple focus changes.)

Maybe (3) is the way to go?

@domenic domenic added the do not merge yet Pull request must not be merged per rationale in comment label Nov 4, 2022
@mfreed7

mfreed7 commented Nov 4, 2022

Copy link
Copy Markdown
Contributor

Thanks! I've switched it to run after ResizeObserver.

Still unsure what to do about blur/focus/change events on sync removal. I guess our choices are:

  1. No events. (Simplest, but hurts developer use cases like @devongovett's)
  2. Sync events. (Like MutationEvents. Ick.)
  3. Queue a task to run them.
  4. Delay them until update-the-rendering timing. (Would probably involve somewhat-complicated tracking infrastructure or a custom queue, especially if we want to consolidate to handle multiple focus changes.)

Maybe (3) is the way to go?

I tend to agree that we should fire events on removal. Otherwise, as @devongovett points out, developers have no great way to tell what happened. It would seem that (3) is the best - still fire the events, but do it when convenient, and not synchronously.

I support this change (to (3)), but I'm a tad worried about compat.

@emilio

emilio commented Nov 5, 2022

Copy link
Copy Markdown
Contributor

The problem with (3) is that if you fire it on the element actually blurred, it won't bubble up because it's already removed... Maybe that's ok as long as we also fire focus somewhere else (to the <body> or so?).

@smaug----

Copy link
Copy Markdown

There is also
(5) run at custom element reaction time
and
(6) run as a microtask

And since the issue is quite similar to DOM mutations, and microtasks were designed for MutationObserver, (6) feels quite reasonable to me.
blur would fire just on the removed element (and propagate through the removed ancestors), but focus should fire then somewhere else.

@domenic

domenic commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

I thought about this more and I think any async version (so, including (3), (4), and (6)) are a no-go. Consider the following code:

console.assert(document.activeElement === element1);
element1.remove(); // (1)
element2.focus();  // (2)

If (1) causes blur on the removed element plus focus on document.body on some delay, then we've messed up, because document.body is not actually focused. In fact, due to the event fired at 2, the developer will actually see this confusing sequence:

  • element2 fires focus
  • (async boundary)
  • element1 fires blur
  • document.body fires focus

Given that some focus/blur events will always be sync, introducing async ones will inevitably introduce a problem like the above. So that argues for (1), (2), or (5).

Between (1) and (5), I am still unsure. Using custom element reaction timing is clever, but this would be the first time we start using it beyond custom elements. It's also pretty weird that developers can opt in to this kind of sync-ish removal event on an arbitrary element, just by making it focused. "One weird trick to make your mutation observers sync!"

I'm currently thinking that we should address @devongovett's use case via a different approach, instead of trying to make focus/blur events on removal work well. For example, he says he wants to detect that focus has changed: I think the bubbling focusin event can do that? Or, we could work on adding some variant of MutationObserver which will let you know if an ancestor is removed. (I think this is whatwg/dom#533; see especially whatwg/dom#533 (comment) by @rniwa.)

@devongovett

devongovett commented Nov 8, 2022 •

Copy link
Copy Markdown

Firing focus/focusin on document.body (perhaps with relatedTarget set to null) would work for my case. This makes sense IMO since document.activeElement does become document.body, it's just not observable at the moment.

There are some related issues for focusin btw. What's implemented in all browsers is not what is currently specified. Not sure if relevant here. w3c/uievents#276 w3c/uievents#88

@domenic

domenic commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

I guess I didn't think through my suggestion of focusin; it has the same timing problems as focus. Observing mutations more generally seems to be a better path.

@devongovett

Copy link
Copy Markdown

If you only fire focus on the body, without a blur, synchronously just after the element has been removed, what is the timing issue? Seems like this wouldn't have the performance impact of mutation events, which must bubble. If it's fired after removal, then additional mutations by the event listener shouldn't affect it. And if it's synchronous, the above example would work as expected.

@domenic

domenic commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

The issue is the same as with any synchronous mutation events: security, etc. See some discussion e.g. in whatwg/dom#533 (comment) or https://lists.w3.org/Archives/Public/public-webapps/2011JulSep/0779.html

@smaug----

Copy link
Copy Markdown

synchronously just after the element has been removed

there is no issue with that. Firing event after the DOM mutation is fine. (It is DOMNodeRemoved which is the most problematic mutation event, it happens before the mutation). Firing event after the mutation is basically custom element reaction time.

@devongovett

Copy link
Copy Markdown

Yeah I figured firing it after mutation just before yielding back to the JS caller would solve that issue.

I think an additional feature to make observing element removal easier in general would also be nice, but would be great to solve this case with focus events specifically if we can. Lots of developers probably won't think to add MutationObserver in addition to focus handlers, so it would be good if there were always a focus event whenever document.activeElement changes.

@mfreed7

mfreed7 commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

If (1) causes blur on the removed element plus focus on document.body on some delay, then we've messed up, because document.body is not actually focused. In fact, due to the event fired at 2, the developer will actually see this confusing sequence:

  • element2 fires focus
  • (async boundary)
  • element1 fires blur
  • document.body fires focus

The problem here really just seems to be the new focus event on the body, right? That was only presented as an alternative, if the blur couldn't be fired on element1. If we drop that from your scenario, the sequence is:

  • element2 fires focus
  • (async boundary)
  • element1 fires blur

...and since element1 has been disconnected from the document anyway, the point is just to make sure there's any event when element1 gets blurred. Based on the presented use case, having an asynchronous blur would still work. The listener can still do focus fixup based on what it finds for document.activeElement. Right?

@domenic

domenic commented Nov 10, 2022

Copy link
Copy Markdown
Member Author

That kind of sequence still makes me quite uncomfortable. If the last event a page sees is blur, then I would expect no element to be focused. Whereas in that example, element2 is focused.

@domenic

domenic commented Jan 18, 2023

Copy link
Copy Markdown
Member Author

In the triage meeting at #8446, we had agreement to move forward with what's currently in this PR.

Separately, we're interested in pursuing whatwg/dom#533 to make node removal observable, for the use cases mentioned here.

As such, I think this PR is ready for review. @emilio, @nt1m, do you know the latest status on web platform tests? Especially for the cases around event timing.

@domenic
domenic requested a review from annevk January 18, 2023 07:12
@domenic domenic removed the do not merge yet Pull request must not be merged per rationale in comment label Jan 18, 2023
@emilio

emilio commented Jan 18, 2023

Copy link
Copy Markdown
Contributor

@devongovett

Copy link
Copy Markdown

Glad that node removal observation will be worked on but I still think it's pretty weird that there is a case where document.activeElement changes but there are no focus or blur events fired. That seems pretty counterintuitive.

@domenic

domenic commented Jan 19, 2023

Copy link
Copy Markdown
Member Author

I have tests already reviewed in https://phabricator.services.mozilla.com/D156219

However, they say "Don't check precise timing while we wait for more concrete spec edits." Gentle ping to update them with more precise timing checks :)

@emilio

emilio commented Jan 19, 2023

Copy link
Copy Markdown
Contributor

However, they say "Don't check precise timing while we wait for more concrete spec edits." Gentle ping to update them with more precise timing checks :)

Done, that also caught a bug in Gecko of course ;)

@annevk annevk 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.

This generally looks good to me editorially. Left some minor inline nits.

Comment thread source Outdated

<p class="note">In some cases, e.g. if <var>entry</var> is an <code>area</code>
element's shape, a scrollable region, or a <span>viewport</span>, no event is fired.</p>
<p class="note" id="note-sometimes-no-blur-event">In some cases, e.g. if <var>entry</var> is

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.

Suggested change
<p class="note" id="note-sometimes-no-blur-event">In some cases, e.g. if <var>entry</var> is
<p class="note" id="note-sometimes-no-blur-event">In some cases, e.g., if <var>entry</var> is

Comment thread source
<p>For each <span>fully active</span> <code>Document</code> in <var>docs</var>, if the <span
data-x="focused area of the document">focused area</span> of that <code>Document</code> is no
longer a <span>focusable area</span>, then run the <span>focusing steps</span> for that
<code>Document</code>'s <span>viewport</span>.</p>

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.

Is "is no longer" important or can it be "is not a"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it can be a bit confusing for the reader to see "focused area ... is not a focusable area", so "no longer" makes it a bit clearer what's going on.

But, it can also be confusing for the reader to think "no longer" might involve some sort of extra state-tracking, compared to "is not".

On balance, the latter seems worse, so I'll change it as you suggest.

@domenic
domenic merged commit e233336 into main Jan 27, 2023
@domenic
domenic deleted the focus-fixup-rule branch January 27, 2023 01:18
domenic added a commit to web-platform-tests/wpt that referenced this pull request Sep 21, 2026
HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in 5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in #38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, #62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases while leaving precise scheduling assertions to the dedicated focus-fixup tests.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <[email protected]>
domenic added a commit to web-platform-tests/wpt that referenced this pull request Sep 21, 2026
HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in 5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in #38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, #62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <[email protected]>
domenic added a commit to web-platform-tests/wpt that referenced this pull request Sep 24, 2026
HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in 5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in #38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, #62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <[email protected]>
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Sep 29, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <[email protected]>

--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Oct 1, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <[email protected]>

--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 5, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <codexopenai.com>

--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827

UltraBlame original commit: d0174234741490e96f935047be72d1cd22ef3b71
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 5, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <codexopenai.com>

--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827

UltraBlame original commit: d0174234741490e96f935047be72d1cd22ef3b71
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 5, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.

Co-authored-by: codex <codexopenai.com>

--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827

UltraBlame original commit: d0174234741490e96f935047be72d1cd22ef3b71
zerox80 pushed a commit to zerox80/firefox that referenced this pull request Oct 16, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.


--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827
zerox80 pushed a commit to zerox80/firefox that referenced this pull request Oct 16, 2026
…ng tests, a=testonly

Automatic update from web-platform-tests
Wait for focus fixup in fieldset disabling tests

HTML clarified focus fixup in whatwg/html#8392, merged on January 27, 2023. It split the old rule into synchronous fixup when the focused node is removed, without blur events, and asynchronous fixup during "update the rendering" when the focused area becomes non-focusable. Disabling a fieldset falls into the latter case: the rendering update runs the focusing steps for the document's viewport.

disabled-003.html was added on April 7, 2023 in web-platform-tests/wpt@5857a9b as a regression test for Chromium's exponential-time fieldset traversal and a crash caused by reentrant blur handling. Although it postdates the HTML change, its assertions require Chromium's synchronous focus change after disabling a fieldset. They therefore fail implementations that defer the change until a rendering update.

The dedicated focus-fixup timing tests were updated in web-platform-tests/wpt#38062, merged on June 4, 2025, to check that focus remains unchanged synchronously and is fixed up after rendering. More recently, web-platform-tests/wpt#62292, merged on August 31, 2026, changed the moveBefore() focus-fixup tests to use waitForAtLeastOneFrame() before checking document.activeElement.

Use the same rendering wait here by converting both nested-fieldset cases to promise tests. Assert that each input initially receives focus before disabling the fieldset, then check that focus has moved away after rendering. This preserves the original shallow and deeply nested crash/hang cases.

Do not add exact-timing assertions here that would fail Chromium for changing focus synchronously. Timing after disabling a fieldset is already covered by the #button4 subtest in https://github.com/web-platform-tests/wpt/blob/532766fee262a2b41054665505b9dc37bd7c0a25/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.html. That case focuses a button and disables its parent fieldset; the shared helper checks that focus remains unchanged synchronously, during the first animation-frame callback, and during ResizeObserver delivery, then checks that focus is fixed up after rendering.

Both subtests change from failing to passing in Firefox 151 and WebKit 26.5, and continue to pass in Chromium 149.


--

wpt-commits: 8e9f3e2199fca135a62526a75410ecf10d3f9e3d
wpt-pr: 62827
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: events Event handlers, their content and IDL attributes, and the events HTML fires topic: focus Focus, sequential focus navigation, tabindex, autofocus and inert

8 participants