Skip to content

Write HTML. Render video. Built for agents.

fix(core): catch PostCSS parse errors instead of dropping compositions (#3589)

miga-heygen1a788d62e7fc
diff --git a/packages/core/src/compiler/compositionScoping.test.ts b/packages/core/src/compiler/compositionScoping.test.ts
index 7ba39a5fbc..80a63c059f 100644
--- a/packages/core/src/compiler/compositionScoping.test.ts
+++ b/packages/core/src/compiler/compositionScoping.test.ts
@@ -1054,4 +1054,13 @@ describe("wrapInlineScriptWithErrorBoundary — <script> breakout", () => {
expect(body).not.toContain("</script");
expect(scriptsAfterRoundTrip(body)).toHaveLength(1);
});
+
+ it("drops the entire stylesheet when PostCSS cannot parse it", () => {
+ const malformedCss = `body { margin: 0; overflow: hidden; }
+:root { --accent: #5ef17c; }
+.stage { position: absolute; inset: 0; }
+.broken { transform: xPercent: -10; }`;
+ const result = scopeCssToComposition(malformedCss, "scene-bad");
+ expect(result).toBe("");
+ });
});
diff --git a/packages/core/src/compiler/compositionScoping.ts b/packages/core/src/compiler/compositionScoping.ts
index c1fc996200..2ae8d9ee7b 100644
--- a/packages/core/src/compiler/compositionScoping.ts
+++ b/packages/core/src/compiler/compositionScoping.ts
@@ -230,7 +230,12 @@ export function scopeCssToComposition(
const scope =
scopeSelectorOverride ||
`[data-composition-id="${escapeCssAttributeValue(trimmedCompositionId)}"]`;
- const root = postcss.parse(css);
+ let root: postcss.Root;
+ try {
+ root = postcss.parse(css);
+ } catch {
+ return "";
+ }
root.walkRules((rule) => {
if (isInsideGlobalAtRule(rule)) return;
diff --git a/packages/lint/src/rules/core.test.ts b/packages/lint/src/rules/core.test.ts
index b0b870d80e..1bc0a21e8a 100644
--- a/packages/lint/src/rules/core.test.ts
+++ b/packages/lint/src/rules/core.test.ts
@@ -777,4 +777,20 @@ describe("core rules", () => {
expect(result.findings.find((f) => f.code === "timeline_id_mismatch")).toBeDefined();
});
});
+
+ describe("css_parse_error — malformed CSS is reported instead of silently swallowed", () => {
+ it("reports a css_parse_error finding for unparseable CSS", async () => {
+ const html = `<html><body>
+ <style>.stage { transform: xPercent: -10; }</style>
+ <div data-composition-id="main" data-width="1920" data-height="1080" data-start="0" data-duration="5"></div>
+ <script src="gsap.min.js"></script>
+ <script>window.__timelines = { main: gsap.timeline({ paused: true }) };</script>
+ </body></html>`;
+ const result = await lintHyperframeHtml(html);
+ const finding = result.findings.find((f) => f.code === "css_parse_error");
+ expect(finding).toBeDefined();
+ expect(finding?.severity).toBe("error");
+ expect(finding?.message).toContain("Missed semicolon");
+ });
+ });
});
diff --git a/packages/lint/src/rules/core.ts b/packages/lint/src/rules/core.ts
index 3461a59422..8d784da2ff 100644
--- a/packages/lint/src/rules/core.ts
+++ b/packages/lint/src/rules/core.ts
@@ -312,7 +312,12 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [
let root: postcss.Root;
try {
root = postcss.parse(style.content);
- } catch {
+ } catch (error) {
+ findings.push({
+ code: "css_parse_error",
+ severity: "error",
+ message: `CSS parse error: ${error instanceof Error ? error.message : "unknown"}`,
+ });
continue;
}
root.walkRules((rule) => {