You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Define timing of focus fixup rule precisely when triggered by style changes. #8225
I was looking into implementing the focus fixup rule in Gecko, and per spec it's not clear when it should happen when it happens as a response to style changes.
Naively, reading the current spec, I'd expect the element to be blurred after the style update (basically, as a result of getBoundingClientRect()). It seems Blink at least does it at a well defined point in the "update the rendering" steps (which is reasonable too).
I thought WebKit implemented this but at least the Safari version I have access to behaves like Firefox.
I think I'd be fine making this a proper step in the "update the rendering", it seems odd that getBoundingClientRect() would fire a blur event.
@mfreed7 / @josepharhar, it seems blink sometimes applies the focus fixup rule sync (when making the form control disabled for example), but in the case of style changes it does it async. I think I'd rather have a single point in update-the-rendering where this happens but I'm curious if there's any reason to do it sync sometimes. Also I wonder when are you doing it r/n?
@nt1m / @rniwa, do you know the status of this in WebKit? I recall seeing some patches in flight to implement this long ago, but it doesn't seem to work, was it reverted or something?
(As for the current state, we don't implement the focus fixup rule for most part, aside for finding the right element to focus when showing/hiding a dialog)
It feels odd to do this in "update the rendering", but that is likely the most performant place to do it. I'm afraid of the patch above - it'll likely slow things down considerably, since we'll be forcing style updates more often.
Yeah I tried to make it synchronous, but since style changes can affect focusability, then things like document.activeElement, document.querySelector(":focus"), etc. need to flush styles, which seems bad for perf. And several tests failed, so probably not web compatible, but I don't remember the details.
Then I agree that doing it in "update the rendering" seems more reasonable.
I'm in favor of keeping that behavior (synchronously fire events for focused element removal), given that it's interoperable, and changing it scares me.
Activity
emilio commentedon Aug 27, 2022
@nt1m / @rniwa, do you know the status of this in WebKit? I recall seeing some patches in flight to implement this long ago, but it doesn't seem to work, was it reverted or something?
nt1m commentedon Aug 27, 2022
I think I tried to implement this in the update rendering steps: https://bugs.webkit.org/show_bug.cgi?id=237273#c1 , it's the easiest way (since you don't have to find every single place where "is this element focusable?" changes and hook it up there).
It works, although the spec implies we should do synchronously and not async, so I just left it there for now.
nt1m commentedon Aug 27, 2022
(As for the current state, we don't implement the focus fixup rule for most part, aside for finding the right element to focus when showing/hiding a dialog)
mfreed7 commentedon Aug 29, 2022
See this Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1275097. It's currently done in a semi-hacky way, e.g. with timers.
@Loirooriol tried to fix this up at one point and make it synchronous, so perhaps he has more comments.
It feels odd to do this in "update the rendering", but that is likely the most performant place to do it. I'm afraid of the patch above - it'll likely slow things down considerably, since we'll be forcing style updates more often.
Loirooriol commentedon Aug 29, 2022
Yeah I tried to make it synchronous, but since style changes can affect focusability, then things like
document.activeElement,document.querySelector(":focus"), etc. need to flush styles, which seems bad for perf. And several tests failed, so probably not web compatible, but I don't remember the details.Then I agree that doing it in "update the rendering" seems more reasonable.
emilio commentedon Sep 1, 2022
So, there seemed to be consensus today on doing this at some point during update the rendering. I sent a patch updating the tests here: https://bugzilla.mozilla.org/show_bug.cgi?id=1788741
However, that uncovers a case where all browsers are interoperable in removing focus synchronously, which is focused element removal.
Not sure to what extent we want that to be special, do we want to keep that behavior? It might be reasonable.
mfreed7 commentedon Sep 2, 2022
Interestingly, we just discussed this case w.r.t. the pop-up API.
I'm in favor of keeping that behavior (synchronously fire events for focused element removal), given that it's interoperable, and changing it scares me.
Loirooriol commentedon Sep 2, 2022
Worth noting that Blink also blurs synchronously when losing the tabindex:
But no interoperability here so changing may be fine.
Make the focus fixup rule more explicit
Make the focus fixup rule more explicit
Make the focus fixup rule more explicit
Make the focus fixup rule more explicit