Skip to content

Write HTML. Render video. Built for agents.

fix(core): a runtime failure just before start-up is named too (#5444)

Miguel Ángel721ebeafaa30
diff --git a/packages/core/src/runtime/entry.startupFailure.test.ts b/packages/core/src/runtime/entry.startupFailure.test.ts
index bb40776332..5d39ad1ad9 100644
--- a/packages/core/src/runtime/entry.startupFailure.test.ts
+++ b/packages/core/src/runtime/entry.startupFailure.test.ts
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import type { RuntimeTimelineLike } from "./types";
+import { AFTER_FONTS_SCRIPT_TYPE } from "../compiler/scriptRuns";
// Its own file: a start-up that throws never installs its teardown, so what it started would leak into later tests.
async function evaluateRuntime(): Promise<void> {
@@ -29,6 +30,8 @@ describe("runtime start-up failure", () => {
vi.doUnmock("./init");
vi.doUnmock("./clipTree");
vi.doUnmock("./timeline");
+ vi.doUnmock("../compiler/svgSelectorAliases");
+ vi.doUnmock("./afterFonts");
document.body.innerHTML = "";
window.__timelines = {};
delete window.__renderReady;
@@ -39,6 +42,32 @@ describe("runtime start-up failure", () => {
.__hyperframeRuntimeBootstrapped;
});
+ it("records a named error when the step before runtime start-up throws", async () => {
+ vi.doMock("../compiler/svgSelectorAliases", () => ({
+ refreshSvgSelectorAliases: () => {
+ throw new Error("aliases");
+ },
+ }));
+
+ await expect(evaluateRuntime()).rejects.toThrow("aliases");
+ expect(window.__hfStartupError).toContain("HyperFrames runtime failed: Error: aliases");
+ });
+
+ it("records a named error when running the font-gated scripts fails", async () => {
+ document.body.innerHTML = `<script type="${AFTER_FONTS_SCRIPT_TYPE}"></script>`;
+ const failed = Promise.reject(new Error("after fonts"));
+ failed.catch(() => {});
+ vi.doMock("./afterFonts", () => ({ runScriptsAfterFonts: () => failed }));
+ const reportError = vi.fn();
+ vi.stubGlobal("reportError", reportError);
+
+ await evaluateRuntime();
+ await vi.waitFor(() =>
+ expect(window.__hfStartupError).toContain("HyperFrames runtime failed: Error: after fonts"),
+ );
+ expect(reportError).toHaveBeenCalledWith(expect.objectContaining({ message: "after fonts" }));
+ });
+
it("records a named start-up error when runtime start-up throws", async () => {
vi.doMock("./init", async (importOriginal) => ({
...(await importOriginal<typeof import("./init")>()),
diff --git a/packages/core/src/runtime/entry.ts b/packages/core/src/runtime/entry.ts
index bdbf4782f2..6f34c13baf 100644
--- a/packages/core/src/runtime/entry.ts
+++ b/packages/core/src/runtime/entry.ts
@@ -69,22 +69,27 @@ function bootstrapHyperframeRuntime(): void {
return;
}
win.__hyperframeRuntimeBootstrapped = true;
+ initSandboxRuntimeModular();
+}
+
+// Compiled composition scripts wait for web fonts, so what they measure matches every run.
+function startAfterCompositionScripts(): void {
try {
- initSandboxRuntimeModular();
+ refreshSvgSelectorAliases();
+ const deferred = Array.from(document.querySelectorAll(AFTER_FONTS_SCRIPTS));
+ if (deferred.length === 0) bootstrapHyperframeRuntime();
+ else {
+ void runScriptsAfterFonts(deferred, bootstrapHyperframeRuntime).catch((err: unknown) => {
+ recordStartupError(err);
+ reportError(err);
+ });
+ }
} catch (err) {
recordStartupError(err);
throw err;
}
}
-// Compiled composition scripts wait for web fonts, so what they measure matches every run.
-function startAfterCompositionScripts(): void {
- refreshSvgSelectorAliases();
- const deferred = Array.from(document.querySelectorAll(AFTER_FONTS_SCRIPTS));
- if (deferred.length === 0) bootstrapHyperframeRuntime();
- else void runScriptsAfterFonts(deferred, bootstrapHyperframeRuntime);
-}
-
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", startAfterCompositionScripts, { once: true });
} else {