Skip to content

fix(core): a timing observer firing after its page is gone no longer throws and fails the run - #8834

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/record-filter-without-global-node
Nov 25, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/record-filter-without-global-node

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

createRecordFilter (packages/core/src/runtime/mutationRecords.ts) checks a node's type against the number 1 instead of the global Node.ELEMENT_NODE. A timing or colour-grading observer whose callback runs after its page is gone no longer throws.

Why

The core runtime suite (test:runtime-coverage) prints ReferenceError: Node is not defined 9 times on every run. All 9 come from MutationObserver callbacks (init.ts takeTimingRecords, colorGrading.ts) that jsdom delivers after their test file's environment has torn down the global Node. On Linux the run still exits 0. On slower Windows runners one of those prints sometimes lands while vitest's worker is closing. Vitest then reports EnvironmentTeardownError: Closing rpc while "onUserConsoleLog" was pending as an unhandled error, and a run whose tests all pass (3763/3763) exits 1.

That is what dequeued a merge group this morning on "Windows render verification" (engine-cli-2, test:runtime-coverage). The PR in that group touched none of this code.

Related work

None.

How

touches read Node.ELEMENT_NODE, a lookup on the global that a page past its teardown no longer has. ELEMENT_NODE = 1 is the DOM's fixed value, so the check means the same thing in a browser and keeps working when the global is gone. Both late observers go through this one function. No other runtime code that reads Node.* is reached from an observer callback: after this change the suite prints no Node is not defined.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

packages/core/src/runtime/mutationRecords.test.ts "judges an inserted element without the global Node, as a callback after its page is gone does": it records an inserted <video>, removes the global Node with vi.stubGlobal, and expects the record to count as a timing change. 7/7 pass, 3 runs in a row.

fails without the fix: packages/core/src/runtime/mutationRecords.test.ts "judges an inserted element without the global Node, as a callback after its page is gone does" fails on main with TypeError: Cannot read properties of undefined (reading 'ELEMENT_NODE').

Whole runtime suite on the devbox (vitest run --coverage src/runtime, the command test:runtime-coverage runs): on main, 3763 passed, exit 0, with 9 Node is not defined prints. With the fix, 3764 passed, exit 0, with 0 prints. Core tsc --noEmit, oxlint, oxfmt --check and the comment-share ratchet are clean.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 57 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at a51d501.

  • touches in createRecordFilter now compares nodeType to a local ELEMENT_NODE = 1 instead of reading the global Node. The DOM fixes that value at 1, so behaviour is unchanged, and a callback delivered after jsdom teardown no longer throws. Both late observers (timing and colour grading) go through this one filter, and no other Node.* read remains in mutationRecords.ts.
  • The new test stubs the global Node to undefined and fails on main with "reading 'ELEMENT_NODE'"; the PR body has the "fails without the fix:" line naming it.
  • 3751cd8..a51d501 changes only the test comment, shortened to fit the line limit.
  • Required checks are green at a51d501, including the Windows test jobs.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit eff291d Nov 25, 2026
103 checks passed
@miguel-heygen
miguel-heygen deleted the fix/record-filter-without-global-node branch November 25, 2026 10:48
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.

2 participants