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
0a73e898
Unverified
Commit
0a73e898
authored
Mar 06, 2024
by
Balázs Orbán
Committed by
GitHub
Mar 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(error-overlay): version staleness in Pages Router (#62942)
parent
4c62c300
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
38 deletions
+47
-38
ReactDevOverlay.tsx
...nt/components/react-dev-overlay/pages/ReactDevOverlay.tsx
+11
-1
bus.ts
...next/src/client/components/react-dev-overlay/pages/bus.ts
+9
-0
client.ts
...t/src/client/components/react-dev-overlay/pages/client.ts
+6
-0
hot-dev-client.ts
packages/next/src/client/dev/error-overlay/hot-dev-client.ts
+5
-0
hmr.test.ts
test/development/basic/hmr.test.ts
+15
-36
index.test.ts
...on/next-image-new/invalid-image-import/test/index.test.ts
+1
-1
No files found.
packages/next/src/client/components/react-dev-overlay/pages/ReactDevOverlay.tsx
View file @
0a73e898
...
@@ -9,6 +9,7 @@ import { ErrorBoundary } from './ErrorBoundary'
...
@@ -9,6 +9,7 @@ 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'
type
RefreshState
=
type
RefreshState
=
|
{
|
{
...
@@ -27,6 +28,7 @@ type OverlayState = {
...
@@ -27,6 +28,7 @@ type OverlayState = {
buildError
:
string
|
null
buildError
:
string
|
null
errors
:
SupportedErrorEvent
[]
errors
:
SupportedErrorEvent
[]
refreshState
:
RefreshState
refreshState
:
RefreshState
versionInfo
:
VersionInfo
}
}
function
pushErrorFilterDuplicates
(
function
pushErrorFilterDuplicates
(
...
@@ -102,6 +104,9 @@ function reducer(state: OverlayState, ev: Bus.BusEvent): OverlayState {
...
@@ -102,6 +104,9 @@ function reducer(state: OverlayState, ev: Bus.BusEvent): OverlayState {
return
state
return
state
}
}
}
}
case
Bus
.
TYPE_VERSION_INFO
:
{
return
{
...
state
,
versionInfo
:
ev
.
versionInfo
}
}
default
:
{
default
:
{
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const
_
:
never
=
ev
const
_
:
never
=
ev
...
@@ -139,6 +144,7 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
...
@@ -139,6 +144,7 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
refreshState
:
{
refreshState
:
{
type
:
'idle'
,
type
:
'idle'
,
},
},
versionInfo
:
{
installed
:
'0.0.0'
,
staleness
:
'unknown'
},
})
})
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
...
@@ -182,12 +188,16 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
...
@@ -182,12 +188,16 @@ const ReactDevOverlay: React.FunctionComponent<ReactDevOverlayProps> =
<
ComponentStyles
/>
<
ComponentStyles
/>
{
displayPrevented
?
null
:
hasBuildError
?
(
{
displayPrevented
?
null
:
hasBuildError
?
(
<
BuildError
message=
{
state
.
buildError
!
}
/>
<
BuildError
message=
{
state
.
buildError
!
}
versionInfo=
{
state
.
versionInfo
}
/>
)
:
hasRuntimeErrors
?
(
)
:
hasRuntimeErrors
?
(
<
Errors
<
Errors
isAppDir=
{
false
}
isAppDir=
{
false
}
errors=
{
state
.
errors
}
errors=
{
state
.
errors
}
initialDisplayState=
{
'fullscreen'
}
initialDisplayState=
{
'fullscreen'
}
versionInfo=
{
state
.
versionInfo
}
/>
/>
)
:
undefined
}
)
:
undefined
}
</
ShadowPortal
>
</
ShadowPortal
>
...
...
packages/next/src/client/components/react-dev-overlay/pages/bus.ts
View file @
0a73e898
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
StackFrame
}
from
'next/dist/compiled/stacktrace-parser'
import
type
{
ComponentStackFrame
}
from
'../internal/helpers/parse-component-stack'
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_OK
=
'build-ok'
export
const
TYPE_BUILD_ERROR
=
'build-error'
export
const
TYPE_BUILD_ERROR
=
'build-error'
...
@@ -7,6 +8,7 @@ export const TYPE_REFRESH = 'fast-refresh'
...
@@ -7,6 +8,7 @@ export const TYPE_REFRESH = 'fast-refresh'
export
const
TYPE_BEFORE_REFRESH
=
'before-fast-refresh'
export
const
TYPE_BEFORE_REFRESH
=
'before-fast-refresh'
export
const
TYPE_UNHANDLED_ERROR
=
'unhandled-error'
export
const
TYPE_UNHANDLED_ERROR
=
'unhandled-error'
export
const
TYPE_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
TYPE_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
TYPE_VERSION_INFO
=
'version-info'
export
type
BuildOk
=
{
type
:
typeof
TYPE_BUILD_OK
}
export
type
BuildOk
=
{
type
:
typeof
TYPE_BUILD_OK
}
export
type
BuildError
=
{
export
type
BuildError
=
{
...
@@ -26,6 +28,12 @@ export type UnhandledRejection = {
...
@@ -26,6 +28,12 @@ export type UnhandledRejection = {
reason
:
Error
reason
:
Error
frames
:
StackFrame
[]
frames
:
StackFrame
[]
}
}
export
type
VersionInfoEvent
=
{
type
:
typeof
TYPE_VERSION_INFO
versionInfo
:
VersionInfo
}
export
type
BusEvent
=
export
type
BusEvent
=
|
BuildOk
|
BuildOk
|
BuildError
|
BuildError
...
@@ -33,6 +41,7 @@ export type BusEvent =
...
@@ -33,6 +41,7 @@ export type BusEvent =
|
BeforeFastRefresh
|
BeforeFastRefresh
|
UnhandledError
|
UnhandledError
|
UnhandledRejection
|
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 @
0a73e898
...
@@ -5,6 +5,7 @@ import {
...
@@ -5,6 +5,7 @@ import {
hydrationErrorState
,
hydrationErrorState
,
patchConsoleError
,
patchConsoleError
,
}
from
'../internal/helpers/hydration-error-info'
}
from
'../internal/helpers/hydration-error-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
patchConsoleError
()
patchConsoleError
()
...
@@ -121,6 +122,10 @@ function onBeforeRefresh() {
...
@@ -121,6 +122,10 @@ function onBeforeRefresh() {
Bus
.
emit
({
type
:
Bus
.
TYPE_BEFORE_REFRESH
})
Bus
.
emit
({
type
:
Bus
.
TYPE_BEFORE_REFRESH
})
}
}
function
onVersionInfo
(
versionInfo
:
VersionInfo
)
{
Bus
.
emit
({
type
:
Bus
.
TYPE_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'
...
@@ -131,4 +136,5 @@ export {
...
@@ -131,4 +136,5 @@ export {
unregister
,
unregister
,
onBeforeRefresh
,
onBeforeRefresh
,
onRefresh
,
onRefresh
,
onVersionInfo
,
}
}
packages/next/src/client/dev/error-overlay/hot-dev-client.ts
View file @
0a73e898
...
@@ -34,6 +34,7 @@ import {
...
@@ -34,6 +34,7 @@ import {
onBuildOk
,
onBuildOk
,
onBeforeRefresh
,
onBeforeRefresh
,
onRefresh
,
onRefresh
,
onVersionInfo
,
}
from
'../../components/react-dev-overlay/pages/client'
}
from
'../../components/react-dev-overlay/pages/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'
...
@@ -278,6 +279,10 @@ function processMessage(obj: HMR_ACTION_TYPES) {
...
@@ -278,6 +279,10 @@ function processMessage(obj: HMR_ACTION_TYPES) {
}
}
const
{
errors
,
warnings
}
=
obj
const
{
errors
,
warnings
}
=
obj
// Is undefined when it's a 'built' event
if
(
'versionInfo'
in
obj
)
onVersionInfo
(
obj
.
versionInfo
)
const
hasErrors
=
Boolean
(
errors
&&
errors
.
length
)
const
hasErrors
=
Boolean
(
errors
&&
errors
.
length
)
if
(
hasErrors
)
{
if
(
hasErrors
)
{
sendMessage
(
sendMessage
(
...
...
test/development/basic/hmr.test.ts
View file @
0a73e898
...
@@ -5,6 +5,7 @@ import {
...
@@ -5,6 +5,7 @@ import {
check
,
check
,
getBrowserBodyText
,
getBrowserBodyText
,
getRedboxHeader
,
getRedboxHeader
,
getRedboxDescription
,
getRedboxSource
,
getRedboxSource
,
hasRedbox
,
hasRedbox
,
renderViaHTTP
,
renderViaHTTP
,
...
@@ -727,14 +728,9 @@ describe.each([[''], ['/docs']])(
...
@@ -727,14 +728,9 @@ describe.each([[''], ['/docs']])(
)
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatchInlineSnapshot
(
`
expect
(
await
getRedboxDescription
(
browser
)).
toMatchInlineSnapshot
(
"1 of 1 unhandled error
`"Error: The default export is not a React Component in page: "/hmr/about5""`
Server Error
)
Error: The default export is not a React Component in page: "/hmr/about5"
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
...
@@ -830,14 +826,9 @@ describe.each([[''], ['/docs']])(
...
@@ -830,14 +826,9 @@ describe.each([[''], ['/docs']])(
)
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatchInlineSnapshot
(
`
expect
(
await
getRedboxDescription
(
browser
)).
toMatchInlineSnapshot
(
"1 of 1 unhandled error
`"Error: The default export is not a React Component in page: "/hmr/about7""`
Server Error
)
Error: The default export is not a React Component in page: "/hmr/about7"
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
await
next
.
patchFile
(
aboutPage
,
aboutContent
)
...
@@ -885,9 +876,7 @@ describe.each([[''], ['/docs']])(
...
@@ -885,9 +876,7 @@ describe.each([[''], ['/docs']])(
)
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatchInlineSnapshot
(
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
'Failed to compile'
)
`"Failed to compile"`
)
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
expect
(
await
getRedboxSource
(
browser
)).
toMatchInlineSnapshot
(
`
"./components/parse-error.xyz
"./components/parse-error.xyz
Module parse failed: Unexpected token (3:0)
Module parse failed: Unexpected token (3:0)
...
@@ -949,9 +938,7 @@ describe.each([[''], ['/docs']])(
...
@@ -949,9 +938,7 @@ describe.each([[''], ['/docs']])(
)
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatchInlineSnapshot
(
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
'Failed to compile'
)
`"Failed to compile"`
)
let
redboxSource
=
await
getRedboxSource
(
browser
)
let
redboxSource
=
await
getRedboxSource
(
browser
)
redboxSource
=
redboxSource
.
replace
(
`
${
next
.
testDir
}
`
,
'.'
)
redboxSource
=
redboxSource
.
replace
(
`
${
next
.
testDir
}
`
,
'.'
)
...
@@ -1023,12 +1010,9 @@ describe.each([[''], ['/docs']])(
...
@@ -1023,12 +1010,9 @@ describe.each([[''], ['/docs']])(
await
browser
.
elementByCss
(
'#error-in-gip-link'
).
click
()
await
browser
.
elementByCss
(
'#error-in-gip-link'
).
click
()
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatchInlineSnapshot
(
`
expect
(
await
getRedboxDescription
(
browser
)).
toMatchInlineSnapshot
(
"1 of 1 unhandled error
`"Error: an-expected-error-in-gip"`
Unhandled Runtime Error
)
Error: an-expected-error-in-gip"
`
)
await
next
.
patchFile
(
await
next
.
patchFile
(
erroredPage
,
erroredPage
,
...
@@ -1067,14 +1051,9 @@ describe.each([[''], ['/docs']])(
...
@@ -1067,14 +1051,9 @@ describe.each([[''], ['/docs']])(
browser
=
await
webdriver
(
next
.
url
,
basePath
+
'/hmr/error-in-gip'
)
browser
=
await
webdriver
(
next
.
url
,
basePath
+
'/hmr/error-in-gip'
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatchInlineSnapshot
(
`
expect
(
await
getRedboxDescription
(
browser
)).
toMatchInlineSnapshot
(
"1 of 1 unhandled error
`"Error: an-expected-error-in-gip"`
Server Error
)
Error: an-expected-error-in-gip
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`
)
const
erroredPage
=
join
(
'pages'
,
'hmr'
,
'error-in-gip.js'
)
const
erroredPage
=
join
(
'pages'
,
'hmr'
,
'error-in-gip.js'
)
...
...
test/integration/next-image-new/invalid-image-import/test/index.test.ts
View file @
0a73e898
...
@@ -23,7 +23,7 @@ function runTests({ isDev }) {
...
@@ -23,7 +23,7 @@ function runTests({ isDev }) {
if
(
isDev
)
{
if
(
isDev
)
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
const
browser
=
await
webdriver
(
appPort
,
'/'
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
hasRedbox
(
browser
)).
toBe
(
true
)
expect
(
await
getRedboxHeader
(
browser
)).
to
Be
(
'Failed to compile'
)
expect
(
await
getRedboxHeader
(
browser
)).
to
Match
(
'Failed to compile'
)
const
source
=
await
getRedboxSource
(
browser
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
process
.
env
.
TURBOPACK
)
{
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
source
).
toMatchInlineSnapshot
(
`
expect
(
source
).
toMatchInlineSnapshot
(
`
...
...
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