diff --git a/docs/guides/rendering.mdx b/docs/guides/rendering.mdx index ac17405c4f..aab708f931 100644 --- a/docs/guides/rendering.mdx +++ b/docs/guides/rendering.mdx @@ -416,7 +416,7 @@ Keep the first exact error rather than only the final “render failed” messag A render refuses any composition HTML file, the entry or a sub-composition, that is larger than 16 MB. The error code is `COMPOSITION_TOO_LARGE`. Keep images, fonts and data in separate files and reference them by path instead of inlining them. -The same error refuses a render whose sub-composition mounts add up to more than 32 MB of composition HTML, or to more than 10,000 mounts. Every mount counts, including each repeat of the same file and each mount nested inside another. The scripts and scoped styles generated for those mounts have their own 32 MB limit. Every inline script in a mounted file is wrapped in a few kilobytes of scoping code, and every style rule is prefixed with its host's `data-composition-id`. Many tiny inline scripts, or a long composition id over many style rules, can reach this limit. Merge small scripts and rules, or keep ids short. +The same error refuses a render whose sub-composition mounts add up to more than 64 MB of composition HTML, or to more than 10,000 mounts. Every mount counts, including each repeat of the same file and each mount nested inside another. The scripts and scoped styles generated for those mounts have their own 64 MB limit. Every inline script in a mounted file is wrapped in a few kilobytes of scoping code, and every style rule is prefixed with its host's `data-composition-id`. Many tiny inline scripts, or a long composition id over many style rules, can reach this limit. Merge small scripts and rules, or keep ids short. Always watch the exported file itself. Preview proves that the project can play; the output file diff --git a/packages/producer/src/services/compositionSizeLimit.ts b/packages/producer/src/services/compositionSizeLimit.ts index 9e859481f1..e35c4892cc 100644 --- a/packages/producer/src/services/compositionSizeLimit.ts +++ b/packages/producer/src/services/compositionSizeLimit.ts @@ -15,7 +15,7 @@ const megabytes = (bytes: number) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`; * What one render may inline across every sub-composition mount. Each file is checked on its own * above, but a few small files that mount each other many times assemble a page far larger. */ -export const MAX_EXPANDED_COMPOSITION_BYTES = 2 * MAX_COMPOSITION_HTML_BYTES; +export const MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES; const MAX_COMPOSITION_MOUNTS = 10_000; class CompositionTooLargeError extends Error { diff --git a/packages/producer/src/services/htmlCompiler.sizeLimit.test.ts b/packages/producer/src/services/htmlCompiler.sizeLimit.test.ts index 21927d6338..067c88818e 100644 --- a/packages/producer/src/services/htmlCompiler.sizeLimit.test.ts +++ b/packages/producer/src/services/htmlCompiler.sizeLimit.test.ts @@ -6,6 +6,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { _setDownloadFetchForTests } from "@hyperframes/engine"; import { assertCompositionFileSize, + CompositionExpansionBudget, MAX_COMPOSITION_HTML_BYTES, MAX_EXPANDED_COMPOSITION_BYTES, } from "./compositionSizeLimit.js"; @@ -132,15 +133,23 @@ describe("composition expansion budget", () => { }, ); + it("allows 64 MB of mounted HTML and refuses one byte more", () => { + expect(MAX_EXPANDED_COMPOSITION_BYTES).toBe(64 * 1024 * 1024); + const budget = new CompositionExpansionBudget(); + for (let i = 0; i < 4; i += 1) budget.charge("scene.html", MAX_COMPOSITION_HTML_BYTES); + expect(() => budget.charge("scene.html", 1)).toThrow(/64\.0 MB of composition HTML/); + }); + it("refuses one large file mounted many times", async () => { - const big = Math.ceil(MAX_EXPANDED_COMPOSITION_BYTES / 4) + 1; + const big = Math.ceil(MAX_EXPANDED_COMPOSITION_BYTES / 5) + 1; const dir = project({ - "index.html": rootMounting("scene.html", 4), + "index.html": rootMounting("scene.html", 5), "scene.html": paddedTo(SCENE, big), }); const error = await compileError(dir); expect(extractSafeRenderErrorCode(error)).toBe("COMPOSITION_TOO_LARGE"); expect(String(error)).toContain('"scene.html"'); + expect(error).toMatchObject({ publicMetadata: { exceeded: "bytes" } }); }); it("leaves a missing mount inside a template to the inliner's warning, as before", async () => { @@ -163,7 +172,9 @@ describe("composition expansion budget", () => { }); it("refuses a mount whose tiny scripts would each be wrapped in kilobytes of scoping code", async () => { - const scripts = ``.repeat(3_000); + const scripts = ``.repeat( + Math.ceil(MAX_EXPANDED_COMPOSITION_BYTES / 10_000), + ); const dir = project({ "index.html": rootMounting("scene.html", 1), "scene.html": SCENE.replace("

Scene

", `

Scene

${scripts}`), @@ -178,7 +189,8 @@ describe("composition expansion budget", () => { it("refuses a long host id over many style rules before building the scoped sheet", async () => { const id = `s${"x".repeat(20_000)}`; - const rules = Array.from({ length: 2_000 }, (_, i) => `.r${i}{color:red}`).join(""); + const count = Math.ceil((2 * MAX_EXPANDED_COMPOSITION_BYTES) / id.length); + const rules = Array.from({ length: count }, (_, i) => `.r${i}{color:red}`).join(""); const dir = project({ "index.html": ROOT.replace("", "").replace( 'data-composition-id="scene"', @@ -195,8 +207,10 @@ describe("composition expansion budget", () => { }); it("reserves the separator a scoped selector list is re-joined with", async () => { - const selectors = Array.from({ length: 2_000 }, (_, i) => `.r${i}`).join(","); - const sheet = `.first,${" ".repeat(20_000)}${selectors}{color:red}`; + const gap = " ".repeat(20_000); + const count = Math.ceil((2 * MAX_EXPANDED_COMPOSITION_BYTES) / gap.length); + const selectors = Array.from({ length: count }, (_, i) => `.r${i}`).join(","); + const sheet = `.first,${gap}${selectors}{color:red}`; const dir = project({ "index.html": ROOT.replace("", ""), "scene.html": SCENE.replace("

Scene

", `

Scene

`),