1
1
/// <reference types="webpack/module.d.ts" />
2
2
3
3
import type { ReactNode } from 'react'
4
- import { useCallback , useEffect , startTransition , useMemo , useRef } from 'react'
4
+ import { useEffect , startTransition , useMemo , useRef } from 'react'
5
5
import stripAnsi from 'next/dist/compiled/strip-ansi'
6
6
import formatWebpackMessages from '../utils/format-webpack-messages'
7
7
import { useRouter } from '../../navigation'
@@ -13,35 +13,29 @@ import {
13
13
ACTION_DEV_INDICATOR ,
14
14
ACTION_REFRESH ,
15
15
ACTION_STATIC_INDICATOR ,
16
- ACTION_UNHANDLED_ERROR ,
17
- ACTION_UNHANDLED_REJECTION ,
18
16
ACTION_VERSION_INFO ,
19
17
REACT_REFRESH_FULL_RELOAD ,
20
18
reportInvalidHmrMessage ,
21
19
useErrorOverlayReducer ,
22
20
} from '../shared'
23
- import { parseStack } from '../utils/parse-stack'
24
21
import { AppDevOverlay } from './app-dev-overlay'
25
- import { useErrorHandler } from '../../errors/use-error-handler'
22
+ import { useErrorHandlers } from '../../errors/use-error-handler'
26
23
import { RuntimeErrorHandler } from '../../errors/runtime-error-handler'
27
24
import {
28
25
useSendMessage ,
29
26
useTurbopack ,
30
27
useWebsocket ,
31
28
useWebsocketPing ,
32
29
} from '../utils/use-websocket'
33
- import { parseComponentStack } from '../utils/parse-component-stack'
34
30
import type { VersionInfo } from '../../../../server/dev/parse-version-info'
35
31
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../../server/dev/hot-reloader-types'
36
32
import type {
37
33
HMR_ACTION_TYPES ,
38
34
TurbopackMsgToBrowser ,
39
35
} from '../../../../server/dev/hot-reloader-types'
40
36
import { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from '../shared'
41
- import type { HydrationErrorState } from '../../errors/hydration-error-info'
42
37
import type { DebugInfo } from '../types'
43
38
import { useUntrackedPathname } from '../../navigation-untracked'
44
- import { getReactStitchedError } from '../../errors/stitched-error'
45
39
import { handleDevBuildIndicatorHmrEvents } from '../../../dev/dev-build-indicator/internal/handle-dev-build-indicator-hmr-events'
46
40
import type { GlobalErrorComponent } from '../../error-boundary'
47
41
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
@@ -509,6 +503,7 @@ export default function HotReload({
509
503
globalError : [ GlobalErrorComponent , React . ReactNode ]
510
504
} ) {
511
505
const [ state , dispatch ] = useErrorOverlayReducer ( 'app' )
506
+ useErrorHandlers ( dispatch )
512
507
513
508
const dispatcher = useMemo < Dispatcher > ( ( ) => {
514
509
return {
@@ -542,43 +537,6 @@ export default function HotReload({
542
537
}
543
538
} , [ dispatch ] )
544
539
545
- const handleOnUnhandledError = useCallback (
546
- ( error : Error ) : void => {
547
- const errorDetails = ( error as any ) . details as
548
- | HydrationErrorState
549
- | undefined
550
- // Component stack is added to the error in use-error-handler in case there was a hydration error
551
- const componentStackTrace =
552
- ( error as any ) . _componentStack || errorDetails ?. componentStack
553
- const warning = errorDetails ?. warning
554
-
555
- dispatch ( {
556
- type : ACTION_UNHANDLED_ERROR ,
557
- reason : error ,
558
- frames : parseStack ( error . stack || '' ) ,
559
- componentStackFrames :
560
- typeof componentStackTrace === 'string'
561
- ? parseComponentStack ( componentStackTrace )
562
- : undefined ,
563
- warning,
564
- } )
565
- } ,
566
- [ dispatch ]
567
- )
568
-
569
- const handleOnUnhandledRejection = useCallback (
570
- ( reason : Error ) : void => {
571
- const stitchedError = getReactStitchedError ( reason )
572
- dispatch ( {
573
- type : ACTION_UNHANDLED_REJECTION ,
574
- reason : stitchedError ,
575
- frames : parseStack ( stitchedError . stack || '' ) ,
576
- } )
577
- } ,
578
- [ dispatch ]
579
- )
580
- useErrorHandler ( handleOnUnhandledError , handleOnUnhandledRejection )
581
-
582
540
const webSocketRef = useWebsocket ( assetPrefix )
583
541
useWebsocketPing ( webSocketRef )
584
542
const sendMessage = useSendMessage ( webSocketRef )
0 commit comments