Skip to content

fix(core): window.__hf has one type, owned by the runtime that sets it - #9114

Merged
miguel-heygen merged 3 commits into
mainfrom
fix/runtime-hf-protocol-one-owner
Nov 30, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
fix/runtime-hf-protocol-one-owner

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

window.__hf now has one type, HfProtocol, declared in packages/core/src/runtime/hfProtocol.ts together with the global that types window.__hf. Engine re-exports it under its existing names, and shader-transitions imports HfTransitionMeta instead of keeping a copy.

Why

The page's __hf object was typed twice: in core's runtime/window.d.ts (what the runtime sets: seek, colorGrading, clipWindow, ...) and in engine's types.ts as HfProtocol (what the renderer reads: duration, seek, media, transitions). Each package checked fine alone. Any check that loads both fails: Subsequent property declarations must have the same type. Property '__hf' must be of type ... (TS2717). Studio's type check already loads engine, through the dev server's producer import. Its sealed tests reach core runtime files such as editingAgent.ts, which read window.__player and other globals from window.d.ts, so checking those tests means loading window.d.ts too, and the two __hf declarations then collide. That blocks type-checking most of Studio's test folders. Loading window.d.ts there is the next change, not this one. shader-transitions held a third copy of HfTransitionMeta, kept in step by a comment.

How

  • runtime/hfProtocol.ts holds HfMediaElement, HfTransitionMeta and HfProtocol: core's fields plus engine's media and transitions. It also declares Window.__hf, so anything that imports the type gets the global too. Core's index exports the three types, plus RuntimeSeekOptions.
  • window.d.ts no longer declares __hf.
  • Engine's types.ts re-exports HfMediaElement, HfProtocol, HfTransitionMeta and RuntimeSeekOptions as HfSeekOptions from core, and drops its own __hf global.
  • shader-transitions imports HfTransitionMeta from core as a type only, so its CDN bundle does not change.

One type change for engine's callers: engine's HfProtocol had duration and seek required, and core's has them optional, as the runtime sets them during boot. Nothing in this repo relied on that: engine, producer, studio-server, Studio and shader-transitions type-check with no edits. HfSeekOptions gains core's optional exact.

Test plan

  • fails without the fix: a check over core's runtime/window.d.ts and engine's src/types.ts together (a temporary tsconfig in packages/engine with those two files). On main it reports TS2717 at src/types.ts(483,5); here it reports nothing. The guard stays: engine's own typecheck now loads core's declaration, so a second __hf in engine fails there.
  • tsc --noEmit passes in core, engine, producer, studio-server, studio and shader-transitions, plus Studio's tsconfig.check.json.
  • Built output, from clean dist folders, at this commit and its parent: engine and shader-transitions emit identical files. Core emits the same files byte for byte, the runtime bundle included. It adds runtime/hfProtocol.js (export {}), runtime/colorGrading.js and runtime/mutationRecords.js, which the new module's type imports bring into core's build. Nothing in dist imports any of the three.
  • Unit tests added/updated: types only
  • Manual testing performed: the checks and build comparison above
  • Comments follow CONTRIBUTING.md "Comments"

No visible change

Type declarations only; no emitted JavaScript changes for any existing file.

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

Reviewed at c10298d. The change reads right; one check this PR itself turns red holds the approval.

Requesting changes for the Comments check only. The comment ratchet fails on the new file: packages/core/src/runtime/hfProtocol.ts is 36.4% comments (36/99) and the package carries 10.6%. Most of that is the per-field doc lines moved over from the two old declarations. Trim them (the field names already say most of it) or get the file under the share another way, and I approve on the green head with no further read of the rest.

What I checked in the diff, all five files read in full as changed:

  • HfProtocol in core is the old window.d.ts shape field for field, plus media and transitions from the engine copy. Nothing dropped from either side.
  • HfMediaElement and HfTransitionMeta match the engine copies field for field; the shader-transitions copy matched too.
  • window.d.ts loses only __hf and the four imports it alone used.
  • Engine keeps its four exported names; HfSeekOptions is now RuntimeSeekOptions. duration and seek become optional for engine's callers, as the body says. Engine and producer readers I found already guard both (typeof ... === "function", ?? 0).
  • shader-transitions imports the type only, uses it in a local type, and already has core as a dev dependency, so its bundle and its declarations do not gain a dependency.
  • fails without the fix: is in the body.

Not run: type checks, builds or the byte comparison (no installed packages on this box); those claims are taken from the body.

Need: yes, two declarations of one global · Size: +108/-144, right · Reuse: one type, three users · Simpler: no · Structure: the owner of the value owns the type
Risk: low, types only; the optional duration/seek is the one visible change for outside users of the engine types.

— Rames

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 65 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-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

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

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

Quarantined, measured but not gated (0)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at 608fe72, both red checks.

Comments: hfProtocol.ts keeps only what the names cannot say (units, the crossfade case, animationEnd's first cycle, "always release", what buildReady waits for). scripts/comment-ratchet.mjs against main: "7 changed source file(s) at or under their share".

Build (package size), and a correction to the body: the body called the three extra files in core's dist harmless because nothing imports them. They were not harmless. hfProtocol.ts's type import of RuntimeColorGradingApi pulled the whole color grading runtime (runtime/colorGrading.ts, about 4,000 lines) into core's build, which put core 109 KB over its size budget. The four public types of that runtime (RuntimeColorGradingApi, its status and preview types) now live in runtime/colorGradingApi.ts, which colorGrading.ts, init.ts, the test and hfProtocol.ts import. A type import no longer loads the runtime.

Measured at this head against main, from clean dist folders with pnpm pack:

  • core unpacked: 5,399,469 bytes on main, 5,403,989 here (+4,520; budget 5,455,485). The only new JS is runtime/hfProtocol.js and runtime/colorGradingApi.js, both export {}. Every other file is byte-identical, the runtime bundle included.
  • engine and shader-transitions: identical.

Also run: tsc --noEmit in core, engine, producer, studio-server, studio, shader-transitions and player, plus Studio's tsconfig.check.json, all 0 errors. colorGrading.test.ts and init.test.ts: 421 passed.

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

Reviewed at 608fe72 (re-review; prior change request at c10298d).

Prior point: the Comments check was red on packages/core/src/runtime/hfProtocol.ts. Resolved: the comments are trimmed and the check passes at this head.

Delta since c10298d, read whole (compared the PR's own diff at both heads):

  • colorGradingApi.ts is new and holds the four public types, moved byte for byte out of runtime/colorGrading.ts. It imports only a type from ../colorGrading.
  • hfProtocol.ts, init.ts, colorGrading.ts and its test now import those types from the new file. No other importer of the four names exists in the packages.
  • The rest of the delta is main merged in (the Studio type-check slice); against main the PR touches no Studio file.
  • No runtime line changed in the delta.

Not run: build, type check and tests (no installed packages on this machine). Build was still pending when I posted; the size claim (core +4.5 KB instead of +109 KB) is the author's number, not measured by me.

Need: yes · Size: fine · Reuse: one shape in core · Simpler: no · Structure: types file apart from the runtime is the right cut
Risk: low, types only.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 29, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 30, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 766ce92 Nov 30, 2026
109 checks passed
@miguel-heygen
miguel-heygen deleted the fix/runtime-hf-protocol-one-owner branch November 30, 2026 06:24
@miguel-heygen miguel-heygen mentioned this pull request Nov 30, 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