Skip to content

Wait for the reloaded document's focus before the Firefox reload-typing test presses its key - #7151

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-7143
Nov 25, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-7143

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

The Firefox copy of test_a_key_typed_through_the_reload_acts_where_the_user_is_put_back pressed r before the reloaded document could receive it. The test pressed once the replacement document left loading. Firefox gives that document focus a little later, and a key pressed in that gap never reaches the page. The test now waits until the document can take the key: in Firefox, for the window's focus event, and in Chromium, for document.hasFocus(). What the test protects is unchanged: a key typed through the reload still lands before the runtime has reopened the thread view, and must resolve the thread the user is put back in.

This is not a dropped keypress in Leaf. With an init script logging every window input event, each failing copy showed no keydown in the new document. The press started at 7965 ms, the window's focus event came at 8052 ms, and the window saw only the stray keyup at 8118 ms. In another failure nothing of the key arrived at all. No Leaf code saw the key, so the early key hold (bootstrap.js, holdEarlyKeys) had nothing to hold.

Waiting for document.hasFocus() alone is not enough in Firefox. It still lost 1 of 48 copies, because hasFocus() already read true while the focus event was still pending. Chromium fires no window focus event on reload, and its document took the key from the start, so Chromium keeps the hasFocus() check.

Evidence from leaf-dev suite flake --workers 4 --load 3 on the Firefox node:

failed
before (two runs of 24) 2 of 24, 2 of 24
waiting for hasFocus() only 1 of 48
this change 0 of 54

The Chromium node passed 12 of 12 under the same load.

Closes #7143 — automated triage

… in Firefox

The test pressed `r` once the replacement document left `loading`, but
Firefox gives that document focus a little later, and a key pressed in
between reaches no document of the page: in failing copies the new window
logged no keydown (and sometimes only the keyup) before its `focus` event.
`document.hasFocus()` alone narrowed the gap but still lost 1 of 48 copies,
since it reads true before Firefox fires the window's `focus` event. The
test now waits for that event in Firefox, and for `hasFocus()` in Chromium,
which fires none on reload and takes the key from the start. The behavior
the test protects, a key typed through the reload acting in the restored
thread view, is unchanged.

`leaf-dev suite flake --copies 24 --workers 4 --load 3`, Firefox: 2 of 24
failed twice before the change; 54 of 54 passed after it. Chromium: 12 of 12.

Closes #7143
@leaf-agent
leaf-agent merged commit c99c2df into main Nov 25, 2026
7 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-7143 branch November 25, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_a_key_typed_through_the_reload_acts_where_the_user_is_put_back: Firefox key typed through a reload resolves nothing under load

1 participant