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): recognize Safari chunk-load failures on stale deploys (#58242)

posthog[bot]a5dc9f80130b
diff --git a/frontend/src/lib/utils/isChunkLoadError.test.ts b/frontend/src/lib/utils/isChunkLoadError.test.ts
new file mode 100644
index 000000000000..b52cf1978243
--- /dev/null
+++ b/frontend/src/lib/utils/isChunkLoadError.test.ts
@@ -0,0 +1,27 @@
+import { isChunkLoadError } from './isChunkLoadError'
+
+describe('isChunkLoadError', () => {
+ it.each([
+ ['webpack ChunkLoadError', { name: 'ChunkLoadError', message: 'Loading chunk 0 failed.' }, true],
+ [
+ 'esbuild dynamic-import failure',
+ { name: 'TypeError', message: 'Failed to fetch dynamically imported module: /static/chunk.js' },
+ true,
+ ],
+ ['Safari native TypeError: Load failed', { name: 'TypeError', message: 'Load failed' }, true],
+ ['generic TypeError', { name: 'TypeError', message: 'undefined is not a function' }, false],
+ ['unrelated Error', { name: 'Error', message: 'something else' }, false],
+ ['error with no name or message', {}, false],
+ ])('classifies %s', (_label, error, expected) => {
+ expect(isChunkLoadError(error)).toBe(expected)
+ })
+
+ it.each([
+ ['null', null],
+ ['undefined', undefined],
+ ['string', 'Load failed'],
+ ['number', 42],
+ ])('returns false for non-object %s', (_label, value) => {
+ expect(isChunkLoadError(value)).toBe(false)
+ })
+})
diff --git a/frontend/src/lib/utils/isChunkLoadError.ts b/frontend/src/lib/utils/isChunkLoadError.ts
new file mode 100644
index 000000000000..800297b4b9fd
--- /dev/null
+++ b/frontend/src/lib/utils/isChunkLoadError.ts
@@ -0,0 +1,18 @@
+/**
+ * Recognizes the various shapes a failed `import(...)` can take across bundlers and browsers:
+ * - webpack: `Error` with `name === 'ChunkLoadError'`
+ * - esbuild/Vite: message contains `'Failed to fetch dynamically imported module'`
+ * - Safari: native `TypeError: Load failed` (no JS stack — see load-failed.tsx known exception)
+ */
+export function isChunkLoadError(error: unknown): boolean {
+ if (!error || typeof error !== 'object') {
+ return false
+ }
+ const err = error as { name?: string; message?: string }
+ const message = typeof err.message === 'string' ? err.message : ''
+ return (
+ err.name === 'ChunkLoadError' ||
+ message.includes('Failed to fetch dynamically imported module') ||
+ (err.name === 'TypeError' && message.includes('Load failed'))
+ )
+}
diff --git a/frontend/src/scenes/ChunkLoadErrorBoundary.tsx b/frontend/src/scenes/ChunkLoadErrorBoundary.tsx
index 50ca238380ca..5b4206da5f95 100644
--- a/frontend/src/scenes/ChunkLoadErrorBoundary.tsx
+++ b/frontend/src/scenes/ChunkLoadErrorBoundary.tsx
@@ -1,19 +1,10 @@
import { Component, type ReactNode } from 'react'
+import { isChunkLoadError } from 'lib/utils/isChunkLoadError'
+
const RELOAD_GUARD_KEY = 'posthog-chunk-reload-at'
const RELOAD_GUARD_WINDOW_MS = 20_000
-function isChunkLoadError(error: unknown): boolean {
- if (!error || typeof error !== 'object') {
- return false
- }
- const err = error as { name?: string; message?: string }
- return (
- err.name === 'ChunkLoadError' ||
- (typeof err.message === 'string' && err.message.includes('Failed to fetch dynamically imported module'))
- )
-}
-
interface State {
error: unknown
surface: boolean
diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsx
index 3557348dc5f0..a32498b8c698 100644
--- a/frontend/src/scenes/sceneLogic.tsx
+++ b/frontend/src/scenes/sceneLogic.tsx
@@ -13,6 +13,7 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { Spinner } from 'lib/lemon-ui/Spinner'
import { getRelativeNextPath, identifierToHuman } from 'lib/utils'
import { getAppContext, getCurrentTeamIdOrNone } from 'lib/utils/getAppContext'
+import { isChunkLoadError } from 'lib/utils/isChunkLoadError'
import { NEW_INTERNAL_TAB } from 'lib/utils/newInternalTab'
import { addProjectIdIfMissing, removeProjectIdIfPresent, stripTrailingSlash } from 'lib/utils/router-utils'
import { withForwardedSearchParams } from 'lib/utils/sceneLogicUtils'
@@ -1366,10 +1367,7 @@ export const sceneLogic = kea<sceneLogicType>([
window.ESBUILD_LOAD_CHUNKS?.(sceneId)
importedScene = await props.scenes[sceneId]()
} catch (error: any) {
- if (
- error.name === 'ChunkLoadError' || // webpack
- error.message?.includes('Failed to fetch dynamically imported module') // esbuild
- ) {
+ if (isChunkLoadError(error)) {
// Reloaded once in the last 20 seconds and now reloading again? Show network error
if (
values.lastReloadAt &&