diff --git a/packages/cli/src/server/studioServer.previewAssets.test.ts b/packages/cli/src/server/studioServer.previewAssets.test.ts index 14f6cb4151..6a3fa7071c 100644 --- a/packages/cli/src/server/studioServer.previewAssets.test.ts +++ b/packages/cli/src/server/studioServer.previewAssets.test.ts @@ -66,8 +66,11 @@ describe("studio preview document", () => { // Kept URLs resolve against the preview's through the asset route. expect(html).toContain(''); expect(await fetchAsset("assets/pic.png")).toEqual(PIC); - const nested = html.match(/]*id="nested" src="([^"]+)"/)?.[1]; - expect(nested).toBe("assets/pic@2x.png"); - expect(await fetchAsset(nested ?? "")).toEqual(PIC_2X); + // Scenes stay separate files the runtime fetches, so the first scene can play before the rest. + expect(html).toContain('data-composition-src="compositions/scene.html"'); + expect(html).not.toContain('id="nested"'); + const scene = (await fetchAsset("compositions/scene.html")).toString("utf-8"); + expect(scene.match(/]*id="nested" src="([^"]+)"/)?.[1]).toBe("../assets/pic@2x.png"); + expect(await fetchAsset("assets/pic@2x.png")).toEqual(PIC_2X); }); }); diff --git a/packages/core/src/compiler/htmlBundler.test.ts b/packages/core/src/compiler/htmlBundler.test.ts index 119f7422a5..2af570a759 100644 --- a/packages/core/src/compiler/htmlBundler.test.ts +++ b/packages/core/src/compiler/htmlBundler.test.ts @@ -420,6 +420,32 @@ describe("bundleToSingleHtml", () => { expect(hostEl?.hasAttribute("data-composition-src")).toBe(false); }); + it("leaves sub-composition hosts for the runtime to fetch with subCompositions: external", async () => { + const dir = makeTempProject({ + "index.html": ` + +
+
+
+`, + "compositions/scene.html": ``, + }); + + const external = parseHTML( + await bundleToSingleHtml(dir, { subCompositions: "external" }), + ).document; + const host = external.getElementById("scene-host"); + expect(host?.getAttribute("data-composition-src")).toBe("compositions/scene.html"); + expect(host?.getAttribute("data-start")).toBe("2"); + expect(external.getElementById("scene-content")).toBeNull(); + + const inlined = parseHTML(await bundleToSingleHtml(dir)).document; + expect(inlined.getElementById("scene-content")).not.toBeNull(); + }); + it("inlines local scripts referenced by sub-compositions into the bundle", async () => { const dir = makeTempProject({ "index.html": ` diff --git a/packages/core/src/compiler/htmlBundler.ts b/packages/core/src/compiler/htmlBundler.ts index 0b6d6ffe45..d4a794dc14 100644 --- a/packages/core/src/compiler/htmlBundler.ts +++ b/packages/core/src/compiler/htmlBundler.ts @@ -780,6 +780,11 @@ export interface BundleOptions { * modes and emits `