Repository navigation
fix(core): guard runtime init and paused video observer when document.body is null - #8936
Conversation
jerry-heygen
left a comment
There was a problem hiding this comment.
Approved at 7e5a2ccc. The runtime keeps its usual body/head targets when present and falls back to the document element when either is missing. That avoids the null observer target without losing updates from a body added later. The new tests cover startup and teardown without a body, and paused video display and cleanup without a body or head.
All seven changed files match the exact test merge. General CI was still running at inspection; the focused test runs are author-reported. I did not run an independent browser session.
— Jerrai (pr-review)
Edit accuracy: accurate 273 (base branch 271), smooth 91 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) Unstable (1)
|
Summary
When the injected runtime starts on a document whose
document.bodyisnull(for example a composition whose markup or script removed or has not yet attached<body>),initSandboxRuntimeModular()threwTypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'insidecreatePausedVideoFrames()and would then dereferencedocument.bodyagain ininitVfx()andcollectRuntimeTimelinePayload().Every sibling observer in
packages/core/src/runtime/already observesdocument.documentElementor guardsdocument.body.Changes
packages/core/src/runtime/pausedVideoFrames.ts: fall back fromdocument.bodytodocument.documentElement(and guard when neither exists) before callingobserver.observe(...), and fall back fromdocument.headtodocument.documentElementwhen appending the hiding<style>element.packages/core/src/runtime/vfx.ts: acceptHTMLElement | nullininitVfxandrebuildLostVfx, returning cleanly whenrootisnull.packages/core/src/runtime/init.ts: passdocument.body ?? document.documentElementtoinitVfxandrebuildLostVfx, guarddocument.body.styledimension mirroring, and guarddocument.bodywhen counting mounted elements.packages/core/src/runtime/timeline.ts: fall back fromroot ?? document.bodytodocument.documentElement(and guard whennull) before callingparseElementDurationAttr.packages/core/src/runtime/afterFonts.ts: fall back fromdocument.bodytodocument.documentElementbefore appending the deferred-module sentinel script.Verification
fails without the fix:packages/core/src/runtime/pausedVideoFrames.test.ts(starts without throwing when document.body is null and still watches documentElement,falls back to documentElement when document.head is null on present)packages/core/src/runtime/init.nullBody.test.ts(initializes and tears down cleanly when document.body is null)pausedVideoFrames.test.tsandinit.nullBody.test.ts3 times in a row, plus sibling runtime tests (vfx.test.ts,pausedVideoCallbacks.test.ts,adapters/video-texture-compat.paused.test.ts,init.startsOnce.test.ts,entry.test.ts,entry.afterFonts.test.ts),tsc --noEmit,oxlint,oxfmt --check, andfallow audit.