Files
HealthLog/src/app/error.tsx
T
Marc-André Bombeck ac212cf6b7 fix(pwa): give the offline page a way back and reload once on any stale chunk
Without a connection a signed-in page opens the worker's offline page:
signed-in pages carry `private, no-store` from the proxy and are never
cached, so this is also what an offline launch of the installed app
shows. The page now offers a real 64 px retry control, reloads by itself
when the connection returns, follows the device's light or dark scheme
and keeps clear of the notch and home indicator. The worker's comment on
the page cache says plainly that only public pages land in it.

The single reload after a stale-shell chunk failure moves into
src/lib/pwa/chunk-reload.ts and now runs in the root error boundary too,
and it recognises a failed dynamic import as WebKit and Firefox word it.

pwa-offline.spec.ts runs in the service-worker project and proves the
offline strip, the offline page and the automatic recovery against the
real worker.
2026-10-08 17:23:47 +02:00

31 lines
883 B
TypeScript

"use client";
import { useEffect } from "react";
import { ErrorDetails } from "@/components/error-details";
import { reloadOnceForChunkError } from "@/lib/pwa/chunk-reload";
export default function AppError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
// Surface to any client-side error tracker that's already hooked up.
if (typeof window !== "undefined") {
const g = window as typeof window & {
__healthlog_onError?: (err: Error & { digest?: string }) => void;
};
g.__healthlog_onError?.(error);
}
// v1.4.38.3 — auto-recover from a stale-shell chunk-load error with a
// single reload (`src/lib/pwa/chunk-reload.ts`, shared with the root
// boundary).
reloadOnceForChunkError(error);
}, [error]);
return <ErrorDetails error={error} reset={reset} />;
}