Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(frontend): show a network error screen when the app shell chunk fails to load (#93988)

Eleftheria Trivyzakic7facd3d7aa9
diff --git a/frontend/src/layout/AppLoadError.tsx b/frontend/src/layout/AppLoadError.tsx
new file mode 100644
index 000000000000..4e856ae7a5ba
--- /dev/null
+++ b/frontend/src/layout/AppLoadError.tsx
@@ -0,0 +1,59 @@
+import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
+import { useEffect, useState } from 'react'
+
+import { IconRefresh } from '@posthog/icons'
+
+import { SupportTicketExceptionEvent, supportLogic } from 'lib/components/Support/supportLogic'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { teamLogic } from 'scenes/teamLogic'
+
+interface AppLoadErrorProps {
+ error: unknown
+}
+
+/**
+ * Shown when the app shell chunk still fails to download after the automatic retries and reload.
+ * The generic ErrorBoundary never sees this error, so the exception is captured here to keep it
+ * visible in error tracking.
+ */
+export function AppLoadError({ error }: AppLoadErrorProps): JSX.Element {
+ const { openSupportForm } = useActions(supportLogic)
+ const { currentTeamId } = useValues(teamLogic)
+ const [exceptionEvent, setExceptionEvent] = useState<SupportTicketExceptionEvent | undefined>()
+
+ // Capture once per mount. A re-render must not send the same failure again.
+ useEffect(() => {
+ setExceptionEvent(posthog.captureException(error, { chunk_load_error: true, team_id: currentTeamId }))
+ }, []) // oxlint-disable-line react-hooks/exhaustive-deps
+
+ return (
+ <div className="p-4">
+ <h1 className="mb-1 text-2xl font-bold">PostHog could not load</h1>
+ <p>
+ Your browser could not download part of the app. This is usually a network problem. Reload the page to
+ try again. If it happens again, try a different network, or turn off browser extensions and proxies.
+ </p>
+ <div className="flex gap-2 flex-wrap">
+ <LemonButton
+ type="primary"
+ icon={<IconRefresh />}
+ onClick={() => window.location.reload()}
+ data-attr="app-load-error-reload"
+ >
+ Reload the page
+ </LemonButton>
+ <LemonButton
+ type="secondary"
+ onClick={() =>
+ openSupportForm({ kind: 'bug', isEmailFormOpen: true, exception_event: exceptionEvent })
+ }
+ data-attr="app-load-error-email-engineer"
+ >
+ Email an engineer
+ </LemonButton>
+ </div>
+ {exceptionEvent?.uuid && <div className="text-muted text-xs mt-2">Exception ID: {exceptionEvent.uuid}</div>}
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/App.tsx b/frontend/src/scenes/App.tsx
index 8fffca1d0493..d97560eb03f9 100644
--- a/frontend/src/scenes/App.tsx
+++ b/frontend/src/scenes/App.tsx
@@ -22,6 +22,7 @@ import { appScenes } from 'scenes/appScenes'
import { sceneLogic } from 'scenes/sceneLogic'
import { userLogic } from 'scenes/userLogic'
+import { AppLoadError } from '~/layout/AppLoadError'
import { ErrorBoundary } from '~/layout/ErrorBoundary'
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
@@ -201,7 +202,7 @@ function AppScene(): JSX.Element | null {
}
return (
- <ChunkLoadErrorBoundary>
+ <ChunkLoadErrorBoundary fallback={(error) => <AppLoadError error={error} />}>
<Suspense
fallback={
// SpinnerOverlay is already imported here — no new lazy deps vs skeleton.
diff --git a/frontend/src/scenes/ChunkLoadErrorBoundary.test.tsx b/frontend/src/scenes/ChunkLoadErrorBoundary.test.tsx
index 9d32a7e15185..58090093abfa 100644
--- a/frontend/src/scenes/ChunkLoadErrorBoundary.test.tsx
+++ b/frontend/src/scenes/ChunkLoadErrorBoundary.test.tsx
@@ -81,6 +81,30 @@ describe('ChunkLoadErrorBoundary', () => {
).toBeInTheDocument()
})
+ it('renders the fallback for repeated chunk errors when one is provided', () => {
+ const reload = jest.fn()
+ window.localStorage.setItem(RELOAD_GUARD_KEY, String(Date.now()))
+
+ render(
+ <TestErrorBoundary>
+ <ChunkLoadErrorBoundary
+ reload={reload}
+ fallback={(error) => <div>fallback: {(error as Error).message}</div>}
+ >
+ <ThrowChunkError />
+ </ChunkLoadErrorBoundary>
+ </TestErrorBoundary>
+ )
+
+ expect(reload).not.toHaveBeenCalled()
+ expect(
+ screen.getByText('fallback: Failed to fetch dynamically imported module: /static/react-json-view.js')
+ ).toBeInTheDocument()
+ expect(
+ screen.queryByText('Failed to fetch dynamically imported module: /static/react-json-view.js')
+ ).not.toBeInTheDocument()
+ })
+
it('lets non-chunk errors bubble to the parent error boundary', () => {
const reload = jest.fn()
diff --git a/frontend/src/scenes/ChunkLoadErrorBoundary.tsx b/frontend/src/scenes/ChunkLoadErrorBoundary.tsx
index 39d4e952f710..f614f1e74188 100644
--- a/frontend/src/scenes/ChunkLoadErrorBoundary.tsx
+++ b/frontend/src/scenes/ChunkLoadErrorBoundary.tsx
@@ -13,13 +13,14 @@ interface State {
/**
* Catches chunk-load failures from `React.lazy(() => import(...))` boundaries.
* On a stale-deploy chunk-hash mismatch we reload once; if a reload was already
- * attempted in the last 20s we let the error bubble to the outer ErrorBoundary
- * rather than spinning forever. Non-chunk errors are re-thrown so the regular
- * error UI still renders.
+ * attempted in the last 20s we render `fallback` when given, or else let the error
+ * bubble to the outer ErrorBoundary rather than spinning forever. Non-chunk errors
+ * are re-thrown so the regular error UI still renders.
*/
interface ChunkLoadErrorBoundaryProps {
children: ReactNode
reload?: () => void
+ fallback?: (error: unknown) => ReactNode
}
export class ChunkLoadErrorBoundary extends Component<ChunkLoadErrorBoundaryProps, State> {
@@ -61,6 +62,9 @@ export class ChunkLoadErrorBoundary extends Component<ChunkLoadErrorBoundaryProp
override render(): ReactNode {
const { error, surface } = this.state
+ if (error && surface && isChunkLoadError(error) && this.props.fallback) {
+ return this.props.fallback(error)
+ }
if (error && (!isChunkLoadError(error) || surface)) {
throw error
}