fix(producer): raise the sub-composition expansion limit to 64 MB (#8096)

* fix(producer): raise the sub-composition expansion limit to 64 MB

A render may now inline up to 64 MB of composition HTML across its mounts,
four times the 16 MB per-file limit, so a project with several large
distinct scenes is no longer refused.

* test(producer): size the generated-output tests from the expansion limit
This commit is contained in:
Michael Wang
2026-11-18 23:49:15 +00:00
committed by GitHub
parent 4be5ba2aad
commit 4d17b71b4d
3 changed files with 22 additions and 8 deletions
+1 -1
View File
@@ -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.
<Tip>
Always watch the exported file itself. Preview proves that the project can play; the output file
@@ -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 {
@@ -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 = `<script>window.n = (window.n || 0) + 1;</script>`.repeat(3_000);
const scripts = `<script>window.n = (window.n || 0) + 1;</script>`.repeat(
Math.ceil(MAX_EXPANDED_COMPOSITION_BYTES / 10_000),
);
const dir = project({
"index.html": rootMounting("scene.html", 1),
"scene.html": SCENE.replace("<h1>Scene</h1>", `<h1>Scene</h1>${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("<html>", "<html><head></head>").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("<html>", "<html><head></head>"),
"scene.html": SCENE.replace("<h1>Scene</h1>", `<style>${sheet}</style><h1>Scene</h1>`),