Skip to content

fix(slideshow): retry init at DOMContentLoaded when the children were not parsed yet - #3750

Merged
jrusso1020 merged 1 commit into
heygen-com:mainfrom
BuddhiLW:fix/slideshow-init-race
Sep 7, 2026
Merged

fix(slideshow): retry init at DOMContentLoaded when the children were not parsed yet#3750
jrusso1020 merged 1 commit into
heygen-com:mainfrom
BuddhiLW:fix/slideshow-init-race

Conversation

@BuddhiLW

@BuddhiLW BuddhiLW commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What

<hyperframes-slideshow> retries init() at DOMContentLoaded when the deferred init ran before its children were parsed.

Why

connectedCallback schedules init() on setTimeout(0) and expects the parser to have appended the children by then. That holds when the page arrives in one piece, and not otherwise. With player.js and slideshow.js loaded from <head>, which is the layout hyperframes present emits, the page bound when served by present's own server, but the same HTML served by a plain static file server (python3 -m http.server) never bound in headless Chromium: init() ran on an empty subtree, returned, and the deck had no chrome and dead arrow keys. Calling init() by hand afterwards bound it.

I hit this exporting decks from Plato (a Clojure slide engine) to HyperFrames; it works around it by placing the scripts after the element.

How

  • locateSlideshowParts(root) classifies the subtree as ready or incomplete (no-player, no-island, malformed-island). init() uses it in place of the inline checks.
  • On incomplete, retryInitWhenParsed arms one DOMContentLoaded listener, only while document.readyState === "loading". Once parsing is over nothing more will arrive, so a missing or malformed island still fails quietly as before.
  • The listener is dropped in disconnectedCallback and guarded by initGeneration, like the timer.

Test plan

  • Unit tests: the classification and the readyState rule directly; the element binds at DOMContentLoaded once the children exist, retries after a truncated island, does not arm once parsing is over, drops the retry on disconnect. vitest in packages/player: 88 passed.
  • typecheck, oxlint, oxfmt --check, fallow via the pre-commit hook.
  • Manual, headless Chromium, the present page over a static file server: 0.8.30 bundle never binds; this branch's bundle binds and ArrowRight advances. Served by hyperframes present itself, both bind.
  • Documentation updated (not applicable)

… not parsed yet

connectedCallback defers init to a setTimeout(0) so the parser can append
the element's children first. With the bundle loaded from <head>, as
`hyperframes present` emits it, headless Chromium fires that timer while
the parser is still inside <hyperframes-slideshow>: init finds no player
or a half-streamed island, returns, and the deck never binds.

While document.readyState is "loading", init now retries once at
DOMContentLoaded. After parsing there is nothing to wait for, so a missing
or malformed island still fails quietly as before. The subtree check is
split out as locateSlideshowParts so the classification is testable
without the element lifecycle.

@jrusso1020 jrusso1020 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.

No blocking findings. The one-shot parser retry is bounded by readyState and guarded against stale connections (packages/player/src/slideshow/hyperframes-slideshow.ts:532); disconnect removes the listener (:312). Reconnect and parser-event ordering also check out.

Validation: all 88 slideshow tests passed locally. CI has no failures reported but several checks are still running; the manual Chromium repro was not independently repeated.

— Codex

Verdict: APPROVE
Reasoning: This narrowly fixes early initialization without changing post-parse failure behavior, and covers missing/truncated children and disconnect cleanup.

@jrusso1020
jrusso1020 merged commit dc9fb67 into heygen-com:main Sep 7, 2026
51 checks passed
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