Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: a failed Halloween reveal closes and leaves the other decorations running; a Night Shift frame that throws is logged and the panel clears

aashucf9c00e7bded
diff --git a/packages/react/src/Halloween/Decorations.tsx b/packages/react/src/Halloween/Decorations.tsx
index f0d06414ee..e1e3648070 100644
--- a/packages/react/src/Halloween/Decorations.tsx
+++ b/packages/react/src/Halloween/Decorations.tsx
@@ -9,6 +9,7 @@ import { createPortal } from "react-dom";
import { BarSpider } from "./BarSpider";
import { BooGhost } from "./Ghost";
import { HalloweenStyles } from "./HalloweenStyles";
+import { Optional } from "./Optional";
import { BatFlyby, SuccessBats } from "./Visitors";
// The app shell's decorations. Its own chunk, loaded by `HalloweenLayer` only
@@ -47,9 +48,12 @@ export default function Decorations() {
<BooGhost />
<AnimatePresence>
{revealOpen && (
- <Suspense key="halloween-reveal" fallback={null}>
- <HalloweenReveal onClose={close} />
- </Suspense>
+ // Its own net: a failed reveal closes, and the rest keep running.
+ <Optional key="halloween-reveal" onError={close}>
+ <Suspense fallback={null}>
+ <HalloweenReveal onClose={close} />
+ </Suspense>
+ </Optional>
)}
</AnimatePresence>
</>
diff --git a/packages/react/src/Halloween/HalloweenLayer.tsx b/packages/react/src/Halloween/HalloweenLayer.tsx
index efb546695e..08a5331f24 100644
--- a/packages/react/src/Halloween/HalloweenLayer.tsx
+++ b/packages/react/src/Halloween/HalloweenLayer.tsx
@@ -2,13 +2,10 @@
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
-import { getLogger } from "@carbon/logger";
-import type { ReactNode } from "react";
-import { Component, lazy, Suspense, useEffect, useRef, useState } from "react";
+import { lazy, Suspense, useEffect, useRef, useState } from "react";
+import { Optional } from "./Optional";
import { useHalloween } from "./season";
-const log = getLogger("react", "halloween");
-
// Seasonal decoration, shared by the ERP and the MES (`@carbon/react/Halloween`).
// Everything renders only on Halloween, when the theme is on for everyone
// (`useHalloween`, season.ts); on any other day this returns nothing. The
@@ -101,23 +98,3 @@ function LoginArt() {
</div>
);
}
-
-/**
- * Renders nothing once a decoration throws or its chunk fails to load, so a
- * broken decoration never takes the app shell or the sign-in page down.
- */
-class Optional extends Component<{ children: ReactNode }, { failed: boolean }> {
- state = { failed: false };
-
- static getDerivedStateFromError() {
- return { failed: true };
- }
-
- componentDidCatch(error: unknown) {
- log.error("Halloween decoration failed", { error });
- }
-
- render() {
- return this.state.failed ? null : this.props.children;
- }
-}
diff --git a/packages/react/src/Halloween/Optional.tsx b/packages/react/src/Halloween/Optional.tsx
new file mode 100644
index 0000000000..87332bae9d
--- /dev/null
+++ b/packages/react/src/Halloween/Optional.tsx
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import { getLogger } from "@carbon/logger";
+import type { ReactNode } from "react";
+import { Component } from "react";
+
+const log = getLogger("react", "halloween");
+
+/**
+ * Renders nothing once a decoration throws or its chunk fails to load, so a
+ * broken decoration never takes the app shell or the sign-in page down.
+ * `onError` lets the owner undo what showing it changed.
+ */
+export class Optional extends Component<
+ { children: ReactNode; onError?: () => void },
+ { failed: boolean }
+> {
+ state = { failed: false };
+
+ static getDerivedStateFromError() {
+ return { failed: true };
+ }
+
+ componentDidCatch(error: unknown) {
+ log.error("Halloween decoration failed", { error });
+ this.props.onError?.();
+ }
+
+ render() {
+ return this.state.failed ? null : this.props.children;
+ }
+}
diff --git a/packages/react/src/Halloween/night-shift/NightShift.tsx b/packages/react/src/Halloween/night-shift/NightShift.tsx
index 577109bab4..e092dc62d6 100644
--- a/packages/react/src/Halloween/night-shift/NightShift.tsx
+++ b/packages/react/src/Halloween/night-shift/NightShift.tsx
@@ -9,7 +9,7 @@
// browser session, so the hill keeps the lanterns it has earned.
import { useLingui } from "@lingui/react/macro";
-import { useEffect, useRef } from "react";
+import { useEffect, useRef, useState } from "react";
import { onToast } from "../toasts";
import type { Buffers } from "./frame";
import { makeBuffers, renderFrame } from "./frame";
@@ -117,6 +117,10 @@ export default function NightShift() {
// Read by every frame, so a language change shows on the next one.
const labels = useRef(words);
labels.current = words;
+ // Frame callbacks and observers are out of the error boundary's reach, so a
+ // draw that throws is rethrown here, during render.
+ const [crash, setCrash] = useState<{ error: unknown } | null>(null);
+ if (crash) throw crash.error;
useEffect(() => {
const canvas = canvasRef.current;
@@ -177,27 +181,32 @@ export default function NightShift() {
};
const draw = () => {
- if (!layout || !buffers || !metrics) return;
- const moment = still
- ? stillMoment(saved.shift)
- : momentAt(clock, saved.shift);
- if (moment.shift !== lastShift) {
- lastShift = moment.shift;
- writeSaved({ seed: saved.seed, shift: moment.shift + 1 });
+ if (disposed || !layout || !buffers || !metrics) return;
+ try {
+ const moment = still
+ ? stillMoment(saved.shift)
+ : momentAt(clock, saved.shift);
+ if (moment.shift !== lastShift) {
+ lastShift = moment.shift;
+ writeSaved({ seed: saved.seed, shift: moment.shift + 1 });
+ }
+ readFocus(watcher);
+ watcher.flare = fade(clock - flareAt, 1.4);
+ watcher.alarm = fade(clock - alarmAt, 2.4);
+ const frame = renderFrame(
+ buffers,
+ layout,
+ planFor(moment.shift),
+ moment,
+ clock,
+ watcher,
+ labels.current
+ );
+ paint(ctx, buffers.main, frame, metrics);
+ } catch (error) {
+ disposed = true;
+ setCrash({ error });
}
- readFocus(watcher);
- watcher.flare = fade(clock - flareAt, 1.4);
- watcher.alarm = fade(clock - alarmAt, 2.4);
- const frame = renderFrame(
- buffers,
- layout,
- planFor(moment.shift),
- moment,
- clock,
- watcher,
- labels.current
- );
- paint(ctx, buffers.main, frame, metrics);
};
const tick = (now: number) => {
@@ -209,8 +218,6 @@ export default function NightShift() {
clock += Math.min(delta, 250) / 1000;
draw();
}
- // Asked for after the draw: a frame that throws ends the loop instead
- // of throwing again on every frame.
frameId = window.requestAnimationFrame(tick);
};