@@ -2,16 +2,20 @@ import './ErrorBoundary.scss'
22
33import clsx from 'clsx'
44import { useActions , useValues } from 'kea'
5+ import { useEffect } from 'react'
56
67import { IconCopy } from '@posthog/icons'
78import { PostHogErrorBoundary , type PostHogErrorBoundaryFallbackProps } from '@posthog/react'
89
910import { SupportTicketExceptionEvent , supportLogic } from 'lib/components/Support/supportLogic'
1011import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
1112import { LemonButton } from 'lib/lemon-ui/LemonButton'
13+ import { getChunkLoadRecoveryAction , reloadAfterChunkLoadError } from 'lib/utils/chunkLoadErrorRecovery'
1214import { copyToClipboard } from 'lib/utils/copyToClipboard'
1315import { teamLogic } from 'scenes/teamLogic'
1416
17+ import { ErrorNetwork } from '../ErrorNetwork'
18+
1519const DOM_MUTATION_PATTERNS = [
1620 "Failed to execute 'removeChild' on 'Node'" ,
1721 "Failed to execute 'insertBefore' on 'Node'" ,
@@ -29,6 +33,36 @@ interface ErrorBoundaryProps {
2933 className ?: string
3034}
3135
36+ function ChunkLoadErrorFallback ( {
37+ className,
38+ recoveryAction,
39+ } : {
40+ className ?: string
41+ recoveryAction : 'reload' | 'show-error'
42+ } ) : JSX . Element {
43+ useEffect ( ( ) => {
44+ if ( recoveryAction === 'reload' ) {
45+ console . error ( 'App assets regenerated in a lazily loaded component. Reloading this page.' )
46+ reloadAfterChunkLoadError ( )
47+ }
48+ } , [ recoveryAction ] )
49+
50+ if ( recoveryAction === 'show-error' ) {
51+ return (
52+ < div className = { clsx ( 'ErrorBoundary' , className ) } >
53+ < ErrorNetwork />
54+ </ div >
55+ )
56+ }
57+
58+ return (
59+ < div className = { clsx ( 'ErrorBoundary' , className ) } >
60+ < h2 > Refreshing…</ h2 >
61+ < p > PostHog just updated. Reloading the page now.</ p >
62+ </ div >
63+ )
64+ }
65+
3266export function ErrorBoundary ( { children, exceptionProps = { } , className } : ErrorBoundaryProps ) : JSX . Element {
3367 const { currentTeamId } = useValues ( teamLogic )
3468 const { openSupportForm } = useActions ( supportLogic )
@@ -53,6 +87,7 @@ export function ErrorBoundary({ children, exceptionProps = {}, className }: Erro
5387 const exceptionEvent = props . exceptionEvent as SupportTicketExceptionEvent
5488
5589 const isBrowserExtensionError = isDOMModificationError ( normalizedError )
90+ const chunkLoadRecoveryAction = getChunkLoadRecoveryAction ( normalizedError )
5691
5792 const errorDetails = [
5893 exceptionEvent ?. uuid ? `Exception ID: ${ exceptionEvent . uuid } ` : null ,
@@ -61,6 +96,10 @@ export function ErrorBoundary({ children, exceptionProps = {}, className }: Erro
6196 . filter ( Boolean )
6297 . join ( '\n\n' )
6398
99+ if ( chunkLoadRecoveryAction !== 'ignore' ) {
100+ return < ChunkLoadErrorFallback className = { className } recoveryAction = { chunkLoadRecoveryAction } />
101+ }
102+
64103 return (
65104 < div className = { clsx ( 'ErrorBoundary' , className ) } >
66105 < h2 > An error has occurred</ h2 >
0 commit comments