Skip to content

Firefox wasm: the heading and the field both match :focus in the read-only field row #197

In review

Description

@pournasserian

What happens. Forms.FieldTests.ReadOnlyIsATabStopAndDisabledIsSkipped (wasm, Firefox) failed once, in nightly run 46546226030, at FieldTests.cs:138. The failing step is AssertFocusNameAsync("Workspace ID"), after the Tab from Address. The error was a strict-mode violation: :focus:not(html, body) matched two elements, <h1 tabindex="-1">Field</h1> and the Workspace ID input.

Why it is not the race of #182. The test waits for the heading to have focus (FormsPage.FocusSettledAsync) before it places focus. A probe recorded every focus() call and every focus event in Firefox wasm on /wasm/field. The router focused the heading once, through focusBySelector, in 5 of 5 runs, and there was no second call. :focus was empty after the heading lost focus.

Not reproduced. It did not fail in 2 full Firefox wasm runs in a 4-CPU Linux container, or in 20 single-row runs at 8 and 1.5 CPUs.

Open question. Two elements matching :focus at once can't be explained from the page. It may be Firefox keeping a stale focus state while several pages of one browser run in parallel. Firefox already shares one pointer capture across pages (#181). If the row fails again, the next step is to record document.activeElement alongside the :focus matches at the failure.

Split from #193, whose other rows #196 fixes.

Activity

  1. pournasserian commented on Dec 1, 2026

    @pournasserian
    MemberAuthor

    Two more rows with the same shape in Firefox wasm, in the nightly of #196's branch (46706315541, job "Firefox, wasm, components"):

    Test Step :focus matched
    Layout.AppShellDrawerTests.WideningWhileTheDrawerIsOpenLeavesOneTabSequenceAndARegionThatScrollsAndTakesFocus AssertFocusNameAsync("Card"), AppShellDrawerTests.cs:202 the Card link, and <h1 tabindex="-1">App shell</h1>
    Overlays.SplitButtonTests.WithTheKeyboardAloneTheActionRunsAndTheSeparatelyNamedToggleOpensTheMenu AssertFocusNameAsync("Save"), SplitButtonTests.cs:34 <h1 tabindex="-1">Split button</h1>, and #split-save__action

    The pattern is the same as the field row. The router had already put focus on the heading before the test began. Focus then moved by FocusAsync or Tab. Afterwards :focus matched both the heading and the element reached.

    Not reproduced.

    • 3 runs of that job in the arm64 container at 2 CPUs, and 2 full wasm runs at 4 CPUs.
    • 4 nightlies of a diagnostic branch (Firefox 16 of 16 jobs green). That branch logged every focus() call, focus and blur event on the page and on the window, document.activeElement and the :focus matches.

    Lead, not shown. Playwright's Firefox (Juggler):

    • sets docShell.overrideHasFocus = true for every page;
    • opens each new page in a window of its own and calls browser.focus() on it (TargetRegistry.js).

    In a parallel run, every page's window is lowered and raised again and again while other tests open pages. A stale focus state on the window's earlier focused element would give exactly this: the heading, which is the first element the router focuses on every page. It would also explain why only Firefox shows it, and only in full parallel runs.

    Next step if it recurs: run the diagnostic branch's logging (commit 193-focus-diag on origin) in the nightly until it catches one. The point to settle is whether document.activeElement is the expected element at the failure. If it is, KeyboardDriver.Focused could read the active element instead of :focus.

  2. pournasserian commented on Dec 1, 2026

    @pournasserian
    MemberAuthor

    Reproduced, with the focus log. It reproduced twice in the "wasm, components" part at 2 CPUs (arm64 container), with logging of every focus() call, every focus, blur, focusin, focusout and keydown event on the page and the window, document.activeElement and the :focus matches:

    • BreadcrumbTests.EnterOnTheButtonShowsTheLevelsInPlaceAndFocusesTheFirstOne (wasm)
    • TabsTests.RovingFocusFollowsTheReadingDirectionAndPassesOverTheDisabledTab (wasm)

    Breadcrumb, abridged (ms since document start):

    4217 focus() h1   (focusBySelector, blazor.web.js: the router)
    4221 focus h1         active=h1    :focus=h1
    4433 focus() span  (KeyboardDriver.StartAtTopAsync)
    4434 focus span       active=span  :focus=span,h1
    4436 keydown Tab      active=body  :focus=h1
    4439 focus a          active=a     :focus=a,h1
    … and so on: every later stop shows :focus=<stop>,h1
    

    Tabs: the router focuses the h1 at 2215. A Tab at 3122 moves focus to the first tab: active=a#tabs-project__tab-…, :focus=h1,a#tabs-project__tab-….

    Cause. When focus leaves the heading, Firefox (Playwright's build) fires no blur or focusout on it, and keeps matching it as :focus and :focus-visible. document.activeElement is right at every step. No window blur or focus happened in between, so the window-raise lead above is ruled out. Only the wasm mode shows it, and the heading had been focused by the router's focusBySelector (focus({ preventScroll: true })). This is the browser's state, not the page's.

    Fix (harness). KeyboardDriver reads focus through :light(:focus:not(html, body)) in AssertFocusNameAsync and in the descriptions. AssertFocusAsync and TabToAsync already read document.activeElement. A locator for the active element would make every focus read the same and would not trust the stale :focus. Playwright allows that through a selector engine registered once by the fixture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions