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
984bd77b
Unverified
Commit
984bd77b
authored
Oct 28, 2022
by
Shu Ding
Committed by
GitHub
Oct 28, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix css modules imports in client components (#42077)
parent
80843e1a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
6 deletions
+71
-6
flight-client-entry-plugin.ts
.../next/build/webpack/plugins/flight-client-entry-plugin.ts
+40
-6
ClientComponent.module.css
...r/app/app/css/css-client/inner/ClientComponent.module.css
+3
-0
foo.js
test/e2e/app-dir/app/app/css/css-client/inner/foo.js
+11
-0
page.js
test/e2e/app-dir/app/app/css/css-client/inner/page.js
+5
-0
index.test.ts
test/e2e/app-dir/index.test.ts
+12
-0
No files found.
packages/next/build/webpack/plugins/flight-client-entry-plugin.ts
View file @
984bd77b
...
@@ -276,7 +276,31 @@ export class FlightClientEntryPlugin {
...
@@ -276,7 +276,31 @@ export class FlightClientEntryPlugin {
})
})
})
})
forEachEntryModule
(({
entryModule
})
=>
{
forEachEntryModule
(({
name
,
entryModule
})
=>
{
// To collect all CSS imports for a specific entry including the ones
// that are in the client graph, we need to store a map for client boundary
// dependencies.
const
clientEntryDependencyMap
:
Record
<
string
,
any
>
=
{}
const
entry
=
compilation
.
entries
.
get
(
name
)
entry
.
includeDependencies
.
forEach
((
dep
:
any
)
=>
{
if
(
dep
.
request
&&
dep
.
request
.
startsWith
(
'next-flight-client-entry-loader?'
)
)
{
const
mod
:
webpack
.
NormalModule
=
compilation
.
moduleGraph
.
getResolvedModule
(
dep
)
compilation
.
moduleGraph
.
getOutgoingConnections
(
mod
)
.
forEach
((
connection
:
any
)
=>
{
if
(
connection
.
dependency
)
{
clientEntryDependencyMap
[
connection
.
dependency
.
request
]
=
connection
.
dependency
}
})
}
})
for
(
const
connection
of
compilation
.
moduleGraph
.
getOutgoingConnections
(
for
(
const
connection
of
compilation
.
moduleGraph
.
getOutgoingConnections
(
entryModule
entryModule
))
{
))
{
...
@@ -288,6 +312,7 @@ export class FlightClientEntryPlugin {
...
@@ -288,6 +312,7 @@ export class FlightClientEntryPlugin {
layoutOrPageRequest
,
layoutOrPageRequest
,
compilation
,
compilation
,
dependency
:
layoutOrPageDependency
,
dependency
:
layoutOrPageDependency
,
clientEntryDependencyMap
,
})
})
Object
.
assign
(
flightCSSManifest
,
cssImports
)
Object
.
assign
(
flightCSSManifest
,
cssImports
)
...
@@ -327,10 +352,12 @@ export class FlightClientEntryPlugin {
...
@@ -327,10 +352,12 @@ export class FlightClientEntryPlugin {
layoutOrPageRequest
,
layoutOrPageRequest
,
compilation
,
compilation
,
dependency
,
dependency
,
clientEntryDependencyMap
,
}:
{
}:
{
layoutOrPageRequest
:
string
layoutOrPageRequest
:
string
compilation
:
any
compilation
:
any
dependency
:
any
/* Dependency */
dependency
:
any
/* Dependency */
clientEntryDependencyMap
?:
Record
<
string
,
any
>
}):
[
ClientComponentImports
,
CssImports
]
{
}):
[
ClientComponentImports
,
CssImports
]
{
/**
/**
* Keep track of checked modules to avoid infinite loops with recursive imports.
* Keep track of checked modules to avoid infinite loops with recursive imports.
...
@@ -369,13 +396,12 @@ export class FlightClientEntryPlugin {
...
@@ -369,13 +396,12 @@ export class FlightClientEntryPlugin {
if
(
!
visitedBySegment
[
layoutOrPageRequest
])
{
if
(
!
visitedBySegment
[
layoutOrPageRequest
])
{
visitedBySegment
[
layoutOrPageRequest
]
=
new
Set
()
visitedBySegment
[
layoutOrPageRequest
]
=
new
Set
()
}
}
if
(
const
storeKey
=
!
modRequest
||
(
inClientComponentBoundary
?
'0'
:
'1'
)
+
':'
+
modRequest
visitedBySegment
[
layoutOrPageRequest
].
has
(
modRequest
)
if
(
!
modRequest
||
visitedBySegment
[
layoutOrPageRequest
].
has
(
storeKey
))
{
)
{
return
return
}
}
visitedBySegment
[
layoutOrPageRequest
].
add
(
modRequest
)
visitedBySegment
[
layoutOrPageRequest
].
add
(
storeKey
)
const
isClientComponent
=
isClientComponentModule
(
mod
)
const
isClientComponent
=
isClientComponentModule
(
mod
)
...
@@ -404,6 +430,14 @@ export class FlightClientEntryPlugin {
...
@@ -404,6 +430,14 @@ export class FlightClientEntryPlugin {
if
((
!
inClientComponentBoundary
&&
isClientComponent
)
||
isCSS
)
{
if
((
!
inClientComponentBoundary
&&
isClientComponent
)
||
isCSS
)
{
clientComponentImports
.
push
(
modRequest
)
clientComponentImports
.
push
(
modRequest
)
// Here we are entering a client boundary, and we need to collect dependencies
// in the client graph too.
if
(
isClientComponent
&&
clientEntryDependencyMap
)
{
if
(
clientEntryDependencyMap
[
modRequest
])
{
filterClientComponents
(
clientEntryDependencyMap
[
modRequest
],
true
)
}
}
return
return
}
}
...
...
test/e2e/app-dir/app/app/css/css-client/inner/ClientComponent.module.css
0 → 100644
View file @
984bd77b
.yuge
{
font-size
:
100px
;
}
test/e2e/app-dir/app/app/css/css-client/inner/foo.js
0 → 100644
View file @
984bd77b
'use client'
import
styles
from
'./ClientComponent.module.css'
export
default
function
ClientComponent
()
{
return
(
<
div
id
=
"client-component"
className
=
{
styles
.
yuge
}
>
Client
Component
<
/div
>
)
}
test/e2e/app-dir/app/app/css/css-client/inner/page.js
0 → 100644
View file @
984bd77b
import
Foo
from
'./foo'
export
default
function
Page
()
{
return
<
Foo
/>
}
test/e2e/app-dir/index.test.ts
View file @
984bd77b
...
@@ -1407,6 +1407,18 @@ describe('app dir', () => {
...
@@ -1407,6 +1407,18 @@ describe('app dir', () => {
).
toBe
(
'rgb(0, 0, 255)'
)
).
toBe
(
'rgb(0, 0, 255)'
)
})
})
})
})
describe
(
'client components'
,
()
=>
{
it
(
'should support css modules inside client components'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/css/css-client/inner'
)
expect
(
await
browser
.
eval
(
`window.getComputedStyle(document.querySelector('#client-component')).fontSize`
)
).
toBe
(
'100px'
)
})
})
})
})
describe
(
'searchParams prop'
,
()
=>
{
describe
(
'searchParams prop'
,
()
=>
{
...
...
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