From b1fbc16b6cc2a40301409f04fd312cc7c2d6a417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 16 Oct 2026 23:50:49 +0000 Subject: [PATCH 01/36] fix(cli): check finishes on video-heavy projects, its geometry seeks skip only video-frame waits (#5715) * fix(cli): check's dense geometry seeks stop waiting for video frames they never read * test(cli): race the dense seek against the barrier ask instead of a timer * fix(cli): keep the geometry seek's comment share at its base * fix(cli): dense geometry seeks still wait for frame sources, only video frames are skipped --- .../capture/captureCompositionFrame.test.ts | 26 ++++++++++++++++--- .../src/capture/captureCompositionFrame.ts | 22 +++++++++++----- .../src/runtime/adapters/seek-dispatch.ts | 16 +++++++++--- .../core/src/runtime/frameSources.test.ts | 13 ++++++++++ packages/core/src/runtime/media.test.ts | 6 +++++ packages/core/src/runtime/media.ts | 1 + packages/core/src/runtime/mediaProxy.ts | 5 +++- packages/core/src/runtime/window.d.ts | 4 +-- 8 files changed, 76 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/capture/captureCompositionFrame.test.ts b/packages/cli/src/capture/captureCompositionFrame.test.ts index 16c23b80c6..cd9a3f5ea9 100644 --- a/packages/cli/src/capture/captureCompositionFrame.test.ts +++ b/packages/cli/src/capture/captureCompositionFrame.test.ts @@ -27,7 +27,7 @@ function fakeSeekPage() { const evaluate = vi.fn( async ( _pageFunction: Parameters[0], - _value?: number, + _value?: Parameters[1], _fallbackToBridgeAndTimelines?: boolean, ): Promise => undefined, ); @@ -108,7 +108,7 @@ describe("seekCompositionTimeline", () => { expect(waitForFunction).not.toHaveBeenCalled(); expect(evaluate).toHaveBeenCalledTimes(4); expect(evaluate).toHaveBeenNthCalledWith(1, expect.any(Function), 1.25, false, false); - expect(evaluate).toHaveBeenNthCalledWith(2, expect.any(Function)); + expect(evaluate).toHaveBeenNthCalledWith(2, expect.any(Function), { videoFrames: true }); expect(evaluate.mock.calls[2]?.[0]).toContain("window.setTimeout(finish, 100)"); // Post-seek font settle: a seek can reveal glyphs whose unicode-range // subsets only start loading after the next layout (CJK snapshot reports). @@ -230,7 +230,7 @@ describe("seekCompositionTimeline", () => { expect(evaluate).toHaveBeenCalledTimes(4); expect(evaluate).toHaveBeenNthCalledWith(1, expect.any(Function), 4, true, false); - expect(evaluate).toHaveBeenNthCalledWith(2, expect.any(Function)); + expect(evaluate).toHaveBeenNthCalledWith(2, expect.any(Function), { videoFrames: true }); expect(evaluate).toHaveBeenNthCalledWith(3, expect.any(Function)); expect(evaluate).toHaveBeenNthCalledWith(4, expect.any(Function), 500); }); @@ -471,6 +471,26 @@ describe("installPageFunctionGuard", () => { }); describe("DENSE_GEOMETRY_SEEK_OPTIONS", () => { + // A 79 s project of 1080p H.264 clips: each of the 600 dense seeks waited ~185 ms for a video frame it never reads, + // so `check` ran past its deadline. Frame sources and hf-seek work can move the DOM, so those still hold it. + it("skips only the seek barrier's video-frame holds, while the audit seek waits for all", async () => { + const barrierCalls = async (options: Parameters[2]) => { + const { page, evaluate } = fakeSeekPage(); + const barrier = vi.fn(async (_options?: { videoFrames?: boolean }) => {}); + vi.stubGlobal("window", { __hfWaitForSeekCompletion: barrier }); + evaluate.mockImplementation(async (pageFunction, value) => + typeof pageFunction === "function" && typeof value === "object" + ? Reflect.apply(pageFunction, undefined, [value]) + : undefined, + ); + await seekCompositionTimeline(page, 3, options); + return barrier.mock.calls; + }; + + expect(await barrierCalls(DENSE_GEOMETRY_SEEK_OPTIONS)).toEqual([[{ videoFrames: false }]]); + expect(await barrierCalls(AUDIT_SEEK_OPTIONS)).toEqual([[{ videoFrames: true }]]); + }); + it("is genuinely geometry-only — no post-seek settle waits at the 600-sample cap", () => { // Dense pass must not inherit AUDIT's post-seek waits — geometry is valid synchronously after setTime, and waits multiply by sample count. expect(DENSE_GEOMETRY_SEEK_OPTIONS.animationFrameSettle).toBe("none"); diff --git a/packages/cli/src/capture/captureCompositionFrame.ts b/packages/cli/src/capture/captureCompositionFrame.ts index a029db5ca8..5321d4fbaf 100644 --- a/packages/cli/src/capture/captureCompositionFrame.ts +++ b/packages/cli/src/capture/captureCompositionFrame.ts @@ -40,6 +40,7 @@ export const DENSE_GEOMETRY_SEEK_OPTIONS = { animationFrameSettle: "none", waitForFontsMs: 0, settleMs: 0, + waitForVideoFrames: false, } as const; export interface SeekCompositionTimelineOptions { @@ -49,18 +50,22 @@ export interface SeekCompositionTimelineOptions { animationFrameSettle?: "race" | "double" | "none"; waitForFontsMs?: number; settleMs?: number; + waitForVideoFrames?: boolean; } +type SeekBarrierOptions = { videoFrames: boolean }; + type CompositionPageFunction = | string | (() => unknown) | ((value: number) => unknown) + | ((barrier: SeekBarrierOptions) => unknown) | ((value: number, fallbackToBridgeAndTimelines: boolean, exactTime: boolean) => unknown); export interface CompositionEvaluationPage { evaluate( pageFunction: CompositionPageFunction, - value?: number, + value?: number | SeekBarrierOptions, fallbackToBridgeAndTimelines?: boolean, exactTime?: boolean, ): Promise; @@ -341,12 +346,15 @@ export async function seekCompositionTimeline( options.exactTime === true, ); - await page.evaluate(async () => { - const waitForCompletion = Reflect.get(window, "__hfWaitForSeekCompletion"); - if (typeof waitForCompletion === "function") { - await Reflect.apply(waitForCompletion, window, []); - } - }); + await page.evaluate( + async (barrier: SeekBarrierOptions) => { + const waitForCompletion = Reflect.get(window, "__hfWaitForSeekCompletion"); + if (typeof waitForCompletion === "function") { + await Reflect.apply(waitForCompletion, window, [barrier]); + } + }, + { videoFrames: options.waitForVideoFrames !== false }, + ); const animationFrameSettle = options.animationFrameSettle ?? "race"; if (animationFrameSettle === "race") { diff --git a/packages/core/src/runtime/adapters/seek-dispatch.ts b/packages/core/src/runtime/adapters/seek-dispatch.ts index 011e7cdfc9..8bce055eef 100644 --- a/packages/core/src/runtime/adapters/seek-dispatch.ts +++ b/packages/core/src/runtime/adapters/seek-dispatch.ts @@ -21,6 +21,7 @@ import { swallow } from "../diagnostics"; let _lastDispatchedTime = -1; type SeekCompletionResult = { status: "fulfilled" } | { status: "rejected"; reason: unknown }; let _pendingCompletions = new Set>(); +let _videoFrameCompletions = new WeakSet>(); let _pendingFailure: { reason: unknown } | undefined; let _activeCompletionBarriers = 0; @@ -62,11 +63,12 @@ function dispatch(time: number): void { * its preview-side capture here, so the CLI seek paths that already await this * barrier wait for a `self` chain's paint instead of racing it. */ -export function registerSeekCompletion(promise: Promise): void { +export function registerSeekCompletion(promise: Promise, kind?: "video-frame"): void { const completion = promise .then(() => ({ status: "fulfilled" })) .catch((reason: unknown) => ({ status: "rejected", reason })); _pendingCompletions.add(completion); + if (kind === "video-frame") _videoFrameCompletions.add(completion); void completion.then((result) => { if (!_pendingCompletions.delete(completion)) return; if (result.status === "rejected" && _pendingFailure === undefined) { @@ -100,15 +102,20 @@ export function isSeekCompletionBarrierActive(): boolean { return _activeCompletionBarriers > 0; } -export async function waitForSeekCompletion(): Promise { +/** `videoFrames: false` skips only the video-frame holds: a geometry read needs every other completion. */ +export async function waitForSeekCompletion(options?: { videoFrames?: boolean }): Promise { + const awaited = () => + [..._pendingCompletions].filter( + (completion) => options?.videoFrames !== false || !_videoFrameCompletions.has(completion), + ); _activeCompletionBarriers += 1; let failed = _pendingFailure; try { // Let concurrently started barriers snapshot the same retained failure // before either one consumes it. await Promise.resolve(); - while (_pendingCompletions.size > 0) { - const results = await Promise.all([..._pendingCompletions]); + for (let pending = awaited(); pending.length > 0; pending = awaited()) { + const results = await Promise.all(pending); const rejected = results.find((result) => result.status === "rejected"); if (failed === undefined && rejected?.status === "rejected") { failed = { reason: rejected.reason }; @@ -131,6 +138,7 @@ export async function waitForSeekCompletion(): Promise { export function resetSeekDispatchState(): void { _lastDispatchedTime = -1; _pendingCompletions = new Set(); + _videoFrameCompletions = new WeakSet(); _pendingFailure = undefined; _activeCompletionBarriers = 0; } diff --git a/packages/core/src/runtime/frameSources.test.ts b/packages/core/src/runtime/frameSources.test.ts index e6bd4c16fc..f717fc0c2c 100644 --- a/packages/core/src/runtime/frameSources.test.ts +++ b/packages/core/src/runtime/frameSources.test.ts @@ -42,6 +42,19 @@ afterEach(() => { }); describe("frame sources", () => { + it("holds a geometry read that skips video frames until its asynchronous draw lands", async () => { + const frame = deferred(); + disposers.push(registerFrameSource({ element: mount(), render: () => frame.promise })); + adapter().seek({ time: 2 }); + let captured = false; + const capture = waitForSeekCompletion({ videoFrames: false }).then(() => (captured = true)); + await Promise.resolve(); + expect(captured).toBe(false); + frame.resolve(); + await capture; + expect(captured).toBe(true); + }); + it("holds capture through setup and asynchronous drawing", async () => { const setup = deferred(); const frame = deferred(); diff --git a/packages/core/src/runtime/media.test.ts b/packages/core/src/runtime/media.test.ts index 34dedbfa66..0bdeea7677 100644 --- a/packages/core/src/runtime/media.test.ts +++ b/packages/core/src/runtime/media.test.ts @@ -742,6 +742,12 @@ describe("syncRuntimeMedia", () => { expect(await barrierSettled(barrier)).toBe(true); }); + it("does not hold a geometry read for a seeking video's frame", async () => { + seekColdVideo(); + expect(await barrierSettled(waitForSeekCompletion({ videoFrames: false }))).toBe(true); + expect(await barrierSettled(waitForSeekCompletion())).toBe(false); + }); + function seekLoadingVideo(): RuntimeMediaClip { const clip = createMockClip({ start: 7.1, end: 18.24 }); Object.defineProperty(clip.el, "readyState", { value: 0, configurable: true }); diff --git a/packages/core/src/runtime/media.ts b/packages/core/src/runtime/media.ts index a23338c319..3685fea529 100644 --- a/packages/core/src/runtime/media.ts +++ b/packages/core/src/runtime/media.ts @@ -48,6 +48,7 @@ function holdSeekBarrierUntilVideoLands(el: HTMLMediaElement): void { for (const type of HOLD_END_EVENTS) el.addEventListener(type, done, true); releaseHeldVideo.set(el, done); }), + "video-frame", ); } diff --git a/packages/core/src/runtime/mediaProxy.ts b/packages/core/src/runtime/mediaProxy.ts index eea5fa1c1e..8639b028d5 100644 --- a/packages/core/src/runtime/mediaProxy.ts +++ b/packages/core/src/runtime/mediaProxy.ts @@ -347,7 +347,10 @@ export function swapToProxy( }); }); // A frame capture holds for the copy as it held for a loading video before, up to the same cap. - registerSeekCompletion(Promise.race([swap, new Promise((cap) => setTimeout(cap, HOLD_CAP_MS))])); + registerSeekCompletion( + Promise.race([swap, new Promise((cap) => setTimeout(cap, HOLD_CAP_MS))]), + "video-frame", + ); const codecName = entry?.codecName ?? null; const details: Record = { asset: originalSrc, diff --git a/packages/core/src/runtime/window.d.ts b/packages/core/src/runtime/window.d.ts index 542b834dc0..c086ab80e8 100644 --- a/packages/core/src/runtime/window.d.ts +++ b/packages/core/src/runtime/window.d.ts @@ -132,9 +132,9 @@ declare global { __hfReseekGpu?: (time: number) => void; /** * Await GPU work registered synchronously by `hf-seek` listeners through - * `event.detail.waitUntil(...)`. + * `event.detail.waitUntil(...)`; `videoFrames: false` skips the video-frame holds. */ - __hfWaitForSeekCompletion?: () => Promise; + __hfWaitForSeekCompletion?: (options?: { videoFrames?: boolean }) => Promise; /** * Canonical root-timeline start for a media element. Snapshot capture uses * this runtime-owned resolver so reference expressions, authored timing From 35b17c3fe6cdf7e40d252f1d813b0a2cecec6a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sat, 17 Oct 2026 00:44:30 +0000 Subject: [PATCH 02/36] chore: release v0.8.167 (#5730) --- .claude-plugin/plugin.json | 2 +- .codex-plugin/plugin.json | 2 +- .cursor-plugin/plugin.json | 2 +- docs/changelog.mdx | 26 ++++++++++++++++++++++++ gemini-extension.json | 2 +- packages/aws-lambda/package.json | 2 +- packages/cli/package.json | 2 +- packages/core/package.json | 2 +- packages/engine/package.json | 2 +- packages/gcp-cloud-run/package.json | 2 +- packages/inspector/package.json | 2 +- packages/lint/package.json | 2 +- packages/parsers/package.json | 2 +- packages/player/package.json | 2 +- packages/producer/package.json | 2 +- packages/sdk/package.json | 2 +- packages/shader-transitions/package.json | 2 +- packages/studio-server/package.json | 2 +- packages/studio/package.json | 2 +- plugin.json | 2 +- releases/v0.8.167.md | 25 +++++++++++++++++++++++ 21 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 releases/v0.8.167.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index e7e1e63ed2..f382e5e624 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "hyperframes", "description": "HyperFrames by HeyGen. Write HTML, render video. Compositions, GSAP and runtime adapter animations, captions, voiceovers, audio-reactive visuals, and website capture for HyperFrames.", - "version": "0.8.166", + "version": "0.8.167", "author": { "name": "HeyGen", "email": "hyperframes@heygen.com", diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json index 5619aa6646..21a26ccacc 100644 --- a/.codex-plugin/plugin.json +++ b/.codex-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "hyperframes", "description": "Write HTML, render video. Compositions, Tailwind v4 styles, GSAP and runtime adapter animations, captions, voiceovers, audio-reactive visuals, and website capture for HyperFrames.", - "version": "0.8.166", + "version": "0.8.167", "author": { "name": "HeyGen", "email": "hyperframes@heygen.com", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 19e3b67443..a04bc1cebf 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -3,7 +3,7 @@ "name": "hyperframes", "displayName": "HyperFrames by HeyGen", "description": "Write HTML, render video. Compositions, Tailwind v4 styles, GSAP and runtime adapter animations, captions, voiceovers, audio-reactive visuals, and website capture for HyperFrames.", - "version": "0.8.166", + "version": "0.8.167", "author": { "name": "HeyGen", "email": "hyperframes@heygen.com" diff --git a/docs/changelog.mdx b/docs/changelog.mdx index d06c3f29a2..cc5bd3a15b 100644 --- a/docs/changelog.mdx +++ b/docs/changelog.mdx @@ -8,6 +8,32 @@ Recent HyperFrames releases, including user-facing features, fixes, and migratio {/* New release entries are prepended by `bun run changelog:draft --write`. */} + +Long projects preview more smoothly: the preview's work now follows what is playing, not the total clip count. Bundling a project also stops freezing the app that runs it. + +## Fixes + +- **Core:** Bundling a project no longer blocks the host's thread on esbuild ([b1cf6e3c517](https://github.com/heygen-com/hyperframes/commit/b1cf6e3c517e227d1dca1b212e7637c19e502a64), [#5714](https://github.com/heygen-com/hyperframes/pull/5714)). +- **CLI:** Page loads stop timing out while a busy machine's Chrome warms up ([41486b9725a](https://github.com/heygen-com/hyperframes/commit/41486b9725ab2aae4f457d75dcd625931d103bb3), [#5705](https://github.com/heygen-com/hyperframes/pull/5705)). + +## Performance + +- **Core:** Hold a clip at 0 inside a later scene until it is due ([13ea8349597](https://github.com/heygen-com/hyperframes/commit/13ea8349597bbcb874402d1771aea65766fd7ffc), [#5716](https://github.com/heygen-com/hyperframes/pull/5716)). +- **Core:** A preview's composition scripts give the page a turn every 50 ms, not one long task ([12d8df37f4d](https://github.com/heygen-com/hyperframes/commit/12d8df37f4db8ccf019da32c97cc1352f8db9652), [#5713](https://github.com/heygen-com/hyperframes/pull/5713)). +- **Lint:** Strip stylesheet comments once per canvas zoom scan ([0bff8342c38](https://github.com/heygen-com/hyperframes/commit/0bff8342c389c1841d3b8d858168700f13627e48), [#5712](https://github.com/heygen-com/hyperframes/pull/5712)). +- **Core:** Preview runtime scales with what plays, not with the film's clip count ([d05bc4215d5](https://github.com/heygen-com/hyperframes/commit/d05bc4215d5757da86956217f4a8a4b2ab11b1fd), [#5674](https://github.com/heygen-com/hyperframes/pull/5674)). + +## Internal + +- **CLI:** Caption image test checks the close itself, not a reusable file number ([eace3d28b6c](https://github.com/heygen-com/hyperframes/commit/eace3d28b6cb721ec1f9a96d7d2ea76bf215551a), [#5707](https://github.com/heygen-com/hyperframes/pull/5707)). + +[View the full commit range](https://github.com/heygen-com/hyperframes/compare/v0.8.166...v0.8.167). + + Date: Sat, 17 Oct 2026 00:47:28 +0000 Subject: [PATCH 03/36] fix(core): a composition mounted twice keeps each mount's own timeline (#5729) --- .../core/src/compiler/compositionAssembly.ts | 8 ++++ .../src/compiler/compositionScoping.test.ts | 39 +++++++++++++++++++ .../core/src/compiler/compositionScoping.ts | 18 +++++---- .../core/src/compiler/htmlBundler.test.ts | 24 ++++++++++++ packages/core/src/compiler/htmlBundler.ts | 2 + .../src/runtime/compositionLoader.test.ts | 24 ++++++++++++ .../core/src/runtime/compositionLoader.ts | 2 + .../src/helpers/compositionInsertion.test.ts | 26 ++++++++++++- .../src/helpers/compositionInsertion.ts | 10 +++-- .../src/helpers/sourceMutation.ts | 13 ++++++- .../sourceMutationSplitAndGroup.test.ts | 29 ++++++++++---- 11 files changed, 174 insertions(+), 21 deletions(-) diff --git a/packages/core/src/compiler/compositionAssembly.ts b/packages/core/src/compiler/compositionAssembly.ts index 97198ecb39..9207bfb492 100644 --- a/packages/core/src/compiler/compositionAssembly.ts +++ b/packages/core/src/compiler/compositionAssembly.ts @@ -309,3 +309,11 @@ export function enumerateNestedCompositionHosts, hosts: readonly Element[]): void { + const root = hosts[0]?.ownerDocument.querySelector("[data-composition-id]"); + const rootId = root && !hosts.includes(root) ? root.getAttribute("data-composition-id") : null; + const mounts = rootId ? counts.get(rootId) : undefined; + if (rootId && mounts) counts.set(rootId, mounts + 1); +} diff --git a/packages/core/src/compiler/compositionScoping.test.ts b/packages/core/src/compiler/compositionScoping.test.ts index dbca7a6916..559d11c5e4 100644 --- a/packages/core/src/compiler/compositionScoping.test.ts +++ b/packages/core/src/compiler/compositionScoping.test.ts @@ -43,6 +43,45 @@ describe("composition scoping", () => { } }); + it("never replaces another mount's timeline under the scene's own id", () => { + const { document } = parseHTML("
"); + const fakeWindow = { document, __timelines: {} as Record, readBack: "" }; + const run = (runtimeId: string, timeline: string) => + new Function( + "window", + wrapScopedCompositionScript( + `window.__timelines.scene = ${JSON.stringify(timeline)}; + window.readBack = window.__timelines.scene;`, + "scene", + undefined, + undefined, + runtimeId, + ), + )(fakeWindow); + + run("scene", "first half"); + run("scene-split", "second half"); + expect(fakeWindow.__timelines).toEqual({ scene: "first half", "scene-split": "second half" }); + expect(fakeWindow.readBack).toBe("second half"); + + // A mount that owns the scene's id keeps it when its script runs again. + const lone = { document, __timelines: {} as Record }; + const runLone = (timeline: string) => + new Function( + "window", + wrapScopedCompositionScript( + `window.__timelines.scene = ${JSON.stringify(timeline)};`, + "scene", + undefined, + undefined, + "intro", + ), + )(lone); + runLone("v1"); + runLone("v2"); + expect(lone.__timelines).toEqual({ scene: "v2", intro: "v2" }); + }); + it("scopes regular selectors while preserving global at-rules", () => { const scoped = scopeCssToComposition( ` diff --git a/packages/core/src/compiler/compositionScoping.ts b/packages/core/src/compiler/compositionScoping.ts index 703a6e5aaa..27f868a0ae 100644 --- a/packages/core/src/compiler/compositionScoping.ts +++ b/packages/core/src/compiler/compositionScoping.ts @@ -415,10 +415,8 @@ export function wrapScopedCompositionScript( if (prop !== __hfCompId) { return Reflect.get(target, prop, target); } - var authoredValue = Reflect.get(target, prop, target); - return authoredValue === undefined - ? Reflect.get(target, __hfTimelineCompId, target) - : authoredValue; + var runtimeValue = Reflect.get(target, __hfTimelineCompId, target); + return runtimeValue === undefined ? Reflect.get(target, prop, target) : runtimeValue; }, set: function(target, prop, value, receiver) { if (prop !== __hfCompId) { @@ -426,11 +424,15 @@ export function wrapScopedCompositionScript( } // The authored node remains in the compiled DOM when its local id // differs from the runtime mount id, so readiness legitimately sees - // both compositions. Publish the same timeline under both identities - // instead of replacing one with the other. - var authoredSet = Reflect.set(target, __hfCompId, value, target); + // both compositions. Publish the same timeline under both identities, + // unless another mount of the same file already owns the authored one. + var authoredValue = Reflect.get(target, __hfCompId, target); + var ownsAuthored = + authoredValue === undefined || + authoredValue === Reflect.get(target, __hfTimelineCompId, target); var runtimeSet = Reflect.set(target, __hfTimelineCompId, value, target); - return authoredSet && runtimeSet; + if (!ownsAuthored) return runtimeSet; + return Reflect.set(target, __hfCompId, value, target) && runtimeSet; }, }); } diff --git a/packages/core/src/compiler/htmlBundler.test.ts b/packages/core/src/compiler/htmlBundler.test.ts index ec2795986c..a511cc885a 100644 --- a/packages/core/src/compiler/htmlBundler.test.ts +++ b/packages/core/src/compiler/htmlBundler.test.ts @@ -1080,6 +1080,30 @@ describe("bundleToSingleHtml", () => { expect(bundled).toContain('var __hfTimelineCompId = "scene__hf2"'); }); + it("gives a mount that shares the page root's id its own runtime id", async () => { + const cliRoot = (title: string) => + `

${title}

`; + const dir = makeTempProject({ + "index.html": ` + + ${cliRoot("Host")} +
+
+ +`, + "compositions/scene.html": `${cliRoot("Scene")} + +`, + }); + + const bundled = await bundleToSingleHtml(dir); + const host = parseHTML(bundled).document.querySelector("#main_2"); + + expect(host?.getAttribute("data-composition-id")).toBe("main__hf1"); + expect(host?.getAttribute("data-hf-original-composition-id")).toBe("main"); + expect(bundled).toContain('var __hfTimelineCompId = "main__hf1"'); + }); + it("uniquifies duplicate sub-compositions across inline-template and external hosts", async () => { const dir = makeTempProject({ "index.html": ` diff --git a/packages/core/src/compiler/htmlBundler.ts b/packages/core/src/compiler/htmlBundler.ts index 6dc5e357a9..7f385202bc 100644 --- a/packages/core/src/compiler/htmlBundler.ts +++ b/packages/core/src/compiler/htmlBundler.ts @@ -11,6 +11,7 @@ import { type CompositionStyle, } from "./scriptRuns"; import { + countPageRoot, executableScripts, isJavaScriptType, planCompositionAssembly, @@ -553,6 +554,7 @@ function countBundledAuthoredCompositionIds(hosts: Element[]): Map { expect(hostB.querySelector('[data-hf-authored-id="scene-root"]')).toBeTruthy(); }); + it("gives a mount that shares the page root's id its own runtime id", async () => { + const root = document.createElement("div"); + root.setAttribute("data-composition-id", "main"); + document.body.appendChild(root); + const host = document.createElement("div"); + host.setAttribute("data-composition-src", "https://example.com/scene.html"); + host.setAttribute("data-composition-id", "main"); + root.appendChild(host); + vi.spyOn(globalThis, "fetch").mockImplementation( + async () => + new Response( + `

Scene

`, + { status: 200 }, + ), + ); + + await loadFixture(); + + expect(root.getAttribute("data-composition-id")).toBe("main"); + expect(host.getAttribute("data-composition-id")).toBe("main__hf1"); + expect(host.getAttribute("data-hf-original-composition-id")).toBe("main"); + expect(host.querySelector("h1")?.textContent).toBe("Scene"); + }); + it("normalizes a runtime composition id back to the authored id when only one host remains", async () => { const hostA = document.createElement("div"); hostA.setAttribute("data-composition-src", "https://example.com/scene.html"); diff --git a/packages/core/src/runtime/compositionLoader.ts b/packages/core/src/runtime/compositionLoader.ts index 3e83a8e219..319ae435fb 100644 --- a/packages/core/src/runtime/compositionLoader.ts +++ b/packages/core/src/runtime/compositionLoader.ts @@ -4,6 +4,7 @@ import { refreshSvgSelectorAliases, } from "../compiler/svgSelectorAliases"; import { + countPageRoot, planCompositionAssembly, extractedCompositionAssets, } from "../compiler/compositionAssembly"; @@ -300,6 +301,7 @@ function countAuthoredCompositionIds(hosts: Element[]): Map { if (!compId) continue; hostCountsByCompositionId.set(compId, (hostCountsByCompositionId.get(compId) || 0) + 1); } + countPageRoot(hostCountsByCompositionId, hosts); return hostCountsByCompositionId; } diff --git a/packages/studio-server/src/helpers/compositionInsertion.test.ts b/packages/studio-server/src/helpers/compositionInsertion.test.ts index 69a1aa582f..b1666bfcb9 100644 --- a/packages/studio-server/src/helpers/compositionInsertion.test.ts +++ b/packages/studio-server/src/helpers/compositionInsertion.test.ts @@ -97,7 +97,31 @@ describe("insertCompositionIntoSource", () => { ); expect(result.hostId).toBe("headline_2"); - expect(new Set(ids).size).toBe(ids.length); + expect(ids).toEqual(["main", "headline", "headline"]); + }); + + it("mounts a project whose root shares the parent root's id under its own host id", () => { + const dir = project(); + const cliRoot = (title: string) => ` +
${title}
+ `; + writeFileSync(join(dir, "index.html"), cliRoot("Host")); + writeFileSync(join(dir, "scene.html"), cliRoot("Scene")); + + const result = insertCompositionIntoSource({ + projectDir: dir, + targetPath: "index.html", + sourcePath: "scene.html", + parentSource: cliRoot("Host"), + start: 0, + desiredTrack: 0, + }); + const host = parseHTML(result.html).document.querySelector("[data-composition-src]"); + + expect(result.hostId).not.toBe("main"); + expect(result.hostId).not.toBe("root"); + expect(host?.id).toBe(result.hostId); + expect(host?.getAttribute("data-composition-id")).toBe("main"); }); it("ignores nested composition internals when resolving a parent track collision", () => { diff --git a/packages/studio-server/src/helpers/compositionInsertion.ts b/packages/studio-server/src/helpers/compositionInsertion.ts index 6d60c74863..5ece43dae7 100644 --- a/packages/studio-server/src/helpers/compositionInsertion.ts +++ b/packages/studio-server/src/helpers/compositionInsertion.ts @@ -153,8 +153,8 @@ function resolveTrack( function uniqueHostId(root: Element, base: string): string { const ids = new Set([ - ...descendants(root, "[id]").map((element) => element.id), - ...descendants(root, "[data-composition-id]").flatMap((element) => { + ...[root, ...descendants(root, "[id]")].map((element) => element.id), + ...[root, ...descendants(root, "[data-composition-id]")].flatMap((element) => { const id = element.getAttribute("data-composition-id"); return id ? [id] : []; }), @@ -192,8 +192,9 @@ export function insertCompositionIntoSource(input: { const height = positiveAttribute(sourceComposition, "data-height"); const { document, root } = compositionRoot(input.parentSource); const parentDuration = positiveAttribute(root, "data-duration", "data-composition-duration"); + const sourceCompositionId = sourceComposition.getAttribute("data-composition-id") ?? ""; const base = - (sourceComposition.getAttribute("data-composition-id") ?? "composition") + (sourceCompositionId || "composition") .replace(/[^a-zA-Z0-9_-]+/g, "-") .replace(/^-+|-+$/g, "") || "composition"; const hostId = uniqueHostId(root, base); @@ -216,7 +217,8 @@ export function insertCompositionIntoSource(input: { host.id = hostId; host.className = "clip"; host.setAttribute("data-hf-id", `hf-${randomUUID()}`); - host.setAttribute("data-composition-id", hostId); + const mountedRootId = sourceCompositionId || hostId; + host.setAttribute("data-composition-id", mountedRootId); host.setAttribute("data-composition-src", relativeSourcePath(targetAbs, sourceAbs)); host.setAttribute("data-start", String(Math.round(input.start * 100) / 100)); host.setAttribute("data-duration", String(duration)); diff --git a/packages/studio-server/src/helpers/sourceMutation.ts b/packages/studio-server/src/helpers/sourceMutation.ts index 6f6dc1a118..4cda4cf4b9 100644 --- a/packages/studio-server/src/helpers/sourceMutation.ts +++ b/packages/studio-server/src/helpers/sourceMutation.ts @@ -173,9 +173,20 @@ export function isHTMLElement(el: Node): el is HTMLElement { return HTMLEl ? el instanceof HTMLEl : el.nodeType === 1 && "style" in el; } +// A mount's id names the root it mounts; the runtime numbers repeated mounts (id__hf1, id__hf2). +function mountsComposition(document: Document, host: Element, compositionId: string): boolean { + if (host.hasAttribute("data-composition-src")) return true; + return ( + host.children.length === 0 && + querySelectorAllWithTemplates(document, "template").some( + (template) => template.id === `${compositionId}-template`, + ) + ); +} + export function dedupeClonedCompositionId(document: Document, clone: Element): void { const compositionId = clone.getAttribute("data-composition-id"); - if (!compositionId) return; + if (!compositionId || mountsComposition(document, clone, compositionId)) return; const usedCompositionIds = new Set( querySelectorAllWithTemplates(document, "[data-composition-id]").map((node) => node.getAttribute("data-composition-id"), diff --git a/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts b/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts index 896bd488b3..902a2d5e5f 100644 --- a/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts +++ b/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts @@ -87,7 +87,7 @@ describe("splitElementInHtml", () => { expect(result.html).toMatch(/id="box-split"[^>]*class="clip"/); }); - it("gives a split composition host a unique composition id", () => { + it("keeps every half of a split composition mount on the root it mounts", () => { const composition = source.replace( 'id="box" class="clip"', 'id="box" class="clip" data-composition-id="headline" data-composition-src="headline.html"', @@ -97,13 +97,28 @@ describe("splitElementInHtml", () => { const second = splitElementInHtml(first.html, { id: "box-split" }, 4, "box-split-2"); const { document } = parseHTML(second.html); - const compositionIds = Array.from( - document.querySelectorAll("[data-composition-id]"), - (element) => element.getAttribute("data-composition-id"), + const mounts = Array.from(document.querySelectorAll("[data-composition-src]")); + expect(mounts.map((element) => element.getAttribute("data-composition-id"))).toEqual([ + "headline", + "headline", + "headline", + ]); + expect(new Set(mounts.map((element) => element.id)).size).toBe(3); + }); + + it("keeps a split inline-template mount on its template", () => { + const composition = source + .replace('id="box" class="clip"', 'id="box" class="clip" data-composition-id="headline"') + .replace( + "", + '', + ); + + const result = splitElementInHtml(composition, { id: "box" }, 3, "box-split"); + + expect(result.html).toMatch( + /id="box-split"[^>]*data-composition-id="headline"|data-composition-id="headline"[^>]*id="box-split"/, ); - expect(compositionIds).toHaveLength(4); - expect(new Set(compositionIds)).toHaveLength(4); - expect(compositionIds).toEqual(expect.arrayContaining(["root", "headline", "headline-split"])); }); it("returns matched false for out-of-range split time", () => { From 4e6ee6d2300290b638042ec88ef5afb7a0c27408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sat, 17 Oct 2026 00:52:55 +0000 Subject: [PATCH 04/36] fix(engine): a WebGPU block mounted as a sub-composition gets WebGPU like a root one (#5735) compositionRequiresWebGpu read only the first data-composition-id tag, the page root. In bundled HTML a mounted composition's root keeps data-requires-webgpu but carries data-hf-inner-root instead of a composition id, so a pasted-in WebGPU block launched without WebGPU and failed with 'WebGPU unavailable' even with PRODUCER_ALLOW_SOFTWARE_WEBGPU set. --- .../engine/src/services/browserManager.test.ts | 16 +++++++++++++++- packages/engine/src/services/browserManager.ts | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/engine/src/services/browserManager.test.ts b/packages/engine/src/services/browserManager.test.ts index 0c0476e9ff..8f51e83c8f 100644 --- a/packages/engine/src/services/browserManager.test.ts +++ b/packages/engine/src/services/browserManager.test.ts @@ -263,7 +263,21 @@ describe("compositionRequiresWebGpu", () => { ).toBe(false); }); - it("reads only the composition root tag and stays linear on repeated '<'", () => { + it("detects the marker on a mounted sub-composition's root in bundled HTML", () => { + expect( + compositionRequiresWebGpu( + '
' + + '
', + ), + ).toBe(true); + expect( + compositionRequiresWebGpu( + '
', + ), + ).toBe(false); + }); + + it("reads only composition root tags and stays linear on repeated '<'", () => { expect( compositionRequiresWebGpu('

'), ).toBe(false); diff --git a/packages/engine/src/services/browserManager.ts b/packages/engine/src/services/browserManager.ts index d347e7aacc..4952238161 100644 --- a/packages/engine/src/services/browserManager.ts +++ b/packages/engine/src/services/browserManager.ts @@ -1149,11 +1149,12 @@ export function buildChromeArgs(options: BuildChromeArgsOptions, config?: GpuCon return chromeArgs; } -/** Does the composition's root element declare `data-requires-webgpu`? */ +/** Does the root, or a mounted root (data-hf-inner-root once bundled), declare `data-requires-webgpu`? */ export function compositionRequiresWebGpu(html: string): boolean { for (const tag of scanHtmlOpeningTags(html)) { const names = tag.attributes.map((attribute) => attribute.name); - if (names.includes("data-composition-id")) return names.includes("data-requires-webgpu"); + const isRoot = names.includes("data-composition-id") || names.includes("data-hf-inner-root"); + if (isRoot && names.includes("data-requires-webgpu")) return true; } return false; } From eab6ca15b1af7ec7bca0bbeb4cd0330e677467a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sat, 17 Oct 2026 02:27:17 +0000 Subject: [PATCH 05/36] fix(cli): timeline lists clips nested in a timed element and lint flags ones that never show (#5732) * fix(cli): timeline lists clips nested in a timed element and lint flags ones that never show * docs(lint): wrap the nested-clip entries * docs(skills): format the nested-clip note and refresh the skills manifest * fix(cli): keep timeline edits from colliding with a clip's own wrapper * fix(cli): cut clips nested in a wrapper at their sub-composition's in-point * refactor(lint): split the nested-clip visibility checks to keep the audit green * style(cli): restore the timeline test's formatting --- docs/reference/lint-rules.mdx | 12 +++- .../cli/src/audio/analysis/targets.test.ts | 1 + packages/cli/src/timeline/a2Shared.ts | 15 +++++ .../timeline/describeProject.inPoint.test.ts | 15 ++++- .../cli/src/timeline/describeProject.test.ts | 38 ++++++++++++ packages/cli/src/timeline/describeProject.ts | 59 +++++++++++++++---- packages/cli/src/timeline/formatTimeline.ts | 10 +++- packages/cli/src/timeline/timeExpr.test.ts | 1 + .../cli/src/timeline/timeline.e2e.test.ts | 21 +++++++ .../lint/src/rules/structure.catalog.test.ts | 1 + packages/lint/src/rules/structure.test.ts | 24 ++++++++ packages/lint/src/rules/structure.ts | 43 ++++++++++++++ skills-manifest.json | 2 +- skills/hyperframes-core/SKILL.md | 3 + 14 files changed, 226 insertions(+), 19 deletions(-) diff --git a/docs/reference/lint-rules.mdx b/docs/reference/lint-rules.mdx index 4a099df1a4..150a7e3c26 100644 --- a/docs/reference/lint-rules.mdx +++ b/docs/reference/lint-rules.mdx @@ -20,7 +20,8 @@ Severities: Source: `packages/lint/src/rules/structure.ts`. -The four codes marked **Warning or error** are warnings when the CLI lints a project, and errors when Studio lints the file it is editing. +The five codes marked **Warning or error** are warnings when the CLI lints a project, and errors when Studio +lints the file it is editing. ### `nested_structure_needs_subcomposition` @@ -52,6 +53,15 @@ The four codes marked **Warning or error** are warnings when the CLI lints a pro **Fix:** Extend the root `data-duration`, or make the clip end at or before it. +### `nested_clip_never_visible` + +**Warning or error.** A timed clip sits inside another timed element, and its time window never overlaps that +element's, so it never appears. A nested clip's `data-start` counts from the composition's start, not from the +element around it. Runs in sub-composition files too. + +**Fix:** Give the clip a `data-start` inside its parent's window, in composition time, or move it out of the +parent. + ## Composition contract Source: `packages/lint/src/rules/composition.ts`. diff --git a/packages/cli/src/audio/analysis/targets.test.ts b/packages/cli/src/audio/analysis/targets.test.ts index cefc9b442f..1e02812ed2 100644 --- a/packages/cli/src/audio/analysis/targets.test.ts +++ b/packages/cli/src/audio/analysis/targets.test.ts @@ -20,6 +20,7 @@ function row( host: null, hostRow: null, children: [], + parentRow: null, trackIndex: 0, src: "audio/a.wav", sourceFile: null, diff --git a/packages/cli/src/timeline/a2Shared.ts b/packages/cli/src/timeline/a2Shared.ts index 44ddd5e6d2..44bab9d666 100644 --- a/packages/cli/src/timeline/a2Shared.ts +++ b/packages/cli/src/timeline/a2Shared.ts @@ -137,6 +137,19 @@ export function diff(before: string, after: string): string { return output.length <= 8_000 ? output : `${output.slice(0, 7_997)}...`; } +function isAncestorOf(ancestor: TimelineRow, row: TimelineRow, timeline: ProjectTimeline): boolean { + for (let pointer = row.parentRow; pointer; ) { + const parent = rowAt(timeline, pointer); + if (parent === ancestor) return true; + pointer = parent.parentRow; + } + return false; +} + +function sameLineage(a: TimelineRow, b: TimelineRow, timeline: ProjectTimeline): boolean { + return isAncestorOf(a, b, timeline) || isAncestorOf(b, a, timeline); +} + function overlap( row: TimelineRow, timeline: ProjectTimeline, @@ -146,6 +159,7 @@ function overlap( return allRows(timeline).find( (candidate) => candidate !== row && + !sameLineage(candidate, row, timeline) && candidate.file === row.file && candidate.trackIndex === row.trackIndex && spansShareTime(start, end, candidate.start, candidate.end), @@ -429,6 +443,7 @@ export function mutationConflict( if (verb === "duplicate") { const conflict = allRows(timeline).find( (candidate) => + !sameLineage(candidate, row, timeline) && candidate.file === row.file && candidate.trackIndex === row.trackIndex && isInsideSpan(nextStart, candidate.start, candidate.end), diff --git a/packages/cli/src/timeline/describeProject.inPoint.test.ts b/packages/cli/src/timeline/describeProject.inPoint.test.ts index 1caf194d04..79b95c3cd1 100644 --- a/packages/cli/src/timeline/describeProject.inPoint.test.ts +++ b/packages/cli/src/timeline/describeProject.inPoint.test.ts @@ -18,12 +18,12 @@ const SCENE = `