fix(bootstrap): show the boot error shell when the app graph fails to evaluate (09-03)
A module that threw while evaluating stopped main.tsx before boot() ran, so the static loading shell stayed up. The entry now imports the app (boot.tsx) dynamically and renders the shell on rejection; the shell reads boot messages without the feature catalog. The preload helper gets its own chunk so lazy chunks do not import the per-build entry, and the bundle budget counts the entry's dynamic imports as initial JS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e215c849fb
commit
9c8a5f417a
@@ -0,0 +1,59 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
import { recordBootFailure } from "../adapters/diagnostics/index.ts";
|
||||
import { BootErrorShell } from "../presentation/boundaries/boot-error-shell.tsx";
|
||||
import {
|
||||
createBootReleaseRecovery,
|
||||
decideBootFailure,
|
||||
} from "./boot-release-recovery.ts";
|
||||
import { createRuntimeComposition } from "./create-runtime-composition.ts";
|
||||
import { initializeColorScheme } from "./initialize-color-scheme.ts";
|
||||
import { ReleaseManifestError } from "./load-release-manifest.ts";
|
||||
import { BootConfigError } from "./load-runtime-config.ts";
|
||||
import { RuntimeApplication } from "./runtime-application.tsx";
|
||||
|
||||
/**
|
||||
* The application boot. main.tsx imports this module dynamically, so a module
|
||||
* in this static graph that throws while it evaluates rejects that import and
|
||||
* main.tsx shows the failure (09-03). Failures after evaluation are handled
|
||||
* here.
|
||||
*/
|
||||
const rootElement = document.getElementById("root");
|
||||
|
||||
if (!rootElement) {
|
||||
throw new Error("Missing #root mount element");
|
||||
}
|
||||
|
||||
const root = createRoot(rootElement);
|
||||
|
||||
async function boot(): Promise<void> {
|
||||
const releaseRecovery = createBootReleaseRecovery();
|
||||
try {
|
||||
const composition = await createRuntimeComposition();
|
||||
// A coherent boot clears any reload-once marker from a previous mismatch.
|
||||
releaseRecovery.markCoherentBoot();
|
||||
document.documentElement.dataset.buildId = composition.release.buildId;
|
||||
document.documentElement.dataset.releaseId = composition.release.releaseId;
|
||||
initializeColorScheme(composition.application.preferences);
|
||||
root.render(<RuntimeApplication composition={composition} />);
|
||||
import.meta.hot?.dispose(() => {
|
||||
void composition.dispose();
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
const safe =
|
||||
error instanceof BootConfigError || error instanceof ReleaseManifestError
|
||||
? error.safe
|
||||
: { supportReference: "boot:unknown" };
|
||||
|
||||
recordBootFailure(error, safe);
|
||||
// Spec §45. A rolling-release mismatch gets exactly one fresh navigation
|
||||
// (HTML is revalidated); a repeat of the same mismatch fails closed.
|
||||
if (decideBootFailure(error, releaseRecovery) === "reload-once") {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
root.render(<BootErrorShell {...safe} />);
|
||||
}
|
||||
}
|
||||
|
||||
void boot();
|
||||
+15
-52
@@ -1,54 +1,17 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
import { recordBootFailure } from "../adapters/diagnostics/index.ts";
|
||||
import { BootErrorShell } from "../presentation/boundaries/boot-error-shell.tsx";
|
||||
import "../presentation/styles/theme.css";
|
||||
import {
|
||||
createBootReleaseRecovery,
|
||||
decideBootFailure,
|
||||
} from "./boot-release-recovery.ts";
|
||||
import { createRuntimeComposition } from "./create-runtime-composition.ts";
|
||||
import { initializeColorScheme } from "./initialize-color-scheme.ts";
|
||||
import { ReleaseManifestError } from "./load-release-manifest.ts";
|
||||
import { BootConfigError } from "./load-runtime-config.ts";
|
||||
import { RuntimeApplication } from "./runtime-application.tsx";
|
||||
|
||||
const rootElement = document.getElementById("root");
|
||||
|
||||
if (!rootElement) {
|
||||
throw new Error("Missing #root mount element");
|
||||
}
|
||||
|
||||
const root = createRoot(rootElement);
|
||||
|
||||
async function boot(): Promise<void> {
|
||||
const releaseRecovery = createBootReleaseRecovery();
|
||||
try {
|
||||
const composition = await createRuntimeComposition();
|
||||
// A coherent boot clears any reload-once marker from a previous mismatch.
|
||||
releaseRecovery.markCoherentBoot();
|
||||
document.documentElement.dataset.buildId = composition.release.buildId;
|
||||
document.documentElement.dataset.releaseId = composition.release.releaseId;
|
||||
initializeColorScheme(composition.application.preferences);
|
||||
root.render(<RuntimeApplication composition={composition} />);
|
||||
import.meta.hot?.dispose(() => {
|
||||
void composition.dispose();
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
const safe =
|
||||
error instanceof BootConfigError || error instanceof ReleaseManifestError
|
||||
? error.safe
|
||||
: { supportReference: "boot:unknown" };
|
||||
|
||||
recordBootFailure(error, safe);
|
||||
// Spec §45. A rolling-release mismatch gets exactly one fresh navigation
|
||||
// (HTML is revalidated); a repeat of the same mismatch fails closed.
|
||||
if (decideBootFailure(error, releaseRecovery) === "reload-once") {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
root.render(<BootErrorShell {...safe} />);
|
||||
}
|
||||
}
|
||||
|
||||
void boot();
|
||||
/**
|
||||
* 09-03. The entry imports the application graph dynamically. A module in it
|
||||
* that throws while it evaluates (a duplicate message key, a route or
|
||||
* operation conflict) used to stop the entry before any handler ran, leaving
|
||||
* the static loading shell up. Now it rejects this import and the failure is
|
||||
* shown.
|
||||
*
|
||||
* The entry stays free of anything the application graph also imports (no
|
||||
* JSX, no React): whatever it hosted, every chunk would import from it, and
|
||||
* the entry's hash changes with every build id.
|
||||
*/
|
||||
void import("./boot.tsx").catch(async (error: unknown) => {
|
||||
const { renderBootFailure } = await import("./render-boot-failure.tsx");
|
||||
renderBootFailure(error);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
import { recordBootFailure } from "../adapters/diagnostics/index.ts";
|
||||
import { BootErrorShell } from "../presentation/boundaries/boot-error-shell.tsx";
|
||||
|
||||
/**
|
||||
* 09-03. Renders the boot failure when the application graph (boot.tsx) could
|
||||
* not even be evaluated. Nothing here reaches the installed feature graph, so
|
||||
* it still loads when that graph throws.
|
||||
*/
|
||||
export function renderBootFailure(error: unknown): void {
|
||||
const safe = { supportReference: "boot:unknown" };
|
||||
recordBootFailure(error, safe);
|
||||
const rootElement = document.getElementById("root");
|
||||
if (!rootElement) throw error;
|
||||
createRoot(rootElement).render(<BootErrorShell {...safe} />);
|
||||
}
|
||||
Reference in New Issue
Block a user