Skip to content

fix(core): guard runtime init and paused video observer when document.body is null - #8936

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/paused-video-frames-null-body
Nov 27, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/paused-video-frames-null-body

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Summary

When the injected runtime starts on a document whose document.body is null (for example a composition whose markup or script removed or has not yet attached <body>), initSandboxRuntimeModular() threw TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node' inside createPausedVideoFrames() and would then dereference document.body again in initVfx() and collectRuntimeTimelinePayload().

Every sibling observer in packages/core/src/runtime/ already observes document.documentElement or guards document.body.

Changes

  • packages/core/src/runtime/pausedVideoFrames.ts: fall back from document.body to document.documentElement (and guard when neither exists) before calling observer.observe(...), and fall back from document.head to document.documentElement when appending the hiding <style> element.
  • packages/core/src/runtime/vfx.ts: accept HTMLElement | null in initVfx and rebuildLostVfx, returning cleanly when root is null.
  • packages/core/src/runtime/init.ts: pass document.body ?? document.documentElement to initVfx and rebuildLostVfx, guard document.body.style dimension mirroring, and guard document.body when counting mounted elements.
  • packages/core/src/runtime/timeline.ts: fall back from root ?? document.body to document.documentElement (and guard when null) before calling parseElementDurationAttr.
  • packages/core/src/runtime/afterFonts.ts: fall back from document.body to document.documentElement before 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)
  • Ran pausedVideoFrames.test.ts and init.nullBody.test.ts 3 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, and fallow audit.

@miguel-heygen miguel-heygen added the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 26, 2026

@jerry-heygen jerry-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

@jerry-heygen jerry-heygen removed the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 91 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)

Unstable (1)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 0c3bd55 Nov 27, 2026
104 checks passed
@miguel-heygen
miguel-heygen deleted the fix/paused-video-frames-null-body branch November 27, 2026 00:22
@jrusso1020 jrusso1020 mentioned this pull request Nov 27, 2026
4 of 5 tasks
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