Skip to content

fix(core): add authored render readiness gate - #1543

Merged
jrusso1020 merged 2 commits into
mainfrom
codex/render-ready-assets
Jun 18, 2026
Merged

fix(core): add authored render readiness gate#1543
jrusso1020 merged 2 commits into
mainfrom
codex/render-ready-assets

Conversation

@jrusso1020

Copy link
Copy Markdown
Collaborator

Summary

  • add window.__hyperframesReady so authored compositions can delay render readiness until async assets settle
  • keep __renderReady false while authored readiness, external compositions, or GSAP batching are still pending
  • narrow embedded-runtime stripping so authored scripts that merely reference readiness flags are preserved

Verification

  • bun run --cwd packages/core test src/compiler/htmlDocument.test.ts src/runtime/init.test.ts
  • bun run --cwd packages/core typecheck
  • pre-commit hooks: lint, format, fallow, typecheck

@jrusso1020
jrusso1020 force-pushed the codex/render-ready-assets branch from 5e9adc0 to 5104bcf Compare June 17, 2026 22:44

@miguel-heygen miguel-heygen 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.

Reviewed — authored render readiness gate via window.__hyperframesReady promise. Clean promise-identity tracking, correct script-stripping fix for regex-only flag assignments. LGTM.

… flag

Per consensus thread (Miguel/Magi/James + me): instead of a public
`window.__hyperframesReady` promise authors / LLMs are expected to set,
the framework auto-detects async asset loading and gates render readiness
internally. Authors keep writing plain HTML; the framework just waits.

What changed
- `RuntimeDeterministicAdapter.getReadyPromise?: () => PromiseLike | null`
  — new optional adapter contract for async readiness. Runtime collects
  promises from every adapter on each `maybePublishRenderReady()` cycle and
  waits for them to settle before publishing `__renderReady = true`.
- `adapters/three.ts` — hooks `THREE.DefaultLoadingManager.onStart` /
  `onLoad`. Items queued at discover-time AND any items queued later (the
  common case — user composition scripts run after the runtime mounts) both
  arm a wait. The wrapped `onLoad` restores the user's own callback so
  composition-side load handlers still fire.
- `runtime/init.ts` — replaces the authored-promise polling
  (`getAuthoredRenderReadyPromise` / `isAuthoredRenderReadySettled` /
  `window.__hyperframesReady` checks) with adapter-aware
  `isAdapterReadinessSettled()`. Discover is re-run inside
  `maybePublishRenderReady` so adapters can refresh their state from the
  current DOM (e.g. THREE may have just finished loading).
- `runtime/window.d.ts` — removes the public `__hyperframesReady` type
  declaration. The flag was the only authored-facing surface from the
  earlier draft; gone, no LLM/skill teaching required.
- `runtime/init.test.ts` — replaces the authored-readiness test with a
  Three.js LoadingManager test that simulates an in-flight load, asserts
  render-ready is held while pending, and resolves on `mgr.onLoad()`.

Kept from the earlier draft
- The `htmlDocument.ts` script-stripping refactor (substring → regex for
  `__playerReady` / `__renderReady` simple-flag assignments) is independent
  of the readiness-gate question and stays as-is. It fixes a separate bug
  where authored scripts that *reference* the flags (e.g.
  `if (window.__renderReady) ...`) were being stripped despite never
  assigning them.

Verification
- bun run --cwd packages/core test src/runtime/init.test.ts
  src/compiler/htmlDocument.test.ts — 33/33 pass
- bun run --cwd packages/core typecheck — clean
- bunx oxlint / bunx oxfmt --check on changed files — clean

@miguel-heygen miguel-heygen 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.

Re-reviewed after rework — public __hyperframesReady dropped, replaced with internal getReadyPromise adapter contract. Three.js adapter auto-hooks LoadingManager. Zero authoring burden. Script-stripping regex fix retained. LGTM.

@jrusso1020
jrusso1020 merged commit bb5f5f8 into main Jun 18, 2026
47 checks passed
@jrusso1020
jrusso1020 deleted the codex/render-ready-assets branch June 18, 2026 01:47
miguel-heygen added a commit that referenced this pull request Jun 18, 2026
Add readiness-only runtime adapters for Mapbox GL JS, Leaflet, Google
Maps, MapLibre GL JS, and D3. Each adapter gates `__renderReady` until
the library's async initialization completes, preventing the renderer
from capturing blank or half-loaded frames.

Built on the `getReadyPromise` adapter contract from #1543. A shared
`createReadinessAdapter()` helper in `_readiness.ts` owns the
settled-tracking WeakSet, promise-identity stability, and
`Promise.allSettled` gate — each adapter provides only its type, window
global name, and `waitFor` callback.

Readiness signals per library:
- Mapbox / MapLibre: `map.loaded()` + `map.on('load', ...)`
- Leaflet: `map.whenReady(cb)`
- Google Maps: `map.addListener('tilesloaded', cb)` with handle cleanup
- D3: `transition.end()` promise

50 unit tests across 5 test files covering happy path, no-instances,
stable promise identity, post-settle drain, loaded-before-subscribe
race, and listener cleanup. 5 producer regression tests with
Docker-generated baselines for end-to-end render verification.
miguel-heygen added a commit that referenced this pull request Jun 18, 2026
#1548)

Add readiness-only runtime adapters for Mapbox GL JS, Leaflet, Google
Maps, MapLibre GL JS, and D3. Each adapter gates `__renderReady` until
the library's async initialization completes, preventing the renderer
from capturing blank or half-loaded frames.

Built on the `getReadyPromise` adapter contract from #1543. A shared
`createReadinessAdapter()` helper in `_readiness.ts` owns the
settled-tracking WeakSet, promise-identity stability, and
`Promise.allSettled` gate — each adapter provides only its type, window
global name, and `waitFor` callback.

Readiness signals per library:
- Mapbox / MapLibre: `map.loaded()` + `map.on('load', ...)`
- Leaflet: `map.whenReady(cb)`
- Google Maps: `map.addListener('tilesloaded', cb)` with handle cleanup
- D3: `transition.end()` promise

50 unit tests across 5 test files covering happy path, no-instances,
stable promise identity, post-settle drain, loaded-before-subscribe
race, and listener cleanup. 5 producer regression tests with
Docker-generated baselines for end-to-end render verification.
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