Uh oh!
There was an error while loading. Please reload this page.
[test] Stop leaking mocked performance clocks into later test files - #37379
Merged
Conversation
Test files running in the Node.js Jest environment share the worker
process's `performance` object, because `jest-environment-node` installs
it by reference rather than by copy. When a test mocked the clock with
`Object.defineProperty(performance, 'now', ...)`, the mutation hit the
shared object and was never undone, since Jest only restores
`jest.spyOn` mocks when a file's runtime is torn down. Every subsequent
test file in the same worker then observed the fake clock, including
jsdom-based files, whose `performance.now()` subtracts a window-creation
timestamp from the shared object's `now()`.
This change switches the six affected test files to
`jest.spyOn(performance, 'now')` and
`jest.spyOn(performance, 'timeOrigin', 'get')`, which Jest restores
automatically at teardown. `ReactFlightDOMEdge-test.js` runs in jsdom
and therefore did not leak, but it used the same pattern and is
converted for consistency. The leak is a suspect for the flaky
`{"time":NaN}` Flight serialization failure seen in CI, since a leaked
clock whose `now()` returns a non-number propagates NaN into the
timing rows the Flight server serializes.
Co-Authored-By: Claude Code (kimi-k3[1m]) <noreply@anthropic.com>Comparing: 373d35e...c71633e Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) Generated by sizebot against c71633e |
eps1lon
marked this pull request as ready for review
August 26, 2026 06:50
unstubbable
approved these changes
Aug 26, 2026
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test files running in the Node.js Jest environment share the worker process's
performanceobject, becausejest-environment-nodeinstalls it by reference rather than by copy. When a test mocked the clock withObject.defineProperty(performance, 'now', ...), the mutation hit the shared object and was never undone, since Jest only restoresjest.spyOnmocks when a file's runtime is torn down (jest-runtime'steardown()callsrestoreAllMocks()). Every subsequent test file in the same worker then observed the fake clock, including jsdom-based files, whoseperformance.now()subtracts a window-creation timestamp from the shared object'snow().This change switches the six affected test files to
jest.spyOn(performance, 'now')andjest.spyOn(performance, 'timeOrigin', 'get'), which Jest restores automatically at teardown.ReactFlightDOMEdge-test.jsruns in jsdom and therefore did not leak, but it used the same pattern and is converted for consistency.This change is mostly for test hygiene. Was discovered while investigating a flaky
{"time":NaN}serialisation bug (e.g. https://github.com/react/react/actions/runs/32878999825/job/97903912119)