Skip to content

test(octane): hold the frame clock in the pre-render passive ViewTransition test - #1902

Merged
trueadm merged 3 commits into
mainfrom
test/deflake-vt-transition-task
Oct 8, 2026
Merged

trueadm merged 3 commits into
mainfrom
test/deflake-vt-transition-task

Conversation

@trueadm

@trueadm trueadm commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This makes "commits without animation when a pre-render passive adds urgent sibling work" (view-transition-scoped-effects.test.ts) deterministic. It failed in octane-prod on #1893 with expected 'initial' to be 'left changed'.

It also moves the host-task nextTask() wait into tests/_helpers.ts, so the ViewTransition suites share one copy.

Why

The test needs a passive effect from a flushSync commit to still be pending when the transition renders. Since #1873, that render runs in its own host task, which drains pending passives before it chooses capture owners.

In jsdom, the passive drains at the next animation frame instead. The frame posts to the runtime's long-lived post-paint MessagePort. Node delivers pending port messages in port-creation order, so once jsdom's frame timer comes due before the transition task runs, the passive goes first.

On a loaded CI worker, that is what happened:

  1. The urgent sibling work commits on its own.
  2. The transition then animates.
  3. The capture mock never runs update(), so left stays 'initial'.
  4. vi.waitFor times out after 1 s.

Neither order is a runtime defect. The test simply targets the "transition task before the next frame" case. So the test now controls the frame clock, and the runtime is unchanged.

The other two flakes from #1893 are in view-transition-matching.test.ts. #1875 already fixed them on main by waiting for the mock's startViewTransition call. The forced reorder below confirms that fix holds.

Changes

  • view-transition-scoped-effects.test.ts: the test fakes setTimeout, clearTimeout, requestAnimationFrame and cancelAnimationFrame, so neither a frame nor the 250 ms fallback timer can drain the passive early.
    • It waits with nextTask(), a host task posted after the runtime's, instead of polling. vi.waitFor would advance the fake timers.
    • afterEach restores real timers.
  • tests/_helpers.ts: adds nextTask(). It takes over the identical local copies in view-transition.test.ts and view-transition-matching.test.ts, and captures MessageChannel at load so a test that stubs it cannot break the helper.

Validation

To reproduce the CI ordering locally without loading the machine, I applied a temporary patch to postHostTask (not committed). After posting, it spins 20 ms of wall clock in a microtask, so timers come due before the event loop reaches the transition task.

  • Forced reorder on main, three VT files:
  • Forced reorder with this PR: view-transition-{matching,scoped-effects}.test.ts and view-transition.test.ts pass 61/61 in both octane and octane-prod.
  • Without the patch: the same three files pass 61/61 in both projects.
  • Mutation check: with routeFlush's pre-capture passive drain disabled, the fixed test fails, so the assertion still guards the behavior.
  • pnpm format:files:check on the changed files
  • pnpm sync: no changes
  • pnpm typecheck:files on the changed tests and their fixtures: no errors in changed lines. The only test-file error is the untouched ../src/compiler/compile.js import in view-transition.test.ts; the rest are in the untouched .tsrx fixtures.
  • pnpm format:check, pnpm typecheck and pnpm test were not run locally, under the parallel-session load rule. CI covers them.
  • perf-review: not applicable (test-only change)

Risk / follow-ups

  • "captures a scope whose update a pre-render passive effect schedules" in the same file has the same premise. Its assertions hold under either order, so it does not flake. Under load, though, it may not exercise the pre-render drain it describes. It uses vi.waitFor, so holding its frames would need the same rewrite.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Test-only refactors and timer fakes; no runtime, auth, or production behavior changes.

Overview
Test-only changes that stabilize ViewTransition timing in Octane’s Vitest suite and deduplicate host-task waiting.

A shared nextTask() helper is added to tests/_helpers.ts (MessageChannel-based wait for work scheduled after the runtime’s transition host task). The duplicate local implementations are removed from view-transition.test.ts and view-transition-matching.test.ts, which now import the shared helper. MessageChannel is captured at module load so stubs cannot break the helper.

In view-transition-scoped-effects.test.ts, the case “commits without animation when a pre-render passive adds urgent sibling work” is made deterministic: it fakes setTimeout / requestAnimationFrame so a jsdom animation frame cannot drain the passive before the transition task, asserts the intermediate DOM state, then advances with nextTask() instead of vi.waitFor (which would advance fake timers). afterEach restores real timers.

No production/runtime code changes.

Reviewed by Cursor Bugbot for commit ef0e35f. Bugbot is set up for automated code reviews on this repo. Configure here.

…sition test

"commits without animation when a pre-render passive adds urgent sibling
work" relies on a passive effect from a sync commit still being pending when
the transition's host task (#1873) starts rendering. In the test, that passive
is drained at the next animation frame, which then posts to the runtime's
long-lived post-paint port. When jsdom's frame timer comes due before the
transition task runs, as it can on a loaded CI worker, the passive drains
first and the transition animates. The test's capture mock never runs the
update, so the left scope stays 'initial', and `vi.waitFor` timed out in
octane-prod on #1893.

The test now fakes setTimeout and requestAnimationFrame, so no frame and no
fallback timer can drain the passive early. It waits for the transition with
a host task posted after the runtime's, not by polling, because `vi.waitFor`
would advance the fake timers.

The host-task `nextTask()` helper moves to tests/_helpers.ts. It replaces the
local copies in view-transition.test.ts and view-transition-matching.test.ts.
#1875 already made the matching tests wait for the native transition start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only labels Oct 8, 2026
@trueadm
trueadm marked this pull request as ready for review October 8, 2026 14:41
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares e14fbdf9a, the merge commit's first parent with 900db8e7d on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.900 2.900 −3.1% −4.7% … ±0.0% ⚪ within noise
octane-tsrx replace 6.375 6.483 +0.8% −1.7% … +6.4% ⚪ within noise
octane-tsrx add 2.625 2.633 −1.8% −3.8% … +1.8% ⚪ within noise
octane-tsrx update 0.124 0.123 −0.7% −1.3% … +0.3% ⚪ within noise
octane-tsrx select 0.006 0.006 +1.1% +0.5% … +1.7% ⚪ within noise
octane-tsrx swap 0.032 0.032 ±0.0% −0.7% … +0.7% ⚪ within noise
octane-tsrx remove 0.015 0.015 +0.4% −2.4% … +2.9% ⚪ within noise
octane-tsrx runlots 26.733 27.575 +1.0% −2.2% … +2.5% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 +2.7% +1.3% … +4.1% ⚪ within noise
octane-tsrx clear 53.392 54.250 +2.0% −0.7% … +3.2% ⚪ within noise
octane-jsx run 4.958 4.742 −1.8% −4.5% … +4.7% ⚪ within noise
octane-jsx replace 8.158 8.458 −3.0% −9.5% … +8.3% ⚪ within noise
octane-jsx add 3.758 3.742 +2.8% ±0.0% … +5.7% ⚪ within noise
octane-jsx update 0.293 0.278 −2.2% −5.2% … −0.4% ⚪ within noise
octane-jsx select 0.144 0.147 +1.6% +0.8% … +2.7% ⚪ within noise
octane-jsx swap 0.249 0.250 +0.0% −2.5% … +3.2% ⚪ within noise
octane-jsx remove 0.192 0.192 −0.8% −2.4% … +0.8% ⚪ within noise
octane-jsx runlots 32.283 33.683 −1.2% −2.9% … +2.0% ⚪ within noise
octane-jsx select_lots 1.821 1.760 −2.5% −3.5% … +0.4% ⚪ within noise
octane-jsx clear 74.175 67.125 −6.3% −14.1% … +0.8% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 60 measured values.

Public-import reachability bundles (bytes)

No changes across 111 measured values.

@trueadm
trueadm merged commit e989ade into main Oct 8, 2026
45 of 55 checks passed
@trueadm
trueadm deleted the test/deflake-vt-transition-task branch October 8, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant