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
10928dfa
Unverified
Commit
10928dfa
authored
Jun 04, 2025
by
Jiachi Liu
Committed by
GitHub
Jun 04, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[global-not-found] fix shared css imports not being picked (#80151)
parent
1a188847
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
108 additions
and
9 deletions
+108
-9
flight-client-entry-plugin.ts
...t/src/build/webpack/plugins/flight-client-entry-plugin.ts
+21
-9
page.tsx
.../app-dir/global-not-found/css/app/call-not-found/page.tsx
+7
-0
client.tsx
test/e2e/app-dir/global-not-found/css/app/client.tsx
+5
-0
global-not-found.css
...e2e/app-dir/global-not-found/css/app/global-not-found.css
+3
-0
global-not-found.tsx
...e2e/app-dir/global-not-found/css/app/global-not-found.tsx
+17
-0
global.css
test/e2e/app-dir/global-not-found/css/app/global.css
+3
-0
layout.tsx
test/e2e/app-dir/global-not-found/css/app/layout.tsx
+16
-0
page.tsx
test/e2e/app-dir/global-not-found/css/app/page.tsx
+3
-0
global-not-found-css.test.ts
...app-dir/global-not-found/css/global-not-found-css.test.ts
+23
-0
next.config.js
test/e2e/app-dir/global-not-found/css/next.config.js
+10
-0
No files found.
packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts
View file @
10928dfa
...
@@ -108,6 +108,9 @@ const pluginState = getProxiedPluginState({
...
@@ -108,6 +108,9 @@ const pluginState = getProxiedPluginState({
injectedClientEntries
:
{}
as
Record
<
string
,
string
>
,
injectedClientEntries
:
{}
as
Record
<
string
,
string
>
,
})
})
const
POSSIBLE_SHARED_CONVENTIONS
=
[
'template'
,
'layout'
]
const
STANDALONE_BUNDLE_CONVENTION
=
'global-not-found'
function
deduplicateCSSImportsForEntry
(
mergedCSSimports
:
CssImports
)
{
function
deduplicateCSSImportsForEntry
(
mergedCSSimports
:
CssImports
)
{
// If multiple entry module connections are having the same CSS import,
// If multiple entry module connections are having the same CSS import,
// we only need to have one module to keep track of that CSS import.
// we only need to have one module to keep track of that CSS import.
...
@@ -138,8 +141,8 @@ function deduplicateCSSImportsForEntry(mergedCSSimports: CssImports) {
...
@@ -138,8 +141,8 @@ function deduplicateCSSImportsForEntry(mergedCSSimports: CssImports) {
const
aName
=
path
.
parse
(
aPath
).
name
const
aName
=
path
.
parse
(
aPath
).
name
const
bName
=
path
.
parse
(
bPath
).
name
const
bName
=
path
.
parse
(
bPath
).
name
const
indexA
=
[
'template'
,
'layout'
]
.
indexOf
(
aName
)
const
indexA
=
POSSIBLE_SHARED_CONVENTIONS
.
indexOf
(
aName
)
const
indexB
=
[
'template'
,
'layout'
]
.
indexOf
(
bName
)
const
indexB
=
POSSIBLE_SHARED_CONVENTIONS
.
indexOf
(
bName
)
if
(
indexA
===
-
1
)
return
1
if
(
indexA
===
-
1
)
return
1
if
(
indexB
===
-
1
)
return
-
1
if
(
indexB
===
-
1
)
return
-
1
...
@@ -148,20 +151,29 @@ function deduplicateCSSImportsForEntry(mergedCSSimports: CssImports) {
...
@@ -148,20 +151,29 @@ function deduplicateCSSImportsForEntry(mergedCSSimports: CssImports) {
const
dedupedCSSImports
:
CssImports
=
{}
const
dedupedCSSImports
:
CssImports
=
{}
const
trackedCSSImports
=
new
Set
<
string
>
()
const
trackedCSSImports
=
new
Set
<
string
>
()
for
(
const
[
entryName
,
cssImports
]
of
sortedCSSImports
)
{
for
(
const
[
entryFilePath
,
cssImports
]
of
sortedCSSImports
)
{
const
entryConventionName
=
path
.
parse
(
entryFilePath
).
name
for
(
const
cssImport
of
cssImports
)
{
for
(
const
cssImport
of
cssImports
)
{
if
(
trackedCSSImports
.
has
(
cssImport
))
continue
// If the CSS import is already tracked, we can skip it.
// Or if it's any standalone entry such as `global-not-found`, it won't share any resources with other entry, skip it.
if
(
trackedCSSImports
.
has
(
cssImport
)
&&
STANDALONE_BUNDLE_CONVENTION
!==
entryConventionName
)
{
continue
}
// Only track CSS imports that are in files that can inherit CSS.
// Only track CSS imports that are in files that can inherit CSS.
const
filename
=
path
.
parse
(
entryName
).
name
if
(
POSSIBLE_SHARED_CONVENTIONS
.
includes
(
entryConventionName
))
{
if
([
'template'
,
'layout'
].
includes
(
filename
))
{
trackedCSSImports
.
add
(
cssImport
)
trackedCSSImports
.
add
(
cssImport
)
}
}
if
(
!
dedupedCSSImports
[
entry
Name
])
{
if
(
!
dedupedCSSImports
[
entry
FilePath
])
{
dedupedCSSImports
[
entry
Name
]
=
[]
dedupedCSSImports
[
entry
FilePath
]
=
[]
}
}
dedupedCSSImports
[
entry
Name
].
push
(
cssImport
)
dedupedCSSImports
[
entry
FilePath
].
push
(
cssImport
)
}
}
}
}
...
...
test/e2e/app-dir/global-not-found/css/app/call-not-found/page.tsx
0 → 100644
View file @
10928dfa
'use client'
import
{
notFound
}
from
'next/navigation'
export
default
function
Page
()
{
notFound
()
}
test/e2e/app-dir/global-not-found/css/app/client.tsx
0 → 100644
View file @
10928dfa
'use client'
export
function
Client
()
{
return
<
div
id=
"client"
>
client
</
div
>
}
test/e2e/app-dir/global-not-found/css/app/global-not-found.css
0 → 100644
View file @
10928dfa
.blue-text
{
color
:
rgb
(
0
,
0
,
255
);
}
test/e2e/app-dir/global-not-found/css/app/global-not-found.tsx
0 → 100644
View file @
10928dfa
import
{
Client
}
from
'./client'
import
'./global.css'
import
'./global-not-found.css'
export
default
function
GlobalNotFound
()
{
return
(
// html tag is different from actual page's layout
<
html
data
-
global
-
not
-
found=
"true"
>
<
body
>
<
h1
id=
"global-error-title"
>
global-not-found
</
h1
>
<
Client
/>
<
p
className=
"orange-text"
>
orange text (from global.css)
</
p
>
<
p
className=
"blue-text"
>
blue text (from global-not-found.css)
</
p
>
</
body
>
</
html
>
)
}
test/e2e/app-dir/global-not-found/css/app/global.css
0 → 100644
View file @
10928dfa
.orange-text
{
color
:
rgb
(
255
,
165
,
0
);
}
test/e2e/app-dir/global-not-found/css/app/layout.tsx
0 → 100644
View file @
10928dfa
import
'./global.css'
export
default
function
RootLayout
({
children
,
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
lang=
"en"
>
<
body
>
{
children
}
</
body
>
<
footer
>
<
p
className=
"orange-text"
>
layout footer orange text
</
p
>
</
footer
>
</
html
>
)
}
test/e2e/app-dir/global-not-found/css/app/page.tsx
0 → 100644
View file @
10928dfa
export
default
function
Page
()
{
return
<
p
>
hello world
</
p
>
}
test/e2e/app-dir/global-not-found/css/global-not-found-css.test.ts
0 → 100644
View file @
10928dfa
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'global-not-found - css'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should include css for global-not-found properly'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/does-not-exist'
)
// This css import is shared with `/` route's layout
const
textColorOrange
=
await
browser
.
elementByCss
(
'.orange-text'
)
.
getComputedCss
(
'color'
)
expect
(
textColorOrange
).
toBe
(
'rgb(255, 165, 0)'
)
// This css import is only used in the global-not-found convention
const
textColorRed
=
await
browser
.
elementByCss
(
'.blue-text'
)
.
getComputedCss
(
'color'
)
expect
(
textColorRed
).
toBe
(
'rgb(0, 0, 255)'
)
})
})
test/e2e/app-dir/global-not-found/css/next.config.js
0 → 100644
View file @
10928dfa
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
experimental
:
{
globalNotFound
:
true
,
},
}
module
.
exports
=
nextConfig
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