Skip to content

Browser tests wait for the page to be still, not a fixed time - #2309

Merged
davidmckayv merged 12 commits into
mainfrom
fix/layout-tests-wait-for-settle
Nov 27, 2026
Merged

davidmckayv merged 12 commits into
mainfrom
fix/layout-tests-wait-for-settle

Conversation

@davidmckayv

@davidmckayv davidmckayv commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What was flaky

The browser layout tests under app/tests draw a screen, add the app's stylesheet after it has drawn, and then measure or photograph it. They failed now and then in CI, most often in WebKit: a dialog measured off the screen, a colour read mid-fade, a row measured before it had laid out again.

The cause

Styles that arrive after the page has drawn start the transitions they declare: a dialog slides from where it sat unstyled to the middle of the window, a button fades from the browser's own colour to its own, rows ease in. About forty files then waited a fixed time (page.waitForTimeout(400), or 150 to 1000ms) and measured. Under a full CI run, eight files at once in Chromium and WebKit, that guess was sometimes short. #2302 fixed one file; the others each had their own copy of the same guess.

The fix

One shared helper, still(page) in app/tests/page-still.ts, replaces every one of those settle waits (40 files, plus the one from #2302). It waits for fonts, then until, for three frames in a row:

  • no animation or transition that ends is running, and
  • no element's laid-out box (offsets and size, before transforms) has changed.

Endless animations (spinners, shimmers) and scroll-driven ones (the transcript's scroll fade) are left out, because they never end on their own; waiting on a scroll-driven animation's finished never returns. Boxes are read before transforms, so the sidebar orb, which scales itself every frame, does not keep a page from being still. A page that never goes still fails after 10 seconds and names what kept moving.

What each test asserts is unchanged. Two files' teardown also gets 30 seconds to close its browsers: under eight files at once, closing two browsers sometimes took longer than a hook's default five.

The lock

app/tests/no-fixed-settle-waits.test.ts fails when any file under app/tests calls waitForTimeout, unless the file is listed with the most fixed waits it may hold and a one-line reason. The listed ones prove something does not happen within a time (no second tab opens, a read is not asked again), let a timer under test run, or poll something the page cannot be asked about.

  • Red on main: fails, listing the 40 files that wait a fixed time to settle.
  • Green on this branch: passes.

CI proof

A temporary job, removed before merge, ran the 40 changed files plus the 9 that use the shared notices helper (49 files) together with bun test --parallel=8, in Chromium and WebKit, in the Playwright v1.62.1 image on the 16-core runner.

  • Final helper: 6 rounds side by side, each 1430 passed. In every round the only failures were 4 tests in sidebar-current-row and sidebar-window-buttons, two files no CI job runs. A baseline job ran those two files from main and they fail the same 4 tests there, so they were already broken before this change.
  • The previous helper version (same box check, before the teardown timeout) ran another 6 rounds: 1430 passed each, the same 4 already-broken tests, and a browser-closing teardown timeout in 2 rounds, which is now fixed.
  • A first version that watched every change to the page never went still on the sidebar's breathing orb; that is why it now reads boxes instead.

The normal CI jobs (Chromium list, WebKit list) pass on this head.

The browser layout tests draw a screen, add the app's stylesheet after it has
drawn, and measure or photograph it. The late styles start the transitions they
declare (a dialog sliding into place, a fade, rows easing in), and about forty
files then waited a fixed 150 to 1000ms before measuring. Under a full CI run,
eight files at once in Chromium and WebKit, that guess was sometimes short and
the test read a screen mid-move.

They now call one shared helper, still(page) in app/tests/page-still.ts, which
waits until, for three frames in a row, no animation that ends is running and
nothing in the document changed. Endless and scroll-driven animations do not
count, since they never end on their own (waiting on a scroll-driven one's
finished never returns). A page that never stops fails with what kept moving.

no-fixed-settle-waits.test.ts keeps it that way: a file under app/tests that
calls waitForTimeout fails unless it is listed with the most waits it may hold
and why (a wait that proves something does not happen, a timer under test, a
poll).
The sidebar's orb breathes by writing its own scale every frame, so a page
with it never stopped changing and the narrow sheet test could not go still.
Read every element's laid-out box instead (offsets, before transforms): a
transform that never ends no longer counts, and anything that lays out again
still does. The failure now names the element that moved and where.
@davidmckayv
davidmckayv merged commit 8b185ee into main Nov 27, 2026
35 checks passed
@davidmckayv
davidmckayv deleted the fix/layout-tests-wait-for-settle branch November 27, 2026 10:05
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.

1 participant