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
a3918569
Unverified
Commit
a3918569
authored
Oct 28, 2024
by
Jude Gao
Committed by
GitHub
Oct 28, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix global-error styles (#71914)
parent
655b808c
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
108 additions
and
10 deletions
+108
-10
app_page_loader_tree.rs
crates/next-core/src/app_page_loader_tree.rs
+3
-1
base_loader_tree.rs
crates/next-core/src/base_loader_tree.rs
+2
-0
index.ts
...s/next/src/build/webpack/loaders/next-app-loader/index.ts
+1
-0
app-index.tsx
packages/next/src/client/app-index.tsx
+1
-1
app-router.tsx
packages/next/src/client/components/app-router.tsx
+6
-3
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+33
-4
types.ts
packages/next/src/server/app-render/types.ts
+1
-1
global-error.tsx
...p-dir/global-error/with-style-import/app/global-error.tsx
+13
-0
global.css
...e2e/app-dir/global-error/with-style-import/app/global.css
+3
-0
layout.tsx
...e2e/app-dir/global-error/with-style-import/app/layout.tsx
+12
-0
page.tsx
test/e2e/app-dir/global-error/with-style-import/app/page.tsx
+3
-0
index.test.ts
.../e2e/app-dir/global-error/with-style-import/index.test.ts
+30
-0
No files found.
crates/next-core/src/app_page_loader_tree.rs
View file @
a3918569
...
@@ -311,7 +311,7 @@ impl AppPageLoaderTreeBuilder {
...
@@ -311,7 +311,7 @@ impl AppPageLoaderTreeBuilder {
page
,
page
,
default
,
default
,
error
,
error
,
global_error
:
_
,
global_error
,
layout
,
layout
,
loading
,
loading
,
template
,
template
,
...
@@ -344,6 +344,8 @@ impl AppPageLoaderTreeBuilder {
...
@@ -344,6 +344,8 @@ impl AppPageLoaderTreeBuilder {
.await
?
;
.await
?
;
self
.write_modules_entry
(
AppDirModuleType
::
DefaultPage
,
*
default
)
self
.write_modules_entry
(
AppDirModuleType
::
DefaultPage
,
*
default
)
.await
?
;
.await
?
;
self
.write_modules_entry
(
AppDirModuleType
::
GlobalError
,
*
global_error
)
.await
?
;
let
modules_code
=
replace
(
&
mut
self
.loader_tree_code
,
temp_loader_tree_code
);
let
modules_code
=
replace
(
&
mut
self
.loader_tree_code
,
temp_loader_tree_code
);
...
...
crates/next-core/src/base_loader_tree.rs
View file @
a3918569
...
@@ -28,6 +28,7 @@ pub enum AppDirModuleType {
...
@@ -28,6 +28,7 @@ pub enum AppDirModuleType {
Loading
,
Loading
,
Template
,
Template
,
NotFound
,
NotFound
,
GlobalError
,
}
}
impl
AppDirModuleType
{
impl
AppDirModuleType
{
...
@@ -40,6 +41,7 @@ impl AppDirModuleType {
...
@@ -40,6 +41,7 @@ impl AppDirModuleType {
AppDirModuleType
::
Loading
=>
"loading"
,
AppDirModuleType
::
Loading
=>
"loading"
,
AppDirModuleType
::
Template
=>
"template"
,
AppDirModuleType
::
Template
=>
"template"
,
AppDirModuleType
::
NotFound
=>
"not-found"
,
AppDirModuleType
::
NotFound
=>
"not-found"
,
AppDirModuleType
::
GlobalError
=>
"global-error"
,
}
}
}
}
}
}
...
...
packages/next/src/build/webpack/loaders/next-app-loader/index.ts
View file @
a3918569
...
@@ -60,6 +60,7 @@ const FILE_TYPES = {
...
@@ -60,6 +60,7 @@ const FILE_TYPES = {
error
:
'error'
,
error
:
'error'
,
loading
:
'loading'
,
loading
:
'loading'
,
'not-found'
:
'not-found'
,
'not-found'
:
'not-found'
,
'global-error'
:
'global-error'
,
}
as
const
}
as
const
const
GLOBAL_ERROR_FILE_TYPE
=
'global-error'
const
GLOBAL_ERROR_FILE_TYPE
=
'global-error'
...
...
packages/next/src/client/app-index.tsx
View file @
a3918569
...
@@ -183,7 +183,7 @@ function ServerRoot(): React.ReactNode {
...
@@ -183,7 +183,7 @@ function ServerRoot(): React.ReactNode {
const
router
=
(
const
router
=
(
<
AppRouter
<
AppRouter
actionQueue=
{
actionQueue
}
actionQueue=
{
actionQueue
}
globalErrorComponent=
{
initialRSCPayload
.
G
}
globalErrorComponent
AndStyles
=
{
initialRSCPayload
.
G
}
assetPrefix=
{
initialRSCPayload
.
p
}
assetPrefix=
{
initialRSCPayload
.
p
}
/>
/>
)
)
...
...
packages/next/src/client/components/app-router.tsx
View file @
a3918569
...
@@ -622,17 +622,20 @@ function Router({
...
@@ -622,17 +622,20 @@ function Router({
export
default
function
AppRouter
({
export
default
function
AppRouter
({
actionQueue
,
actionQueue
,
globalErrorComponent
,
globalErrorComponent
AndStyles
:
[
globalErrorComponent
,
globalErrorStyles
]
,
assetPrefix
,
assetPrefix
,
}:
{
}:
{
actionQueue
:
AppRouterActionQueue
actionQueue
:
AppRouterActionQueue
globalErrorComponent
:
ErrorComponent
globalErrorComponent
AndStyles
:
[
ErrorComponent
,
React
.
ReactNode
|
undefined
]
assetPrefix
:
string
assetPrefix
:
string
})
{
})
{
useNavFailureHandler
()
useNavFailureHandler
()
return
(
return
(
<
ErrorBoundary
errorComponent=
{
globalErrorComponent
}
>
<
ErrorBoundary
errorComponent=
{
globalErrorComponent
}
errorStyles=
{
globalErrorStyles
}
>
<
Router
actionQueue=
{
actionQueue
}
assetPrefix=
{
assetPrefix
}
/>
<
Router
actionQueue=
{
actionQueue
}
assetPrefix=
{
assetPrefix
}
/>
</
ErrorBoundary
>
</
ErrorBoundary
>
)
)
...
...
packages/next/src/server/app-render/app-render.tsx
View file @
a3918569
...
@@ -161,6 +161,8 @@ import { InvariantError } from '../../shared/lib/invariant-error'
...
@@ -161,6 +161,8 @@ import { InvariantError } from '../../shared/lib/invariant-error'
import
'./clean-async-snapshot.external'
import
'./clean-async-snapshot.external'
import
{
INFINITE_CACHE
}
from
'../../lib/constants'
import
{
INFINITE_CACHE
}
from
'../../lib/constants'
import
{
createComponentStylesAndScripts
}
from
'./create-component-styles-and-scripts'
import
{
parseLoaderTree
}
from
'./parse-loader-tree'
export
type
GetDynamicParamFromSegment
=
(
export
type
GetDynamicParamFromSegment
=
(
// [slug] / [[slug]] / [...slug]
// [slug] / [[slug]] / [...slug]
...
@@ -723,6 +725,8 @@ async function getRSCPayload(
...
@@ -723,6 +725,8 @@ async function getRSCPayload(
</
React
.
Fragment
>
</
React
.
Fragment
>
)
)
const
globalErrorStyles
=
await
getGlobalErrorStyles
(
tree
,
ctx
)
return
{
return
{
// See the comment above the `Preloads` component (below) for why this is part of the payload
// See the comment above the `Preloads` component (below) for why this is part of the payload
P
:
<
Preloads
preloadCallbacks=
{
preloadCallbacks
}
/>,
P
:
<
Preloads
preloadCallbacks=
{
preloadCallbacks
}
/>,
...
@@ -732,7 +736,7 @@ async function getRSCPayload(
...
@@ -732,7 +736,7 @@ async function getRSCPayload(
i
:
!!
couldBeIntercepted
,
i
:
!!
couldBeIntercepted
,
f
:
[[
initialTree
,
seedData
,
initialHead
]],
f
:
[[
initialTree
,
seedData
,
initialHead
]],
m
:
missingSlots
,
m
:
missingSlots
,
G
:
GlobalError
,
G
:
[
GlobalError
,
globalErrorStyles
]
,
s
:
typeof
ctx
.
renderOpts
.
postponed
===
'string'
,
s
:
typeof
ctx
.
renderOpts
.
postponed
===
'string'
,
S
:
workStore
.
isStaticGeneration
,
S
:
workStore
.
isStaticGeneration
,
}
}
...
@@ -817,6 +821,8 @@ async function getErrorRSCPayload(
...
@@ -817,6 +821,8 @@ async function getErrorRSCPayload(
null
,
null
,
]
]
const
globalErrorStyles
=
await
getGlobalErrorStyles
(
tree
,
ctx
)
return
{
return
{
b
:
ctx
.
renderOpts
.
buildId
,
b
:
ctx
.
renderOpts
.
buildId
,
p
:
ctx
.
assetPrefix
,
p
:
ctx
.
assetPrefix
,
...
@@ -824,7 +830,7 @@ async function getErrorRSCPayload(
...
@@ -824,7 +830,7 @@ async function getErrorRSCPayload(
m
:
undefined
,
m
:
undefined
,
i
:
false
,
i
:
false
,
f
:
[[
initialTree
,
initialSeedData
,
initialHead
]],
f
:
[[
initialTree
,
initialSeedData
,
initialHead
]],
G
:
GlobalError
,
G
:
[
GlobalError
,
globalErrorStyles
]
,
s
:
typeof
ctx
.
renderOpts
.
postponed
===
'string'
,
s
:
typeof
ctx
.
renderOpts
.
postponed
===
'string'
,
S
:
workStore
.
isStaticGeneration
,
S
:
workStore
.
isStaticGeneration
,
}
satisfies
InitialRSCPayload
}
satisfies
InitialRSCPayload
...
@@ -881,7 +887,7 @@ function App<T>({
...
@@ -881,7 +887,7 @@ function App<T>({
<
ServerInsertedHTMLProvider
>
<
ServerInsertedHTMLProvider
>
<
AppRouter
<
AppRouter
actionQueue=
{
actionQueue
}
actionQueue=
{
actionQueue
}
globalErrorComponent=
{
response
.
G
}
globalErrorComponent
AndStyles
=
{
response
.
G
}
assetPrefix=
{
response
.
p
}
assetPrefix=
{
response
.
p
}
/>
/>
</
ServerInsertedHTMLProvider
>
</
ServerInsertedHTMLProvider
>
...
@@ -930,7 +936,7 @@ function AppWithoutContext<T>({
...
@@ -930,7 +936,7 @@ function AppWithoutContext<T>({
return
(
return
(
<
AppRouter
<
AppRouter
actionQueue=
{
actionQueue
}
actionQueue=
{
actionQueue
}
globalErrorComponent=
{
response
.
G
}
globalErrorComponent
AndStyles
=
{
response
.
G
}
assetPrefix=
{
response
.
p
}
assetPrefix=
{
response
.
p
}
/>
/>
)
)
...
@@ -3822,3 +3828,26 @@ export async function warmFlightResponse(
...
@@ -3822,3 +3828,26 @@ export async function warmFlightResponse(
chunkListeners
.
push
(
r
)
chunkListeners
.
push
(
r
)
})
})
}
}
const
getGlobalErrorStyles
=
async
(
tree
:
LoaderTree
,
ctx
:
AppRenderContext
):
Promise
<
React
.
ReactNode
|
undefined
>
=>
{
const
{
modules
:
{
'global-error'
:
globalErrorModule
},
}
=
parseLoaderTree
(
tree
)
let
globalErrorStyles
if
(
globalErrorModule
)
{
const
[,
styles
]
=
await
createComponentStylesAndScripts
({
ctx
,
filePath
:
globalErrorModule
[
1
],
getComponent
:
globalErrorModule
[
0
],
injectedCSS
:
new
Set
(),
injectedJS
:
new
Set
(),
})
globalErrorStyles
=
styles
}
return
globalErrorStyles
}
packages/next/src/server/app-render/types.ts
View file @
a3918569
...
@@ -226,7 +226,7 @@ export type InitialRSCPayload = {
...
@@ -226,7 +226,7 @@ export type InitialRSCPayload = {
/** missingSlots */
/** missingSlots */
m
:
Set
<
string
>
|
undefined
m
:
Set
<
string
>
|
undefined
/** GlobalError */
/** GlobalError */
G
:
React
.
ComponentType
<
any
>
G
:
[
React
.
ComponentType
<
any
>
,
React
.
ReactNode
|
undefined
]
/** postponed */
/** postponed */
s
:
boolean
s
:
boolean
/** prerendered */
/** prerendered */
...
...
test/e2e/app-dir/global-error/with-style-import/app/global-error.tsx
0 → 100644
View file @
a3918569
'use client'
import
'./global.css'
export
default
function
GlobalError
()
{
return
(
<
html
>
<
body
>
<
h2
>
Error!
</
h2
>
</
body
>
</
html
>
)
}
test/e2e/app-dir/global-error/with-style-import/app/global.css
0 → 100644
View file @
a3918569
h2
{
color
:
yellow
;
}
test/e2e/app-dir/global-error/with-style-import/app/layout.tsx
0 → 100644
View file @
a3918569
// to avoid bailing out of the build
export
const
dynamic
=
'force-dynamic'
export
default
function
RootLayout
({
children
})
{
throw
new
Error
(
'Root Layout Error'
)
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/global-error/with-style-import/app/page.tsx
0 → 100644
View file @
a3918569
export
default
function
Home
()
{
return
<
p
>
Home
</
p
>
}
test/e2e/app-dir/global-error/with-style-import/index.test.ts
0 → 100644
View file @
a3918569
import
{
assertHasRedbox
,
getRedboxHeader
}
from
'next-test-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
async
function
testDev
(
browser
,
errorRegex
)
{
await
assertHasRedbox
(
browser
)
expect
(
await
getRedboxHeader
(
browser
)).
toMatch
(
errorRegex
)
}
describe
(
'app dir - global error - with style import'
,
()
=>
{
const
{
next
,
isNextDev
,
skipped
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
})
if
(
skipped
)
{
return
}
it
(
'should render global error with correct styles'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
if
(
isNextDev
)
{
await
testDev
(
browser
,
/Root Layout Error/
)
return
}
const
h2
=
await
browser
.
elementByCss
(
'h2'
)
expect
(
await
h2
.
getComputedCss
(
'color'
)).
toBe
(
'rgb(255, 255, 0)'
)
// yellow
})
})
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