Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1e26ccef
Unverified
Commit
1e26ccef
authored
Mar 10, 2024
by
Balázs Orbán
Committed by
GitHub
Mar 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(error-overlay): unify Pages/App router error overlay source (#62939)
parent
fff9ddc2
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
424 additions
and
425 deletions
+424
-425
index.ts
packages/next/src/build/output/index.ts
+1
-1
impl.ts
packages/next/src/build/webpack-build/impl.ts
+1
-1
app-index.tsx
packages/next/src/client/app-index.tsx
+4
-7
ReactDevOverlay.tsx
...ient/components/react-dev-overlay/app/ReactDevOverlay.tsx
+14
-20
hot-reloader-client.tsx
.../components/react-dev-overlay/app/hot-reloader-client.tsx
+45
-51
Errors.tsx
...omponents/react-dev-overlay/internal/container/Errors.tsx
+3
-5
root-layout-missing-tags-error.tsx
...lay/internal/container/root-layout-missing-tags-error.tsx
+1
-1
format-webpack-messages.ts
...t-dev-overlay/internal/helpers/format-webpack-messages.ts
+0
-0
getErrorByType.ts
...ents/react-dev-overlay/internal/helpers/getErrorByType.ts
+1
-1
stack-frame.ts
...ponents/react-dev-overlay/internal/helpers/stack-frame.ts
+1
-3
ErrorBoundary.tsx
...ient/components/react-dev-overlay/pages/ErrorBoundary.tsx
+2
-4
ReactDevOverlay.tsx
...nt/components/react-dev-overlay/pages/ReactDevOverlay.tsx
+67
-181
bus.ts
...next/src/client/components/react-dev-overlay/pages/bus.ts
+1
-44
client.ts
...t/src/client/components/react-dev-overlay/pages/client.ts
+23
-23
hot-reloader-client.ts
...components/react-dev-overlay/pages/hot-reloader-client.ts
+8
-10
websocket.ts
...rc/client/components/react-dev-overlay/pages/websocket.ts
+1
-1
shared.ts
...es/next/src/client/components/react-dev-overlay/shared.ts
+168
-0
amp-dev.ts
packages/next/src/client/dev/amp-dev.ts
+4
-1
dev-build-watcher.ts
packages/next/src/client/dev/dev-build-watcher.ts
+1
-1
messages.ts
packages/next/src/client/dev/error-overlay/messages.ts
+0
-2
hot-middleware-client.ts
packages/next/src/client/dev/hot-middleware-client.ts
+2
-2
on-demand-entries-client.ts
packages/next/src/client/dev/on-demand-entries-client.ts
+1
-1
page-bootstrap.ts
packages/next/src/client/page-bootstrap.ts
+74
-64
report-to-socket.ts
packages/next/src/client/tracing/report-to-socket.ts
+1
-1
No files found.
packages/next/src/build/output/index.ts
View file @
1e26ccef
...
@@ -2,7 +2,7 @@ import { bold, red, yellow } from '../../lib/picocolors'
...
@@ -2,7 +2,7 @@ import { bold, red, yellow } from '../../lib/picocolors'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
textTable
from
'next/dist/compiled/text-table'
import
textTable
from
'next/dist/compiled/text-table'
import
createStore
from
'next/dist/compiled/unistore'
import
createStore
from
'next/dist/compiled/unistore'
import
formatWebpackMessages
from
'../../client/
dev/error-overlay
/format-webpack-messages'
import
formatWebpackMessages
from
'../../client/
components/react-dev-overlay/internal/helpers
/format-webpack-messages'
import
{
store
as
consoleStore
}
from
'./store'
import
{
store
as
consoleStore
}
from
'./store'
import
type
{
OutputState
}
from
'./store'
import
type
{
OutputState
}
from
'./store'
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
...
...
packages/next/src/build/webpack-build/impl.ts
View file @
1e26ccef
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
import
type
{
webpack
}
from
'next/dist/compiled/webpack/webpack'
import
{
red
}
from
'../../lib/picocolors'
import
{
red
}
from
'../../lib/picocolors'
import
formatWebpackMessages
from
'../../client/
dev/error-overlay
/format-webpack-messages'
import
formatWebpackMessages
from
'../../client/
components/react-dev-overlay/internal/helpers
/format-webpack-messages'
import
{
nonNullable
}
from
'../../lib/non-nullable'
import
{
nonNullable
}
from
'../../lib/non-nullable'
import
type
{
COMPILER_INDEXES
}
from
'../../shared/lib/constants'
import
type
{
COMPILER_INDEXES
}
from
'../../shared/lib/constants'
import
{
import
{
...
...
packages/next/src/client/app-index.tsx
View file @
1e26ccef
...
@@ -165,7 +165,7 @@ export function hydrate() {
...
@@ -165,7 +165,7 @@ export function hydrate() {
</
StrictModeIfEnabled
>
</
StrictModeIfEnabled
>
)
)
const
rootLayoutMissingTags
=
window
.
__next_root_layout_missing_tags
||
null
const
rootLayoutMissingTags
=
window
.
__next_root_layout_missing_tags
const
hasMissingTags
=
!!
rootLayoutMissingTags
?.
length
const
hasMissingTags
=
!!
rootLayoutMissingTags
?.
length
const
options
=
{
onRecoverableError
}
satisfies
ReactDOMClient
.
RootOptions
const
options
=
{
onRecoverableError
}
satisfies
ReactDOMClient
.
RootOptions
...
@@ -190,8 +190,8 @@ export function hydrate() {
...
@@ -190,8 +190,8 @@ export function hydrate() {
require
(
'./components/react-dev-overlay/app/ReactDevOverlay'
)
require
(
'./components/react-dev-overlay/app/ReactDevOverlay'
)
.
default
as
typeof
import
(
'./components/react-dev-overlay/app/ReactDevOverlay'
).
default
.
default
as
typeof
import
(
'./components/react-dev-overlay/app/ReactDevOverlay'
).
default
const
INITIAL_OVERLAY_STATE
:
typeof
import
(
'./components/react-dev-overlay/
app/error-overlay-reducer
'
).
INITIAL_OVERLAY_STATE
=
const
INITIAL_OVERLAY_STATE
:
typeof
import
(
'./components/react-dev-overlay/
shared
'
).
INITIAL_OVERLAY_STATE
=
require
(
'./components/react-dev-overlay/
app/error-overlay-reducer
'
).
INITIAL_OVERLAY_STATE
require
(
'./components/react-dev-overlay/
shared
'
).
INITIAL_OVERLAY_STATE
const
getSocketUrl
:
typeof
import
(
'./components/react-dev-overlay/internal/helpers/get-socket-url'
).
getSocketUrl
=
const
getSocketUrl
:
typeof
import
(
'./components/react-dev-overlay/internal/helpers/get-socket-url'
).
getSocketUrl
=
require
(
'./components/react-dev-overlay/internal/helpers/get-socket-url'
)
require
(
'./components/react-dev-overlay/internal/helpers/get-socket-url'
)
...
@@ -207,10 +207,7 @@ export function hydrate() {
...
@@ -207,10 +207,7 @@ export function hydrate() {
const
errorTree
=
(
const
errorTree
=
(
<
FallbackLayout
>
<
FallbackLayout
>
<
ReactDevOverlay
<
ReactDevOverlay
state=
{
{
state=
{
{
...
INITIAL_OVERLAY_STATE
,
rootLayoutMissingTags
}
}
...
INITIAL_OVERLAY_STATE
,
rootLayoutMissingTags
,
}
}
onReactError=
{
()
=>
{}
}
onReactError=
{
()
=>
{}
}
>
>
{
reactEl
}
{
reactEl
}
...
...
packages/next/src/client/components/react-dev-overlay/app/ReactDevOverlay.tsx
View file @
1e26ccef
import
*
as
React
from
'react'
import
*
as
React
from
'react'
import
{
ACTION_UNHANDLED_ERROR
}
from
'./error-overlay-reducer'
import
{
ACTION_UNHANDLED_ERROR
,
type
OverlayState
}
from
'../shared'
import
type
{
OverlayState
,
UnhandledErrorAction
,
}
from
'./error-overlay-reducer'
import
{
ShadowPortal
}
from
'../internal/components/ShadowPortal'
import
{
ShadowPortal
}
from
'../internal/components/ShadowPortal'
import
{
BuildError
}
from
'../internal/container/BuildError'
import
{
BuildError
}
from
'../internal/container/BuildError'
...
@@ -18,7 +14,7 @@ import { RootLayoutMissingTagsError } from '../internal/container/root-layout-mi
...
@@ -18,7 +14,7 @@ import { RootLayoutMissingTagsError } from '../internal/container/root-layout-mi
interface
ReactDevOverlayState
{
interface
ReactDevOverlayState
{
reactError
:
SupportedErrorEvent
|
null
reactError
:
SupportedErrorEvent
|
null
}
}
class
ReactDevOverlay
extends
React
.
PureComponent
<
export
default
class
ReactDevOverlay
extends
React
.
PureComponent
<
{
{
state
:
OverlayState
state
:
OverlayState
children
:
React
.
ReactNode
children
:
React
.
ReactNode
...
@@ -29,17 +25,17 @@ class ReactDevOverlay extends React.PureComponent<
...
@@ -29,17 +25,17 @@ class ReactDevOverlay extends React.PureComponent<
state
=
{
reactError
:
null
}
state
=
{
reactError
:
null
}
static
getDerivedStateFromError
(
error
:
Error
):
ReactDevOverlayState
{
static
getDerivedStateFromError
(
error
:
Error
):
ReactDevOverlayState
{
const
e
=
error
if
(
!
error
.
stack
)
return
{
reactError
:
null
}
const
event
:
UnhandledErrorAction
=
{
return
{
reactError
:
{
id
:
0
,
event
:
{
type
:
ACTION_UNHANDLED_ERROR
,
type
:
ACTION_UNHANDLED_ERROR
,
reason
:
error
,
reason
:
error
,
frames
:
parseStack
(
e
.
stack
!
),
frames
:
parseStack
(
error
.
stack
),
}
},
const
errorEvent
:
SupportedErrorEvent
=
{
},
id
:
0
,
event
,
}
}
return
{
reactError
:
errorEvent
}
}
}
componentDidCatch
(
componentErr
:
Error
)
{
componentDidCatch
(
componentErr
:
Error
)
{
...
@@ -52,7 +48,7 @@ class ReactDevOverlay extends React.PureComponent<
...
@@ -52,7 +48,7 @@ class ReactDevOverlay extends React.PureComponent<
const
hasBuildError
=
state
.
buildError
!=
null
const
hasBuildError
=
state
.
buildError
!=
null
const
hasRuntimeErrors
=
Boolean
(
state
.
errors
.
length
)
const
hasRuntimeErrors
=
Boolean
(
state
.
errors
.
length
)
const
hasMissingTags
=
Boolean
(
state
.
rootLayoutMissingTags
)
const
hasMissingTags
=
Boolean
(
state
.
rootLayoutMissingTags
?.
length
)
const
isMounted
=
const
isMounted
=
hasBuildError
||
hasRuntimeErrors
||
reactError
||
hasMissingTags
hasBuildError
||
hasRuntimeErrors
||
reactError
||
hasMissingTags
...
@@ -71,7 +67,7 @@ class ReactDevOverlay extends React.PureComponent<
...
@@ -71,7 +67,7 @@ class ReactDevOverlay extends React.PureComponent<
<
CssReset
/>
<
CssReset
/>
<
Base
/>
<
Base
/>
<
ComponentStyles
/>
<
ComponentStyles
/>
{
state
.
rootLayoutMissingTags
?
(
{
state
.
rootLayoutMissingTags
?.
length
?
(
<
RootLayoutMissingTagsError
<
RootLayoutMissingTagsError
missingTags=
{
state
.
rootLayoutMissingTags
}
missingTags=
{
state
.
rootLayoutMissingTags
}
/>
/>
...
@@ -101,5 +97,3 @@ class ReactDevOverlay extends React.PureComponent<
...
@@ -101,5 +97,3 @@ class ReactDevOverlay extends React.PureComponent<
)
)
}
}
}
}
export
default
ReactDevOverlay
packages/next/src/client/components/react-dev-overlay/app/hot-reloader-client.tsx
View file @
1e26ccef
import
type
{
ReactNode
}
from
'react'
import
type
{
ReactNode
}
from
'react'
import
React
,
{
import
{
useCallback
,
useEffect
,
startTransition
,
useMemo
}
from
'react'
useCallback
,
useEffect
,
useReducer
,
useMemo
,
startTransition
,
}
from
'react'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
formatWebpackMessages
from
'../
../../dev/error-overlay
/format-webpack-messages'
import
formatWebpackMessages
from
'../
internal/helpers
/format-webpack-messages'
import
{
useRouter
}
from
'../../navigation'
import
{
useRouter
}
from
'../../navigation'
import
{
import
{
ACTION_VERSION_INFO
,
INITIAL_OVERLAY_STATE
,
errorOverlayReducer
,
}
from
'./error-overlay-reducer'
import
{
ACTION_BUILD_OK
,
ACTION_BUILD_ERROR
,
ACTION_BEFORE_REFRESH
,
ACTION_BEFORE_REFRESH
,
ACTION_BUILD_ERROR
,
ACTION_BUILD_OK
,
ACTION_REFRESH
,
ACTION_REFRESH
,
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_REJECTION
,
ACTION_UNHANDLED_REJECTION
,
}
from
'./error-overlay-reducer'
ACTION_VERSION_INFO
,
useErrorOverlayReducer
,
}
from
'../shared'
import
{
parseStack
}
from
'../internal/helpers/parseStack'
import
{
parseStack
}
from
'../internal/helpers/parseStack'
import
ReactDevOverlay
from
'./ReactDevOverlay'
import
ReactDevOverlay
from
'./ReactDevOverlay'
import
{
useErrorHandler
}
from
'../internal/helpers/use-error-handler'
import
{
useErrorHandler
}
from
'../internal/helpers/use-error-handler'
...
@@ -40,9 +31,8 @@ import type {
...
@@ -40,9 +31,8 @@ import type {
TurbopackMsgToBrowser
,
TurbopackMsgToBrowser
,
}
from
'../../../../server/dev/hot-reloader-types'
}
from
'../../../../server/dev/hot-reloader-types'
import
{
extractModulesFromTurbopackMessage
}
from
'../../../../server/dev/extract-modules-from-turbopack-message'
import
{
extractModulesFromTurbopackMessage
}
from
'../../../../server/dev/extract-modules-from-turbopack-message'
import
{
REACT_REFRESH_FULL_RELOAD_FROM_ERROR
}
from
'../
../../dev/error-overlay/messages
'
import
{
REACT_REFRESH_FULL_RELOAD_FROM_ERROR
}
from
'../
shared
'
import
type
{
HydrationErrorState
}
from
'../internal/helpers/hydration-error-info'
import
type
{
HydrationErrorState
}
from
'../internal/helpers/hydration-error-info'
interface
Dispatcher
{
interface
Dispatcher
{
onBuildOk
():
void
onBuildOk
():
void
onBuildError
(
message
:
string
):
void
onBuildError
(
message
:
string
):
void
...
@@ -244,6 +234,7 @@ function tryApplyUpdates(
...
@@ -244,6 +234,7 @@ function tryApplyUpdates(
)
)
}
}
/** Handles messages from the sevrer for the App Router. */
function
processMessage
(
function
processMessage
(
obj
:
HMR_ACTION_TYPES
,
obj
:
HMR_ACTION_TYPES
,
sendMessage
:
(
message
:
string
)
=>
void
,
sendMessage
:
(
message
:
string
)
=>
void
,
...
@@ -314,9 +305,8 @@ function processMessage(
...
@@ -314,9 +305,8 @@ function processMessage(
const
{
errors
,
warnings
}
=
obj
const
{
errors
,
warnings
}
=
obj
// Is undefined when it's a 'built' event
// Is undefined when it's a 'built' event
if
(
'versionInfo'
in
obj
)
{
if
(
'versionInfo'
in
obj
)
dispatcher
.
onVersionInfo
(
obj
.
versionInfo
)
dispatcher
.
onVersionInfo
(
obj
.
versionInfo
)
}
const
hasErrors
=
Boolean
(
errors
&&
errors
.
length
)
const
hasErrors
=
Boolean
(
errors
&&
errors
.
length
)
// Compilation with errors (e.g. syntax error or missing modules).
// Compilation with errors (e.g. syntax error or missing modules).
if
(
hasErrors
)
{
if
(
hasErrors
)
{
...
@@ -464,10 +454,8 @@ export default function HotReload({
...
@@ -464,10 +454,8 @@ export default function HotReload({
assetPrefix
:
string
assetPrefix
:
string
children
?:
ReactNode
children
?:
ReactNode
})
{
})
{
const
[
state
,
dispatch
]
=
useReducer
(
const
[
state
,
dispatch
]
=
useErrorOverlayReducer
()
errorOverlayReducer
,
INITIAL_OVERLAY_STATE
)
const
dispatcher
=
useMemo
<
Dispatcher
>
(()
=>
{
const
dispatcher
=
useMemo
<
Dispatcher
>
(()
=>
{
return
{
return
{
onBuildOk
()
{
onBuildOk
()
{
...
@@ -486,9 +474,10 @@ export default function HotReload({
...
@@ -486,9 +474,10 @@ export default function HotReload({
dispatch
({
type
:
ACTION_VERSION_INFO
,
versionInfo
})
dispatch
({
type
:
ACTION_VERSION_INFO
,
versionInfo
})
},
},
}
}
},
[])
},
[
dispatch
])
const
handleOnUnhandledError
=
useCallback
((
error
:
Error
):
void
=>
{
const
handleOnUnhandledError
=
useCallback
(
(
error
:
Error
):
void
=>
{
const
errorDetails
=
(
error
as
any
).
details
as
const
errorDetails
=
(
error
as
any
).
details
as
|
HydrationErrorState
|
HydrationErrorState
|
undefined
|
undefined
...
@@ -504,14 +493,19 @@ export default function HotReload({
...
@@ -504,14 +493,19 @@ export default function HotReload({
:
undefined
,
:
undefined
,
warning
,
warning
,
})
})
},
[])
},
const
handleOnUnhandledRejection
=
useCallback
((
reason
:
Error
):
void
=>
{
[
dispatch
]
)
const
handleOnUnhandledRejection
=
useCallback
(
(
reason
:
Error
):
void
=>
{
dispatch
({
dispatch
({
type
:
ACTION_UNHANDLED_REJECTION
,
type
:
ACTION_UNHANDLED_REJECTION
,
reason
:
reason
,
reason
:
reason
,
frames
:
parseStack
(
reason
.
stack
!
),
frames
:
parseStack
(
reason
.
stack
!
),
})
})
},
[])
},
[
dispatch
]
)
const
handleOnReactError
=
useCallback
(()
=>
{
const
handleOnReactError
=
useCallback
(()
=>
{
RuntimeErrorHandler
.
hadRuntimeError
=
true
RuntimeErrorHandler
.
hadRuntimeError
=
true
},
[])
},
[])
...
...
packages/next/src/client/components/react-dev-overlay/internal/container/Errors.tsx
View file @
1e26ccef
...
@@ -2,11 +2,9 @@ import { useState, useEffect, useMemo, useCallback } from 'react'
...
@@ -2,11 +2,9 @@ import { useState, useEffect, useMemo, useCallback } from 'react'
import
{
import
{
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_REJECTION
,
ACTION_UNHANDLED_REJECTION
,
}
from
'../../app/error-overlay-reducer'
type
UnhandledErrorAction
,
import
type
{
type
UnhandledRejectionAction
,
UnhandledErrorAction
,
}
from
'../../shared'
UnhandledRejectionAction
,
}
from
'../../app/error-overlay-reducer'
import
{
import
{
Dialog
,
Dialog
,
DialogBody
,
DialogBody
,
...
...
packages/next/src/client/components/react-dev-overlay/internal/container/root-layout-missing-tags-error.tsx
View file @
1e26ccef
...
@@ -5,7 +5,7 @@ import { Overlay } from '../components/Overlay'
...
@@ -5,7 +5,7 @@ import { Overlay } from '../components/Overlay'
import
{
VersionStalenessInfo
}
from
'../components/VersionStalenessInfo'
import
{
VersionStalenessInfo
}
from
'../components/VersionStalenessInfo'
import
{
HotlinkedText
}
from
'../components/hot-linked-text'
import
{
HotlinkedText
}
from
'../components/hot-linked-text'
export
type
RootLayoutMissingTagsErrorProps
=
{
type
RootLayoutMissingTagsErrorProps
=
{
missingTags
:
string
[]
missingTags
:
string
[]
versionInfo
?:
VersionInfo
versionInfo
?:
VersionInfo
}
}
...
...
packages/next/src/client/
dev/error-overlay
/format-webpack-messages.ts
→
packages/next/src/client/
components/react-dev-overlay/internal/helpers
/format-webpack-messages.ts
View file @
1e26ccef
File moved
packages/next/src/client/components/react-dev-overlay/internal/helpers/getErrorByType.ts
View file @
1e26ccef
import
{
import
{
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_REJECTION
,
ACTION_UNHANDLED_REJECTION
,
}
from
'../../
app/error-overlay-reducer
'
}
from
'../../
shared
'
import
type
{
SupportedErrorEvent
}
from
'../container/Errors'
import
type
{
SupportedErrorEvent
}
from
'../container/Errors'
import
{
getOriginalStackFrames
}
from
'./stack-frame'
import
{
getOriginalStackFrames
}
from
'./stack-frame'
import
type
{
OriginalStackFrame
}
from
'./stack-frame'
import
type
{
OriginalStackFrame
}
from
'./stack-frame'
...
...
packages/next/src/client/components/react-dev-overlay/internal/helpers/stack-frame.ts
View file @
1e26ccef
...
@@ -32,9 +32,7 @@ function getOriginalStackFrame(
...
@@ -32,9 +32,7 @@ function getOriginalStackFrame(
`
${
`
${
process
.
env
.
__NEXT_ROUTER_BASEPATH
||
''
process
.
env
.
__NEXT_ROUTER_BASEPATH
||
''
}
/__nextjs_original-stack-frame?
${
params
.
toString
()}
`
,
}
/__nextjs_original-stack-frame?
${
params
.
toString
()}
`
,
{
{
signal
:
controller
.
signal
}
signal
:
controller
.
signal
,
}
)
)
.
finally
(()
=>
{
.
finally
(()
=>
{
clearTimeout
(
tm
)
clearTimeout
(
tm
)
...
...
packages/next/src/client/components/react-dev-overlay/pages/ErrorBoundary.tsx
View file @
1e26ccef
import
React
from
'react'
import
*
as
React
from
'react'
type
ErrorBoundaryProps
=
{
type
ErrorBoundaryProps
=
{
children
?:
React
.
ReactNode
children
?:
React
.
ReactNode
...
@@ -8,7 +8,7 @@ type ErrorBoundaryProps = {
...
@@ -8,7 +8,7 @@ type ErrorBoundaryProps = {
}
}
type
ErrorBoundaryState
=
{
error
:
Error
|
null
}
type
ErrorBoundaryState
=
{
error
:
Error
|
null
}
class
ErrorBoundary
extends
React
.
PureComponent
<
export
class
ErrorBoundary
extends
React
.
PureComponent
<
ErrorBoundaryProps
,
ErrorBoundaryProps
,
ErrorBoundaryState
ErrorBoundaryState
>
{
>
{
...
@@ -47,5 +47,3 @@ class ErrorBoundary extends React.PureComponent<
...
@@ -47,5 +47,3 @@ class ErrorBoundary extends React.PureComponent<
)
)
}
}
}
}
export
{
ErrorBoundary
}
packages/next/src/client/components/react-dev-overlay/pages/ReactDevOverlay.tsx
View file @
1e26ccef
...
@@ -3,117 +3,12 @@ import * as React from 'react'
...
@@ -3,117 +3,12 @@ import * as React from 'react'
import
*
as
Bus
from
'./bus'
import
*
as
Bus
from
'./bus'
import
{
ShadowPortal
}
from
'../internal/components/ShadowPortal'
import
{
ShadowPortal
}
from
'../internal/components/ShadowPortal'
import
{
BuildError
}
from
'../internal/container/BuildError'
import
{
BuildError
}
from
'../internal/container/BuildError'
import
type
{
SupportedErrorEvent
}
from
'../internal/container/Errors'
import
{
Errors
}
from
'../internal/container/Errors'
import
{
Errors
}
from
'../internal/container/Errors'
import
{
ErrorBoundary
}
from
'./ErrorBoundary'
import
{
ErrorBoundary
}
from
'./ErrorBoundary'
import
{
Base
}
from
'../internal/styles/Base'
import
{
Base
}
from
'../internal/styles/Base'
import
{
ComponentStyles
}
from
'../internal/styles/ComponentStyles'
import
{
ComponentStyles
}
from
'../internal/styles/ComponentStyles'
import
{
CssReset
}
from
'../internal/styles/CssReset'
import
{
CssReset
}
from
'../internal/styles/CssReset'
import
type
{
VersionInfo
}
from
'../../../../server/dev/parse-version-info'
import
{
useErrorOverlayReducer
}
from
'../shared'
type
RefreshState
=
|
{
// No refresh in progress.
type
:
'idle'
}
|
{
// The refresh process has been triggered, but the new code has not been
// executed yet.
type
:
'pending'
errors
:
SupportedErrorEvent
[]
}
type
OverlayState
=
{
nextId
:
number
buildError
:
string
|
null
errors
:
SupportedErrorEvent
[]
refreshState
:
RefreshState
versionInfo
:
VersionInfo
}
function
pushErrorFilterDuplicates
(
errors
:
SupportedErrorEvent
[],
err
:
SupportedErrorEvent
):
SupportedErrorEvent
[]
{
return
[
...
errors
.
filter
((
e
)
=>
{
// Filter out duplicate errors
return
e
.
event
.
reason
!==
err
.
event
.
reason
}),
err
,
]
}
function
reducer
(
state
:
OverlayState
,
ev
:
Bus
.
BusEvent
):
OverlayState
{
switch
(
ev
.
type
)
{
case
Bus
.
TYPE_BUILD_OK
:
{
return
{
...
state
,
buildError
:
null
}
}
case
Bus
.
TYPE_BUILD_ERROR
:
{
return
{
...
state
,
buildError
:
ev
.
message
}
}
case
Bus
.
TYPE_BEFORE_REFRESH
:
{
return
{
...
state
,
refreshState
:
{
type
:
'pending'
,
errors
:
[]
}
}
}
case
Bus
.
TYPE_REFRESH
:
{
return
{
...
state
,
buildError
:
null
,
errors
:
// Errors can come in during updates. In this case, UNHANDLED_ERROR
// and UNHANDLED_REJECTION events might be dispatched between the
// BEFORE_REFRESH and the REFRESH event. We want to keep those errors
// around until the next refresh. Otherwise we run into a race
// condition where those errors would be cleared on refresh completion
// before they can be displayed.
state
.
refreshState
.
type
===
'pending'
?
state
.
refreshState
.
errors
:
[],
refreshState
:
{
type
:
'idle'
},
}
}
case
Bus
.
TYPE_UNHANDLED_ERROR
:
case
Bus
.
TYPE_UNHANDLED_REJECTION
:
{
switch
(
state
.
refreshState
.
type
)
{
case
'idle'
:
{
return
{
...
state
,
nextId
:
state
.
nextId
+
1
,
errors
:
pushErrorFilterDuplicates
(
state
.
errors
,
{
id
:
state
.
nextId
,
event
:
ev
,
}),
}
}
case
'pending'
:
{
return
{
...
state
,
nextId
:
state
.
nextId
+
1
,
refreshState
:
{
...
state
.
refreshState
,
errors
:
pushErrorFilterDuplicates
(
state
.
refreshState
.
errors
,
{
id
:
state
.
nextId
,
event
:
ev
,
}),
},
}
}
default
:
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const
_
:
never
=
state
.
refreshState
return
state
}
}
case
Bus
.
TYPE_VERSION_INFO
:
{
return
{
...
state
,
versionInfo
:
ev
.
versionInfo
}
}
default
:
{
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const
_
:
never
=
ev
return
state
}
}
}
type
ErrorType
=
'runtime'
|
'build'
type
ErrorType
=
'runtime'
|
'build'
...
@@ -127,25 +22,18 @@ const shouldPreventDisplay = (
...
@@ -127,25 +22,18 @@ const shouldPreventDisplay = (
return
preventType
.
includes
(
errorType
)
return
preventType
.
includes
(
errorType
)
}
}
type
ReactDevOverlayProps
=
{
interface
ReactDevOverlayProps
{
children
?:
React
.
ReactNode
children
?:
React
.
ReactNode
preventDisplay
?:
ErrorType
[]
preventDisplay
?:
ErrorType
[]
globalOverlay
?:
boolean
globalOverlay
?:
boolean
}
}
const
ReactDevOverlay
:
React
.
FunctionComponent
<
ReactDevOverlayProps
>
=
export
default
function
ReactDevOverlay
({
function
ReactDevOverlay
({
children
,
preventDisplay
,
globalOverlay
})
{
children
,
const
[
state
,
dispatch
]
=
React
.
useReducer
<
preventDisplay
,
React
.
Reducer
<
OverlayState
,
Bus
.
BusEvent
>
globalOverlay
,
>
(
reducer
,
{
}:
ReactDevOverlayProps
)
{
nextId
:
1
,
const
[
state
,
dispatch
]
=
useErrorOverlayReducer
()
buildError
:
null
,
errors
:
[],
refreshState
:
{
type
:
'idle'
,
},
versionInfo
:
{
installed
:
'0.0.0'
,
staleness
:
'unknown'
},
})
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
Bus
.
on
(
dispatch
)
Bus
.
on
(
dispatch
)
...
@@ -173,7 +61,7 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
...
@@ -173,7 +61,7 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
const
displayPrevented
=
shouldPreventDisplay
(
errorType
,
preventDisplay
)
const
displayPrevented
=
shouldPreventDisplay
(
errorType
,
preventDisplay
)
return
(
return
(
<
React
.
Fragment
>
<
>
<
ErrorBoundary
<
ErrorBoundary
globalOverlay=
{
globalOverlay
}
globalOverlay=
{
globalOverlay
}
isMounted=
{
isMounted
}
isMounted=
{
isMounted
}
...
@@ -196,14 +84,12 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
...
@@ -196,14 +84,12 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
<
Errors
<
Errors
isAppDir=
{
false
}
isAppDir=
{
false
}
errors=
{
state
.
errors
}
errors=
{
state
.
errors
}
initialDisplayState=
{
'fullscreen'
}
versionInfo=
{
state
.
versionInfo
}
versionInfo=
{
state
.
versionInfo
}
initialDisplayState=
{
'fullscreen'
}
/>
/>
)
:
undefined
}
)
:
undefined
}
</
ShadowPortal
>
</
ShadowPortal
>
)
:
undefined
}
)
:
undefined
}
</
React
.
Fragment
>
</
>
)
)
}
}
export
default
ReactDevOverlay
packages/next/src/client/components/react-dev-overlay/pages/bus.ts
View file @
1e26ccef
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
BusEvent
}
from
'../shared'
import
type
{
ComponentStackFrame
}
from
'../internal/helpers/parse-component-stack'
import
type
{
VersionInfo
}
from
'../../../../server/dev/parse-version-info'
export
const
TYPE_BUILD_OK
=
'build-ok'
export
const
TYPE_BUILD_ERROR
=
'build-error'
export
const
TYPE_REFRESH
=
'fast-refresh'
export
const
TYPE_BEFORE_REFRESH
=
'before-fast-refresh'
export
const
TYPE_UNHANDLED_ERROR
=
'unhandled-error'
export
const
TYPE_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
TYPE_VERSION_INFO
=
'version-info'
export
type
BuildOk
=
{
type
:
typeof
TYPE_BUILD_OK
}
export
type
BuildError
=
{
type
:
typeof
TYPE_BUILD_ERROR
message
:
string
}
export
type
BeforeFastRefresh
=
{
type
:
typeof
TYPE_BEFORE_REFRESH
}
export
type
FastRefresh
=
{
type
:
typeof
TYPE_REFRESH
}
export
type
UnhandledError
=
{
type
:
typeof
TYPE_UNHANDLED_ERROR
reason
:
Error
frames
:
StackFrame
[]
componentStackFrames
?:
ComponentStackFrame
[]
}
export
type
UnhandledRejection
=
{
type
:
typeof
TYPE_UNHANDLED_REJECTION
reason
:
Error
frames
:
StackFrame
[]
}
export
type
VersionInfoEvent
=
{
type
:
typeof
TYPE_VERSION_INFO
versionInfo
:
VersionInfo
}
export
type
BusEvent
=
|
BuildOk
|
BuildError
|
FastRefresh
|
BeforeFastRefresh
|
UnhandledError
|
UnhandledRejection
|
VersionInfoEvent
export
type
BusEventHandler
=
(
ev
:
BusEvent
)
=>
void
export
type
BusEventHandler
=
(
ev
:
BusEvent
)
=>
void
...
...
packages/next/src/client/components/react-dev-overlay/pages/client.ts
View file @
1e26ccef
...
@@ -5,6 +5,15 @@ import {
...
@@ -5,6 +5,15 @@ import {
hydrationErrorState
,
hydrationErrorState
,
patchConsoleError
,
patchConsoleError
,
}
from
'../internal/helpers/hydration-error-info'
}
from
'../internal/helpers/hydration-error-info'
import
{
ACTION_BEFORE_REFRESH
,
ACTION_BUILD_ERROR
,
ACTION_BUILD_OK
,
ACTION_REFRESH
,
ACTION_UNHANDLED_ERROR
,
ACTION_UNHANDLED_REJECTION
,
ACTION_VERSION_INFO
,
}
from
'../shared'
import
type
{
VersionInfo
}
from
'../../../../server/dev/parse-version-info'
import
type
{
VersionInfo
}
from
'../../../../server/dev/parse-version-info'
// Patch console.error to collect information about hydration errors
// Patch console.error to collect information about hydration errors
...
@@ -46,7 +55,7 @@ function onUnhandledError(ev: ErrorEvent) {
...
@@ -46,7 +55,7 @@ function onUnhandledError(ev: ErrorEvent) {
// This is to avoid same error as different type showing up on client to cause flashing.
// This is to avoid same error as different type showing up on client to cause flashing.
if
(
e
.
name
!==
'ModuleBuildError'
&&
e
.
name
!==
'ModuleNotFoundError'
)
{
if
(
e
.
name
!==
'ModuleBuildError'
&&
e
.
name
!==
'ModuleNotFoundError'
)
{
Bus
.
emit
({
Bus
.
emit
({
type
:
Bus
.
TYPE
_UNHANDLED_ERROR
,
type
:
ACTION
_UNHANDLED_ERROR
,
reason
:
error
,
reason
:
error
,
frames
:
parseStack
(
e
.
stack
!
),
frames
:
parseStack
(
e
.
stack
!
),
componentStackFrames
,
componentStackFrames
,
...
@@ -67,13 +76,13 @@ function onUnhandledRejection(ev: PromiseRejectionEvent) {
...
@@ -67,13 +76,13 @@ function onUnhandledRejection(ev: PromiseRejectionEvent) {
const
e
=
reason
const
e
=
reason
Bus
.
emit
({
Bus
.
emit
({
type
:
Bus
.
TYPE
_UNHANDLED_REJECTION
,
type
:
ACTION
_UNHANDLED_REJECTION
,
reason
:
reason
,
reason
:
reason
,
frames
:
parseStack
(
e
.
stack
!
),
frames
:
parseStack
(
e
.
stack
!
),
})
})
}
}
function
register
()
{
export
function
register
()
{
if
(
isRegistered
)
{
if
(
isRegistered
)
{
return
return
}
}
...
@@ -89,7 +98,7 @@ function register() {
...
@@ -89,7 +98,7 @@ function register() {
window
.
addEventListener
(
'unhandledrejection'
,
onUnhandledRejection
)
window
.
addEventListener
(
'unhandledrejection'
,
onUnhandledRejection
)
}
}
function
unregister
()
{
export
function
unregister
()
{
if
(
!
isRegistered
)
{
if
(
!
isRegistered
)
{
return
return
}
}
...
@@ -106,35 +115,26 @@ function unregister() {
...
@@ -106,35 +115,26 @@ function unregister() {
window
.
removeEventListener
(
'unhandledrejection'
,
onUnhandledRejection
)
window
.
removeEventListener
(
'unhandledrejection'
,
onUnhandledRejection
)
}
}
function
onBuildOk
()
{
export
function
onBuildOk
()
{
Bus
.
emit
({
type
:
Bus
.
TYPE
_BUILD_OK
})
Bus
.
emit
({
type
:
ACTION
_BUILD_OK
})
}
}
function
onBuildError
(
message
:
string
)
{
export
function
onBuildError
(
message
:
string
)
{
Bus
.
emit
({
type
:
Bus
.
TYPE
_BUILD_ERROR
,
message
})
Bus
.
emit
({
type
:
ACTION
_BUILD_ERROR
,
message
})
}
}
function
onRefresh
()
{
export
function
onRefresh
()
{
Bus
.
emit
({
type
:
Bus
.
TYPE
_REFRESH
})
Bus
.
emit
({
type
:
ACTION
_REFRESH
})
}
}
function
onBeforeRefresh
()
{
export
function
onBeforeRefresh
()
{
Bus
.
emit
({
type
:
Bus
.
TYPE
_BEFORE_REFRESH
})
Bus
.
emit
({
type
:
ACTION
_BEFORE_REFRESH
})
}
}
function
onVersionInfo
(
versionInfo
:
VersionInfo
)
{
export
function
onVersionInfo
(
versionInfo
:
VersionInfo
)
{
Bus
.
emit
({
type
:
Bus
.
TYPE
_VERSION_INFO
,
versionInfo
})
Bus
.
emit
({
type
:
ACTION
_VERSION_INFO
,
versionInfo
})
}
}
export
{
getErrorByType
}
from
'../internal/helpers/getErrorByType'
export
{
getErrorByType
}
from
'../internal/helpers/getErrorByType'
export
{
getServerError
}
from
'../internal/helpers/nodeStackFrames'
export
{
getServerError
}
from
'../internal/helpers/nodeStackFrames'
export
{
default
as
ReactDevOverlay
}
from
'./ReactDevOverlay'
export
{
default
as
ReactDevOverlay
}
from
'./ReactDevOverlay'
export
{
onBuildOk
,
onBuildError
,
register
,
unregister
,
onBeforeRefresh
,
onRefresh
,
onVersionInfo
,
}
packages/next/src/client/
dev/error-overlay/hot-dev
-client.ts
→
packages/next/src/client/
components/react-dev-overlay/pages/hot-reloader
-client.ts
View file @
1e26ccef
...
@@ -35,17 +35,17 @@ import {
...
@@ -35,17 +35,17 @@ import {
onBeforeRefresh
,
onBeforeRefresh
,
onRefresh
,
onRefresh
,
onVersionInfo
,
onVersionInfo
,
}
from
'.
./../components/react-dev-overlay/pages
/client'
}
from
'./client'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
{
addMessageListener
,
sendMessage
}
from
'./websocket'
import
{
addMessageListener
,
sendMessage
}
from
'./websocket'
import
formatWebpackMessages
from
'./format-webpack-messages'
import
formatWebpackMessages
from
'.
./internal/helpers
/format-webpack-messages'
import
{
HMR_ACTIONS_SENT_TO_BROWSER
}
from
'../../../server/dev/hot-reloader-types'
import
{
HMR_ACTIONS_SENT_TO_BROWSER
}
from
'../../../
../
server/dev/hot-reloader-types'
import
type
{
import
type
{
HMR_ACTION_TYPES
,
HMR_ACTION_TYPES
,
TurbopackMsgToBrowser
,
TurbopackMsgToBrowser
,
}
from
'../../../server/dev/hot-reloader-types'
}
from
'../../../
../
server/dev/hot-reloader-types'
import
{
extractModulesFromTurbopackMessage
}
from
'../../../server/dev/extract-modules-from-turbopack-message'
import
{
extractModulesFromTurbopackMessage
}
from
'../../../
../
server/dev/extract-modules-from-turbopack-message'
import
{
REACT_REFRESH_FULL_RELOAD_FROM_ERROR
}
from
'.
/messages
'
import
{
REACT_REFRESH_FULL_RELOAD_FROM_ERROR
}
from
'.
./shared
'
// This alternative WebpackDevServer combines the functionality of:
// This alternative WebpackDevServer combines the functionality of:
// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js
// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js
// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js
// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js
...
@@ -258,7 +258,7 @@ function handleAvailableHash(hash: string) {
...
@@ -258,7 +258,7 @@ function handleAvailableHash(hash: string) {
mostRecentCompilationHash
=
hash
mostRecentCompilationHash
=
hash
}
}
/
/ Handle messages from the server.
/
** Handles messages from the sevrer for the Pages Router. */
function
processMessage
(
obj
:
HMR_ACTION_TYPES
)
{
function
processMessage
(
obj
:
HMR_ACTION_TYPES
)
{
if
(
!
(
'action'
in
obj
))
{
if
(
!
(
'action'
in
obj
))
{
return
return
...
@@ -273,9 +273,7 @@ function processMessage(obj: HMR_ACTION_TYPES) {
...
@@ -273,9 +273,7 @@ function processMessage(obj: HMR_ACTION_TYPES) {
}
}
case
HMR_ACTIONS_SENT_TO_BROWSER
.
BUILT
:
case
HMR_ACTIONS_SENT_TO_BROWSER
.
BUILT
:
case
HMR_ACTIONS_SENT_TO_BROWSER
.
SYNC
:
{
case
HMR_ACTIONS_SENT_TO_BROWSER
.
SYNC
:
{
if
(
obj
.
hash
)
{
if
(
obj
.
hash
)
handleAvailableHash
(
obj
.
hash
)
handleAvailableHash
(
obj
.
hash
)
}
const
{
errors
,
warnings
}
=
obj
const
{
errors
,
warnings
}
=
obj
...
...
packages/next/src/client/
dev/error-overlay
/websocket.ts
→
packages/next/src/client/
components/react-dev-overlay/pages
/websocket.ts
View file @
1e26ccef
import
type
{
HMR_ACTION_TYPES
}
from
'../../../server/dev/hot-reloader-types'
import
type
{
HMR_ACTION_TYPES
}
from
'../../../
../
server/dev/hot-reloader-types'
let
source
:
WebSocket
let
source
:
WebSocket
...
...
packages/next/src/client/components/react-dev-overlay/
app/error-overlay-reducer
.ts
→
packages/next/src/client/components/react-dev-overlay/
shared
.ts
View file @
1e26ccef
import
{
useReducer
}
from
'react'
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
VersionInfo
}
from
'../../../../server/dev/parse-version-info'
import
type
{
VersionInfo
}
from
'../../../server/dev/parse-version-info'
import
type
{
SupportedErrorEvent
}
from
'../internal/container/Errors'
import
type
{
SupportedErrorEvent
}
from
'./internal/container/Errors'
import
type
{
ComponentStackFrame
}
from
'../internal/helpers/parse-component-stack'
import
type
{
ComponentStackFrame
}
from
'./internal/helpers/parse-component-stack'
type
FastRefreshState
=
/** No refresh in progress. */
|
{
type
:
'idle'
}
/** The refresh process has been triggered, but the new code has not been executed yet. */
|
{
type
:
'pending'
;
errors
:
SupportedErrorEvent
[]
}
export
interface
OverlayState
{
nextId
:
number
buildError
:
string
|
null
errors
:
SupportedErrorEvent
[]
refreshState
:
FastRefreshState
rootLayoutMissingTags
:
typeof
window
.
__next_root_layout_missing_tags
versionInfo
:
VersionInfo
notFound
:
boolean
}
export
const
ACTION_BUILD_OK
=
'build-ok'
export
const
ACTION_BUILD_OK
=
'build-ok'
export
const
ACTION_BUILD_ERROR
=
'build-error'
export
const
ACTION_BUILD_ERROR
=
'build-error'
export
const
ACTION_BEFORE_REFRESH
=
'before-fast-refresh'
export
const
ACTION_BEFORE_REFRESH
=
'before-fast-refresh'
export
const
ACTION_REFRESH
=
'fast-refresh'
export
const
ACTION_REFRESH
=
'fast-refresh'
export
const
ACTION_VERSION_INFO
=
'version-info'
export
const
ACTION_UNHANDLED_ERROR
=
'unhandled-error'
export
const
ACTION_UNHANDLED_ERROR
=
'unhandled-error'
export
const
ACTION_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
ACTION_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
ACTION_VERSION_INFO
=
'version-info'
export
const
INITIAL_OVERLAY_STATE
:
OverlayState
=
{
nextId
:
1
,
buildError
:
null
,
errors
:
[],
notFound
:
false
,
refreshState
:
{
type
:
'idle'
},
versionInfo
:
{
installed
:
'0.0.0'
,
staleness
:
'unknown'
},
rootLayoutMissingTags
:
null
,
}
interface
BuildOkAction
{
interface
BuildOkAction
{
type
:
typeof
ACTION_BUILD_OK
type
:
typeof
ACTION_BUILD_OK
...
@@ -52,24 +61,14 @@ interface VersionInfoAction {
...
@@ -52,24 +61,14 @@ interface VersionInfoAction {
versionInfo
:
VersionInfo
versionInfo
:
VersionInfo
}
}
export
type
FastRefreshState
=
export
type
BusEvent
=
|
{
|
BuildOkAction
type
:
'idle'
|
BuildErrorAction
}
|
BeforeFastRefreshAction
|
{
|
FastRefreshAction
type
:
'pending'
|
UnhandledErrorAction
errors
:
SupportedErrorEvent
[]
|
UnhandledRejectionAction
}
|
VersionInfoAction
export
interface
OverlayState
{
nextId
:
number
buildError
:
string
|
null
errors
:
SupportedErrorEvent
[]
rootLayoutMissingTags
:
string
[]
|
null
refreshState
:
FastRefreshState
versionInfo
:
VersionInfo
notFound
:
boolean
}
function
pushErrorFilterDuplicates
(
function
pushErrorFilterDuplicates
(
errors
:
SupportedErrorEvent
[],
errors
:
SupportedErrorEvent
[],
...
@@ -84,31 +83,31 @@ function pushErrorFilterDuplicates(
...
@@ -84,31 +83,31 @@ function pushErrorFilterDuplicates(
]
]
}
}
export
const
errorOverlayReducer
:
React
.
Reducer
<
export
const
INITIAL_OVERLAY_STATE
:
OverlayState
=
{
Readonly
<
OverlayState
>
,
nextId
:
1
,
Readonly
<
buildError
:
null
,
|
BuildOkAction
errors
:
[],
|
BuildErrorAction
notFound
:
false
,
|
BeforeFastRefreshAction
refreshState
:
{
type
:
'idle'
},
|
FastRefreshAction
rootLayoutMissingTags
:
[],
|
UnhandledErrorAction
versionInfo
:
{
installed
:
'0.0.0'
,
staleness
:
'unknown'
},
|
UnhandledRejectionAction
}
|
VersionInfoAction
>
export
function
useErrorOverlayReducer
()
{
>
=
(
state
,
action
)
=>
{
return
useReducer
<
React
.
Reducer
<
OverlayState
,
BusEvent
>>
((
_
state
,
action
)
=>
{
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
case
ACTION_BUILD_OK
:
{
case
ACTION_BUILD_OK
:
{
return
{
...
state
,
buildError
:
null
}
return
{
...
_
state
,
buildError
:
null
}
}
}
case
ACTION_BUILD_ERROR
:
{
case
ACTION_BUILD_ERROR
:
{
return
{
...
state
,
buildError
:
action
.
message
}
return
{
...
_
state
,
buildError
:
action
.
message
}
}
}
case
ACTION_BEFORE_REFRESH
:
{
case
ACTION_BEFORE_REFRESH
:
{
return
{
...
state
,
refreshState
:
{
type
:
'pending'
,
errors
:
[]
}
}
return
{
...
_
state
,
refreshState
:
{
type
:
'pending'
,
errors
:
[]
}
}
}
}
case
ACTION_REFRESH
:
{
case
ACTION_REFRESH
:
{
return
{
return
{
...
state
,
...
_
state
,
buildError
:
null
,
buildError
:
null
,
errors
:
errors
:
// Errors can come in during updates. In this case, UNHANDLED_ERROR
// Errors can come in during updates. In this case, UNHANDLED_ERROR
...
@@ -117,33 +116,33 @@ export const errorOverlayReducer: React.Reducer<
...
@@ -117,33 +116,33 @@ export const errorOverlayReducer: React.Reducer<
// around until the next refresh. Otherwise we run into a race
// around until the next refresh. Otherwise we run into a race
// condition where those errors would be cleared on refresh completion
// condition where those errors would be cleared on refresh completion
// before they can be displayed.
// before they can be displayed.
state
.
refreshState
.
type
===
'pending'
_
state
.
refreshState
.
type
===
'pending'
?
state
.
refreshState
.
errors
?
_
state
.
refreshState
.
errors
:
[],
:
[],
refreshState
:
{
type
:
'idle'
},
refreshState
:
{
type
:
'idle'
},
}
}
}
}
case
ACTION_UNHANDLED_ERROR
:
case
ACTION_UNHANDLED_ERROR
:
case
ACTION_UNHANDLED_REJECTION
:
{
case
ACTION_UNHANDLED_REJECTION
:
{
switch
(
state
.
refreshState
.
type
)
{
switch
(
_
state
.
refreshState
.
type
)
{
case
'idle'
:
{
case
'idle'
:
{
return
{
return
{
...
state
,
...
_
state
,
nextId
:
state
.
nextId
+
1
,
nextId
:
_
state
.
nextId
+
1
,
errors
:
pushErrorFilterDuplicates
(
state
.
errors
,
{
errors
:
pushErrorFilterDuplicates
(
_
state
.
errors
,
{
id
:
state
.
nextId
,
id
:
_
state
.
nextId
,
event
:
action
,
event
:
action
,
}),
}),
}
}
}
}
case
'pending'
:
{
case
'pending'
:
{
return
{
return
{
...
state
,
...
_
state
,
nextId
:
state
.
nextId
+
1
,
nextId
:
_
state
.
nextId
+
1
,
refreshState
:
{
refreshState
:
{
...
state
.
refreshState
,
...
_
state
.
refreshState
,
errors
:
pushErrorFilterDuplicates
(
state
.
refreshState
.
errors
,
{
errors
:
pushErrorFilterDuplicates
(
_
state
.
refreshState
.
errors
,
{
id
:
state
.
nextId
,
id
:
_
state
.
nextId
,
event
:
action
,
event
:
action
,
}),
}),
},
},
...
@@ -151,15 +150,19 @@ export const errorOverlayReducer: React.Reducer<
...
@@ -151,15 +150,19 @@ export const errorOverlayReducer: React.Reducer<
}
}
default
:
default
:
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const
_
:
never
=
state
.
refreshState
const
_
:
never
=
_
state
.
refreshState
return
state
return
_
state
}
}
}
}
case
ACTION_VERSION_INFO
:
{
case
ACTION_VERSION_INFO
:
{
return
{
...
state
,
versionInfo
:
action
.
versionInfo
}
return
{
...
_
state
,
versionInfo
:
action
.
versionInfo
}
}
}
default
:
{
default
:
{
return
state
return
_
state
}
}
}
}
},
INITIAL_OVERLAY_STATE
)
}
}
export
const
REACT_REFRESH_FULL_RELOAD_FROM_ERROR
=
'[Fast Refresh] performing full reload because your application had an unrecoverable error'
packages/next/src/client/dev/amp-dev.ts
View file @
1e26ccef
/* globals __webpack_hash__ */
/* globals __webpack_hash__ */
import
{
displayContent
}
from
'./fouc'
import
{
displayContent
}
from
'./fouc'
import
initOnDemandEntries
from
'./on-demand-entries-client'
import
initOnDemandEntries
from
'./on-demand-entries-client'
import
{
addMessageListener
,
connectHMR
}
from
'./error-overlay/websocket'
import
{
addMessageListener
,
connectHMR
,
}
from
'../components/react-dev-overlay/pages/websocket'
import
{
HMR_ACTIONS_SENT_TO_BROWSER
}
from
'../../server/dev/hot-reloader-types'
import
{
HMR_ACTIONS_SENT_TO_BROWSER
}
from
'../../server/dev/hot-reloader-types'
declare
global
{
declare
global
{
...
...
packages/next/src/client/dev/dev-build-watcher.ts
View file @
1e26ccef
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define */
import
{
HMR_ACTIONS_SENT_TO_BROWSER
}
from
'../../server/dev/hot-reloader-types'
import
{
HMR_ACTIONS_SENT_TO_BROWSER
}
from
'../../server/dev/hot-reloader-types'
import
type
{
HMR_ACTION_TYPES
}
from
'../../server/dev/hot-reloader-types'
import
type
{
HMR_ACTION_TYPES
}
from
'../../server/dev/hot-reloader-types'
import
{
addMessageListener
}
from
'.
/error-overlay
/websocket'
import
{
addMessageListener
}
from
'.
./components/react-dev-overlay/pages
/websocket'
type
VerticalPosition
=
'top'
|
'bottom'
type
VerticalPosition
=
'top'
|
'bottom'
type
HorizonalPosition
=
'left'
|
'right'
type
HorizonalPosition
=
'left'
|
'right'
...
...
packages/next/src/client/dev/error-overlay/messages.ts
deleted
100644 → 0
View file @
fff9ddc2
export
const
REACT_REFRESH_FULL_RELOAD_FROM_ERROR
=
'[Fast Refresh] performing full reload because your application had an unrecoverable error'
packages/next/src/client/dev/hot-middleware-client.ts
View file @
1e26ccef
import
connect
from
'.
/error-overlay/hot-dev
-client'
import
connect
from
'.
./components/react-dev-overlay/pages/hot-reloader
-client'
import
{
sendMessage
}
from
'.
/error-overlay
/websocket'
import
{
sendMessage
}
from
'.
./components/react-dev-overlay/pages
/websocket'
let
reloading
=
false
let
reloading
=
false
...
...
packages/next/src/client/dev/on-demand-entries-client.ts
View file @
1e26ccef
import
Router
from
'../router'
import
Router
from
'../router'
import
{
sendMessage
}
from
'.
/error-overlay
/websocket'
import
{
sendMessage
}
from
'.
./components/react-dev-overlay/pages
/websocket'
export
default
async
(
page
?:
string
)
=>
{
export
default
async
(
page
?:
string
)
=>
{
if
(
page
)
{
if
(
page
)
{
...
...
packages/next/src/client/page-bootstrap.ts
View file @
1e26ccef
...
@@ -3,7 +3,10 @@ import initOnDemandEntries from './dev/on-demand-entries-client'
...
@@ -3,7 +3,10 @@ import initOnDemandEntries from './dev/on-demand-entries-client'
import
initializeBuildWatcher
from
'./dev/dev-build-watcher'
import
initializeBuildWatcher
from
'./dev/dev-build-watcher'
import
type
{
ShowHideHandler
}
from
'./dev/dev-build-watcher'
import
type
{
ShowHideHandler
}
from
'./dev/dev-build-watcher'
import
{
displayContent
}
from
'./dev/fouc'
import
{
displayContent
}
from
'./dev/fouc'
import
{
connectHMR
,
addMessageListener
}
from
'./dev/error-overlay/websocket'
import
{
connectHMR
,
addMessageListener
,
}
from
'./components/react-dev-overlay/pages/websocket'
import
{
import
{
assign
,
assign
,
urlQueryToSearchParams
,
urlQueryToSearchParams
,
...
@@ -29,18 +32,19 @@ export function pageBootrap(assetPrefix: string) {
...
@@ -29,18 +32,19 @@ export function pageBootrap(assetPrefix: string) {
addMessageListener
((
payload
)
=>
{
addMessageListener
((
payload
)
=>
{
if
(
reloading
)
return
if
(
reloading
)
return
if
(
'action'
in
payload
)
{
if
(
'action'
in
payload
)
{
if
(
payload
.
action
===
HMR_ACTIONS_SENT_TO_BROWSER
.
SERVER_ERROR
)
{
switch
(
payload
.
action
)
{
case
HMR_ACTIONS_SENT_TO_BROWSER
.
SERVER_ERROR
:
{
const
{
stack
,
message
}
=
JSON
.
parse
(
payload
.
errorJSON
)
const
{
stack
,
message
}
=
JSON
.
parse
(
payload
.
errorJSON
)
const
error
=
new
Error
(
message
)
const
error
=
new
Error
(
message
)
error
.
stack
=
stack
error
.
stack
=
stack
throw
error
throw
error
}
else
if
(
payload
.
action
===
HMR_ACTIONS_SENT_TO_BROWSER
.
RELOAD_PAGE
)
{
}
case
HMR_ACTIONS_SENT_TO_BROWSER
.
RELOAD_PAGE
:
{
reloading
=
true
reloading
=
true
window
.
location
.
reload
()
window
.
location
.
reload
()
}
else
if
(
break
payload
.
action
===
}
HMR_ACTIONS_SENT_TO_BROWSER
.
DEV_PAGES_MANIFEST_UPDATE
case
HMR_ACTIONS_SENT_TO_BROWSER
.
DEV_PAGES_MANIFEST_UPDATE
:
{
)
{
fetch
(
fetch
(
`
${
assetPrefix
}
/_next/static/development/_devPagesManifest.json`
`
${
assetPrefix
}
/_next/static/development/_devPagesManifest.json`
)
)
...
@@ -51,21 +55,23 @@ export function pageBootrap(assetPrefix: string) {
...
@@ -51,21 +55,23 @@ export function pageBootrap(assetPrefix: string) {
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
`Failed to fetch devPagesManifest`
,
err
)
console
.
log
(
`Failed to fetch devPagesManifest`
,
err
)
})
})
break
}
default
:
break
}
}
}
else
if
(
'event'
in
payload
)
{
}
else
if
(
'event'
in
payload
)
{
if
(
payload
.
event
===
HMR_ACTIONS_SENT_TO_BROWSER
.
MIDDLEWARE_CHANGES
)
{
switch
(
payload
.
event
)
{
case
HMR_ACTIONS_SENT_TO_BROWSER
.
MIDDLEWARE_CHANGES
:
{
return
window
.
location
.
reload
()
return
window
.
location
.
reload
()
}
else
if
(
}
payload
.
event
===
HMR_ACTIONS_SENT_TO_BROWSER
.
CLIENT_CHANGES
case
HMR_ACTIONS_SENT_TO_BROWSER
.
CLIENT_CHANGES
:
{
)
{
const
isOnErrorPage
=
window
.
next
.
router
.
pathname
===
'/_error'
const
isOnErrorPage
=
window
.
next
.
router
.
pathname
===
'/_error'
// On the error page we want to reload the page when a page was changed
// On the error page we want to reload the page when a page was changed
if
(
isOnErrorPage
)
{
if
(
isOnErrorPage
)
return
window
.
location
.
reload
()
return
window
.
location
.
reload
()
break
}
}
}
else
if
(
case
HMR_ACTIONS_SENT_TO_BROWSER
.
SERVER_ONLY_CHANGES
:
{
payload
.
event
===
HMR_ACTIONS_SENT_TO_BROWSER
.
SERVER_ONLY_CHANGES
)
{
const
{
pages
}
=
payload
const
{
pages
}
=
payload
// Make sure to reload when the dev-overlay is showing for an
// Make sure to reload when the dev-overlay is showing for an
...
@@ -102,6 +108,10 @@ export function pageBootrap(assetPrefix: string) {
...
@@ -102,6 +108,10 @@ export function pageBootrap(assetPrefix: string) {
})
})
.
finally
(
clearIndicator
)
.
finally
(
clearIndicator
)
}
}
break
}
default
:
break
}
}
}
}
})
})
...
...
packages/next/src/client/tracing/report-to-socket.ts
View file @
1e26ccef
import
{
sendMessage
}
from
'../
dev/error-overlay
/websocket'
import
{
sendMessage
}
from
'../
components/react-dev-overlay/pages
/websocket'
import
type
{
Span
}
from
'./tracer'
import
type
{
Span
}
from
'./tracer'
export
default
function
reportToSocket
(
span
:
Span
)
{
export
default
function
reportToSocket
(
span
:
Span
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment