Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ui): a rebuilt bundle no longer reads as a crash in whichever section is open

rubenluetke10-beep9b3c41652b52
diff --git a/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.test.tsx b/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.test.tsx
new file mode 100644
index 0000000000..8b67b82f91
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.test.tsx
@@ -0,0 +1,99 @@
+/**
+ * A rebuilt bundle is not a crash, and the card has to say so.
+ *
+ * The live report (2026-08-23): opening the Wiki section after the frontend
+ * had been rebuilt under the open window produced a red crash card reading
+ * "Cannot read properties of undefined (reading 'WikiGraph')". Nothing was
+ * wrong with the wiki — the window was asking for a chunk that no longer
+ * existed. These tests pin the two halves of telling those apart: what the
+ * user is shown, and what the button does.
+ */
+import { fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { ViewErrorBoundary } from "./ViewErrorBoundary";
+
+const reloadWhenServable = vi.fn();
+
+vi.mock("@/lib/safeReload", () => ({
+ reloadWhenServable: (...args: unknown[]) => reloadWhenServable(...args),
+ browserSafeReloadDeps: () => ({}),
+}));
+
+function Boom({ message }: { message: string }): JSX.Element {
+ throw new Error(message);
+}
+
+const STALE_CHUNK =
+ "Failed to fetch dynamically imported module: " +
+ "http://127.0.0.1:47821/assets/WikiGraph-ZXJsF_pi.js";
+
+function renderCrash(message: string) {
+ const onRecover = vi.fn();
+ // React logs every caught error; the noise is not what is under test.
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
+ const consoleInfo = vi.spyOn(console, "info").mockImplementation(() => {});
+ render(
+ <ViewErrorBoundary viewName="memory" resetKey="memory" onRecover={onRecover}>
+ <Boom message={message} />
+ </ViewErrorBoundary>,
+ );
+ return { onRecover, consoleError, consoleInfo };
+}
+
+afterEach(() => {
+ vi.restoreAllMocks();
+ reloadWhenServable.mockClear();
+});
+
+describe("ViewErrorBoundary", () => {
+ it("offers a reload — not 'back to chats' — when the chunk is stale", () => {
+ const { onRecover } = renderCrash(STALE_CHUNK);
+
+ const buttons = screen.getAllByRole("button");
+ expect(buttons).toHaveLength(1);
+ fireEvent.click(buttons[0]);
+
+ expect(reloadWhenServable).toHaveBeenCalledTimes(1);
+ expect(onRecover).not.toHaveBeenCalled();
+ });
+
+ it("never shows the raw engine message for a stale chunk", () => {
+ // "Failed to fetch dynamically imported module: …WikiGraph-ZXJsF_pi.js"
+ // tells the user nothing they can act on and reads as a broken section.
+ renderCrash(STALE_CHUNK);
+
+ expect(screen.queryByText(/WikiGraph/)).toBeNull();
+ expect(screen.queryByText(/dynamically imported/i)).toBeNull();
+ });
+
+ it("does not log a stale chunk as a crash", () => {
+ // A rebuild is routine. Reporting it at error level is what made a normal
+ // `npm run build` look like a fault in whichever section was open.
+ const { consoleError } = renderCrash(STALE_CHUNK);
+
+ const ours = consoleError.mock.calls.filter(
+ (call) => call[0] === "Jarvis view crashed",
+ );
+ expect(ours).toHaveLength(0);
+ });
+
+ it("still reports a genuine component bug, with its message and recovery", () => {
+ const { onRecover, consoleError } = renderCrash(
+ "Cannot read properties of undefined (reading 'nodes')",
+ );
+
+ expect(screen.getByText(/reading 'nodes'/)).toBeTruthy();
+
+ fireEvent.click(screen.getAllByRole("button")[0]);
+ expect(onRecover).toHaveBeenCalledTimes(1);
+ expect(reloadWhenServable).not.toHaveBeenCalled();
+
+ // React re-renders a failing tree once more to build a better stack, so
+ // the boundary legitimately catches twice. What matters is that it logged.
+ const ours = consoleError.mock.calls.filter(
+ (call) => call[0] === "Jarvis view crashed",
+ );
+ expect(ours.length).toBeGreaterThan(0);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.tsx b/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.tsx
index dc79e1c184..e5cd58d08c 100644
--- a/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.tsx
+++ b/jarvis/ui/web/frontend/src/components/ViewErrorBoundary.tsx
@@ -1,7 +1,10 @@
import { Component, type ErrorInfo, type ReactNode } from "react";
-import { AlertTriangle, RotateCcw } from "lucide-react";
+import { AlertTriangle, RefreshCw, RotateCcw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { translate } from "@/i18n";
+import { cn } from "@/lib/utils";
+import { isChunkLoadError } from "@/lib/preloadRecovery";
+import { browserSafeReloadDeps, reloadWhenServable } from "@/lib/safeReload";
import { useEventStore } from "@/store/events";
interface ViewErrorBoundaryProps {
@@ -14,6 +17,14 @@ interface ViewErrorBoundaryProps {
interface ViewErrorBoundaryState {
hasError: boolean;
message: string;
+ /**
+ * The crash was a lazy chunk that is no longer on disk, not a bug.
+ *
+ * A rebuild replaces every hashed chunk, so a window that was already open
+ * asks for files that have been deleted under it. Nothing is broken and
+ * nothing is worth reporting — the window simply has to fetch the new build.
+ */
+ stale: boolean;
resetKey: string;
}
@@ -24,6 +35,7 @@ export class ViewErrorBoundary extends Component<
state: ViewErrorBoundaryState = {
hasError: false,
message: "",
+ stale: false,
resetKey: this.props.resetKey,
};
@@ -31,6 +43,7 @@ export class ViewErrorBoundary extends Component<
return {
hasError: true,
message: error instanceof Error ? error.message : String(error),
+ stale: isChunkLoadError(error),
};
}
@@ -39,12 +52,27 @@ export class ViewErrorBoundary extends Component<
state: ViewErrorBoundaryState,
): Partial<ViewErrorBoundaryState> | null {
if (props.resetKey !== state.resetKey) {
- return { hasError: false, message: "", resetKey: props.resetKey };
+ return {
+ hasError: false,
+ message: "",
+ stale: false,
+ resetKey: props.resetKey,
+ };
}
return null;
}
componentDidCatch(error: unknown, info: ErrorInfo) {
+ if (isChunkLoadError(error)) {
+ // Expected during a rebuild, and the recovery is already under way.
+ // Logging it as a crash is what makes a routine rebuild look like a bug
+ // in whichever section the user happened to open.
+ console.info("Jarvis view is running an old bundle", {
+ view: this.props.viewName,
+ error,
+ });
+ return;
+ }
console.error("Jarvis view crashed", {
view: this.props.viewName,
error,
@@ -53,39 +81,98 @@ export class ViewErrorBoundary extends Component<
}
private recover = () => {
- this.setState({ hasError: false, message: "", resetKey: this.props.resetKey });
+ this.setState({
+ hasError: false,
+ message: "",
+ stale: false,
+ resetKey: this.props.resetKey,
+ });
this.props.onRecover();
};
+ /**
+ * Take the new build, once it is whole.
+ *
+ * The preload recovery spends one automatic reload per incident; a second
+ * failure inside its settle window lands here instead, which is why this
+ * button exists at all. It goes through `reloadWhenServable` for the same
+ * reason every other reload in this app does — reloading into a half-written
+ * `dist/` leaves a window with no JavaScript left to try again.
+ */
+ private reloadBundle = () => {
+ reloadWhenServable(browserSafeReloadDeps());
+ };
+
render() {
if (!this.state.hasError) return this.props.children;
+ // A stale chunk is a rebuild, not a fault: no destructive colour, no raw
+ // engine message, and an action that fixes the actual situation.
+ const stale = this.state.stale;
+
return (
<div className="flex h-full min-h-0 flex-col bg-background">
<div className="flex flex-1 items-center justify-center p-6">
- <div className="w-full max-w-xl rounded-lg border border-destructive/30 bg-card/80 p-5 shadow-xl">
+ <div
+ className={cn(
+ "w-full max-w-xl rounded-lg border bg-card/80 p-5 shadow-xl",
+ stale ? "border-border" : "border-destructive/30",
+ )}
+ >
<div className="flex items-start gap-3">
- <div className="rounded-md bg-destructive/10 p-2 text-destructive">
- <AlertTriangle className="h-5 w-5" />
+ <div
+ className={cn(
+ "rounded-md p-2",
+ stale
+ ? "bg-muted text-muted-foreground"
+ : "bg-destructive/10 text-destructive",
+ )}
+ >
+ {stale ? (
+ <RefreshCw className="h-5 w-5" />
+ ) : (
+ <AlertTriangle className="h-5 w-5" />
+ )}
</div>
<div className="min-w-0 flex-1">
<h2 className="font-display text-base font-semibold">
- {translate("view_error_boundary.title")}
+ {translate(
+ stale
+ ? "view_error_boundary.stale_title"
+ : "view_error_boundary.title",
+ )}
</h2>
- <p className="mt-1 text-sm text-muted-foreground">
- {this.props.viewName} {translate("view_error_boundary.crashed_prefix")}{" "}
- {useEventStore.getState().assistantName}{" "}
- {translate("view_error_boundary.crashed_suffix")}
- </p>
- {this.state.message && (
+ {stale ? (
+ <p className="mt-1 text-sm text-muted-foreground">
+ {translate("view_error_boundary.stale_hint")}
+ </p>
+ ) : (
+ <p className="mt-1 text-sm text-muted-foreground">
+ {this.props.viewName} {translate("view_error_boundary.crashed_prefix")}{" "}
+ {useEventStore.getState().assistantName}{" "}
+ {translate("view_error_boundary.crashed_suffix")}
+ </p>
+ )}
+ {!stale && this.state.message && (
<pre className="mt-3 max-h-32 overflow-auto rounded-md border border-border bg-background/80 p-3 text-xs text-muted-foreground">
{this.state.message}
</pre>
)}
- <Button className="mt-4" size="sm" onClick={this.recover}>
- <RotateCcw className="h-3.5 w-3.5" />
- <span className="ml-1.5">{translate("view_error_boundary.back_to_chats")}</span>
- </Button>
+ {stale ? (
+ <Button className="mt-4" size="sm" onClick={this.reloadBundle}>
+ <RefreshCw className="h-3.5 w-3.5" />
+ <span className="ml-1.5">
+ {translate("view_error_boundary.stale_action")}
+ </span>
+ </Button>
+ ) : (
+ <Button className="mt-4" size="sm" onClick={this.recover}>
+ <RotateCcw className="h-3.5 w-3.5" />
+ <span className="ml-1.5">
+ {translate("view_error_boundary.back_to_chats")}
+ </span>
+ </Button>
+ )}
</div>
</div>
</div>
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index c0013f355c..fd4497acb4 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -2446,6 +2446,9 @@
"back_to_chats": "Zurueck zu Chats",
"group_title": "Dieser Bereich konnte nicht geladen werden",
"group_hint": "Alle anderen Einstellungen auf dieser Seite funktionieren weiterhin.",
+ "stale_title": "Die Oberfläche wurde neu gebaut",
+ "stale_hint": "Dieses Fenster läuft noch auf der vorherigen Version. Neu laden holt die aktuelle.",
+ "stale_action": "Neu laden",
"group_retry": "Erneut versuchen"
},
"view_loading": {
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 4968b01084..99653ee531 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -2446,6 +2446,9 @@
"back_to_chats": "Back to Chats",
"group_title": "This section could not be loaded",
"group_hint": "Every other setting on this page still works.",
+ "stale_title": "The interface has been rebuilt",
+ "stale_hint": "This window is still running the previous version. Reloading picks up the current one.",
+ "stale_action": "Reload",
"group_retry": "Try again"
},
"view_loading": {
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 8fcf57dcee..6e9ed7c7a7 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -2446,6 +2446,9 @@
"back_to_chats": "Volver a los chats",
"group_title": "No se pudo cargar esta sección",
"group_hint": "El resto de los ajustes de esta página siguen funcionando.",
+ "stale_title": "La interfaz se ha vuelto a compilar",
+ "stale_hint": "Esta ventana sigue ejecutando la versión anterior. Al recargar se obtiene la actual.",
+ "stale_action": "Recargar",
"group_retry": "Intentar de nuevo"
},
"view_loading": {
diff --git a/jarvis/ui/web/frontend/src/lib/preloadRecovery.test.ts b/jarvis/ui/web/frontend/src/lib/preloadRecovery.test.ts
index cc79db7617..8c421e825e 100644
--- a/jarvis/ui/web/frontend/src/lib/preloadRecovery.test.ts
+++ b/jarvis/ui/web/frontend/src/lib/preloadRecovery.test.ts
@@ -15,6 +15,7 @@ import {
SETTLE_MS,
handlePreloadError,
installPreloadRecovery,
+ isChunkLoadError,
type PreloadRecoveryDeps,
} from "./preloadRecovery";
@@ -96,7 +97,7 @@ describe("preload recovery", () => {
expect(reload).toHaveBeenCalledTimes(1);
});
- it("listens for the preload error and keeps Vite from reloading on its own", () => {
+ it("listens for the preload error and reloads on it", () => {
const { deps, reload } = makeDeps();
const listeners: EventListener[] = [];
installPreloadRecovery(deps, {
@@ -108,10 +109,60 @@ describe("preload recovery", () => {
const preventDefault = vi.fn();
listeners[0]({ preventDefault } as unknown as Event);
- expect(preventDefault).toHaveBeenCalledTimes(1);
expect(reload).toHaveBeenCalledTimes(1);
});
+ it("NEVER cancels the event, so the failed import still rejects", () => {
+ // The regression this pins (2026-08-23): the listener cancelled the event
+ // unconditionally. Vite's preload helper is installed as
+ // `import(...).catch(handler)` and only rethrows when the event was not
+ // cancelled — so cancelling made every failed dynamic import RESOLVE WITH
+ // `undefined`. The caller's `.then((mod) => ({ default: mod.WikiGraph }))`
+ // then died as "Cannot read properties of undefined (reading
+ // 'WikiGraph')", which is how a rebuild during an open window was reported
+ // as a crash in the wiki system.
+ //
+ // Both passes matter: the one that reloads and the one the guard stops.
+ const { deps } = makeDeps();
+ const listeners: EventListener[] = [];
+ installPreloadRecovery(deps, {
+ addEventListener: ((_name: string, fn: EventListener) => {
+ listeners.push(fn);
+ }) as Window["addEventListener"],
+ });
+
+ const preventDefault = vi.fn();
+ listeners[0]({ preventDefault } as unknown as Event);
+ listeners[0]({ preventDefault } as unknown as Event);
+
+ expect(preventDefault).not.toHaveBeenCalled();
+ });
+
+ describe("isChunkLoadError", () => {
+ it.each([
+ // Chromium — the message the desktop WebView actually produces.
+ "Failed to fetch dynamically imported module: http://127.0.0.1:47821/assets/WikiGraph-ZXJsF_pi.js",
+ // Firefox.
+ "error loading dynamically imported module",
+ // WebKit.
+ "Importing a module script failed.",
+ // Vite's own preload helper.
+ "Unable to preload CSS for /assets/AgenticIdeView-CFbL2ovg.css",
+ ])("recognises %s", (message) => {
+ expect(isChunkLoadError(new Error(message))).toBe(true);
+ });
+
+ it("does not claim a real component bug is a stale chunk", () => {
+ expect(
+ isChunkLoadError(
+ new TypeError("Cannot read properties of undefined (reading 'nodes')"),
+ ),
+ ).toBe(false);
+ expect(isChunkLoadError(undefined)).toBe(false);
+ expect(isChunkLoadError("boom")).toBe(false);
+ });
+ });
+
it("never reloads when the guard cannot be remembered", () => {
// No storage means no way to bound a loop, so no loop is started.
const reload = vi.fn();
diff --git a/jarvis/ui/web/frontend/src/lib/preloadRecovery.ts b/jarvis/ui/web/frontend/src/lib/preloadRecovery.ts
index 0113460a63..3a8996a9fb 100644
--- a/jarvis/ui/web/frontend/src/lib/preloadRecovery.ts
+++ b/jarvis/ui/web/frontend/src/lib/preloadRecovery.ts
@@ -43,6 +43,34 @@ export const RELOAD_GUARD_KEY = "jarvis:preload-reloaded";
*/
export const SETTLE_MS = 30_000;
+/**
+ * Phrases every engine uses for "that chunk did not load".
+ *
+ * There is no error type to test — a failed dynamic import is a plain
+ * `TypeError` whose message is the only distinguishing mark, and each engine
+ * words it differently. Vite's own CSS preload failure is in here too, because
+ * it reaches a view through exactly the same import.
+ */
+const CHUNK_LOAD_PHRASES = [
+ "failed to fetch dynamically imported module", // Chromium
+ "error loading dynamically imported module", // Firefox
+ "importing a module script failed", // WebKit
+ "unable to preload css for", // Vite's own preload helper
+];
+
+/**
+ * Is this crash a chunk that is no longer on disk?
+ *
+ * Used by the view error boundary to tell "the app was rebuilt under this
+ * window" apart from a real component bug — the two need opposite messages,
+ * and only the first one heals by itself.
+ */
+export function isChunkLoadError(error: unknown): boolean {
+ const message = (error instanceof Error ? error.message : String(error ?? ""))
+ .toLowerCase();
+ return CHUNK_LOAD_PHRASES.some((phrase) => message.includes(phrase));
+}
+
export interface PreloadRecoveryDeps {
/** Where the one-reload-per-incident mark lives. Survives a reload. */
storage: Pick<Storage, "getItem" | "setItem" | "removeItem">;
@@ -94,10 +122,21 @@ export function installPreloadRecovery(
): void {
if (!target) return;
- target.addEventListener("vite:preloadError", ((event: Event) => {
- // Vite's default for an unhandled preload error is to reload the page
- // itself; preventing it keeps the decision here, where it is bounded.
- event.preventDefault();
+ target.addEventListener("vite:preloadError", ((_event: Event) => {
+ // The event is deliberately NOT cancelled.
+ //
+ // Vite does not reload on its own for a preload failure — its helper only
+ // rethrows the error unless the event is cancelled. Cancelling therefore
+ // buys nothing and costs the failure itself: the helper is installed as
+ // `import(...).catch(handler)`, so a handler that does not throw makes the
+ // dynamic import RESOLVE WITH `undefined`. The caller's
+ // `.then((mod) => ({ default: mod.WikiGraph }))` then dies as
+ // "Cannot read properties of undefined (reading 'WikiGraph')" — a message
+ // that points at the view instead of at the missing chunk, and the reason
+ // clicking Wiki during a rebuild reported as a crash in the wiki system.
+ //
+ // Letting the error travel keeps the view's error boundary honest while
+ // the reload below heals the window underneath it.
handlePreloadError(deps);
}) as EventListener);