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
7eb53237
Commit
7eb53237
authored
Apr 15, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Still add marker module for CSS modules
parent
8818b373
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
33 deletions
+80
-33
app.rs
crates/next-api/src/app.rs
+28
-15
css_client_reference_transition.rs
...e/css_client_reference/css_client_reference_transition.rs
+41
-11
transforms.rs
crates/next-core/src/next_server/transforms.rs
+3
-1
reference_type.rs
turbopack/crates/turbopack-core/src/reference_type.rs
+5
-3
module_asset.rs
turbopack/crates/turbopack-css/src/module_asset.rs
+2
-2
mod.rs
turbopack/crates/turbopack/src/module_options/mod.rs
+1
-1
No files found.
crates/next-api/src/app.rs
View file @
7eb53237
...
...
@@ -374,11 +374,16 @@ impl AppProject {
#[turbo_tasks
::
function]
pub
fn
css_client_reference_transition
(
self
:
Vc
<
Self
>
)
->
Vc
<
Box
<
dyn
Transition
>>
{
Vc
::
upcast
(
NextCssClientReferenceTransition
::
new
(
Vc
::
upcast
(
Vc
::
upcast
(
NextCssClientReferenceTransition
::
new
_client
(
Vc
::
upcast
(
self
.client_transition
(),
)))
}
#[turbo_tasks
::
function]
pub
fn
css_client_reference_marker_transition
(
self
:
Vc
<
Self
>
)
->
Vc
<
Box
<
dyn
Transition
>>
{
Vc
::
upcast
(
NextCssClientReferenceTransition
::
new_marker
())
}
#[turbo_tasks
::
function]
async
fn
get_rsc_transitions
(
self
:
Vc
<
Self
>
,
...
...
@@ -417,24 +422,14 @@ impl AppProject {
.into_iter
()
.collect
(),
transition_rules
:
vec!
[
// Mark as client reference (and exclude from RSC chunking) the edge from the
// CSS Module to the actual CSS
TransitionRule
::
new_internal
(
RuleCondition
::
all
(
vec!
[
RuleCondition
::
ReferenceType
(
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
,
)),
module_styles_rule_condition
(),
]),
ResolvedVc
::
upcast
(
self
.css_client_reference_transition
()
.to_resolved
()
.await
?
),
),
// Don't wrap in marker module but change context, this is used to determine
// the list of CSS module classes.
// CSS Modules should be in the client layer but, the JS CSS Module should not be
// wrapped in the CssClientReferenceModule
TransitionRule
::
new
(
module_styles_rule_condition
(),
ResolvedVc
::
upcast
(
self
.client_transition
()
.to_resolved
()
.await
?
),
),
// Mark as client reference all regular CSS imports
// Mark all regular CSS imports as client reference (transition and wrap
// CssClientReferenceModule)
TransitionRule
::
new
(
styles_rule_condition
(),
ResolvedVc
::
upcast
(
self
.css_client_reference_transition
()
.to_resolved
()
.await
?
),
...
...
@@ -596,6 +591,24 @@ impl AppProject {
Ok
(
ModuleAssetContext
::
new
(
TransitionOptions
{
named_transitions
:
transitions
,
transition_rules
:
vec!
[
// The edge from the JS CSS Module to the actual CSS styles module should be
// wrapped with a CssClientReferenceModule to mark it as a client reference
// (and exclude it from RSC chunking).
TransitionRule
::
new_internal
(
RuleCondition
::
all
(
vec!
[
RuleCondition
::
ReferenceType
(
ReferenceType
::
Css
(
CssReferenceSubType
::
ModuleStyles
,
)),
module_styles_rule_condition
(),
]),
ResolvedVc
::
upcast
(
self
.css_client_reference_marker_transition
()
.to_resolved
()
.await
?
,
),
),
],
..
Default
::
default
()
}
.cell
(),
...
...
crates/next-core/src/next_client_reference/css_client_reference/css_client_reference_transition.rs
View file @
7eb53237
use
anyhow
::{
Context
,
Result
};
use
turbo_tasks
::{
ResolvedVc
,
Vc
};
use
turbopack
::{
ModuleAssetContext
,
css
::
chunk
::
CssChunkPlaceable
,
transition
::
Transition
};
use
turbopack_core
::{
context
::
ProcessResult
,
reference_type
::
ReferenceType
,
source
::
Source
};
use
turbopack_core
::{
context
::{
AssetContext
,
ProcessResult
},
reference_type
::{
CssReferenceSubType
,
ReferenceType
},
source
::
Source
,
};
use
crate
::
next_client_reference
::
css_client_reference
::
css_client_reference_module
::
CssClientReferenceModule
;
#[turbo_tasks
::
value(shared)]
pub
struct
NextCssClientReferenceTransition
{
client_transition
:
ResolvedVc
<
Box
<
dyn
Transition
>>
,
client_transition
:
Option
<
ResolvedVc
<
Box
<
dyn
Transition
>
>>
,
}
#[turbo_tasks
::
value_impl]
impl
NextCssClientReferenceTransition
{
/// Create a transition that only add a marker `CssClientReferenceModule`.
#[turbo_tasks
::
function]
pub
fn
new
(
client_transition
:
ResolvedVc
<
Box
<
dyn
Transition
>>
)
->
Vc
<
Self
>
{
NextCssClientReferenceTransition
{
client_transition
}
.cell
()
pub
fn
new_marker
()
->
Vc
<
Self
>
{
NextCssClientReferenceTransition
{
client_transition
:
None
,
}
.cell
()
}
/// Create a transition that applies `client_transiton` and adds a marker
/// `CssClientReferenceModule`.
#[turbo_tasks
::
function]
pub
fn
new_client
(
client_transition
:
ResolvedVc
<
Box
<
dyn
Transition
>>
)
->
Vc
<
Self
>
{
NextCssClientReferenceTransition
{
client_transition
:
Some
(
client_transition
),
}
.cell
()
}
}
...
...
@@ -25,15 +43,27 @@ impl Transition for NextCssClientReferenceTransition {
self
:
Vc
<
Self
>
,
original_source
:
Vc
<
Box
<
dyn
Source
>>
,
source
:
Vc
<
Box
<
dyn
Source
>>
,
rsc_
module_asset_context
:
Vc
<
ModuleAssetContext
>
,
module_asset_context
:
Vc
<
ModuleAssetContext
>
,
reference_type
:
ReferenceType
,
)
->
Result
<
Vc
<
ProcessResult
>>
{
let
module
=
self
.await
?
.client_transition
.process
(
original_source
,
source
,
rsc_module_asset_context
,
reference_type
,
);
let
new_reference_type
=
match
reference_type
{
ReferenceType
::
Css
(
CssReferenceSubType
::
ModuleStyles
)
=>
{
// Prevent an infinite loop since this transition matches on the
// InternalModuleStyles reference type
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
)
}
ty
=>
ty
,
};
let
module
=
if
let
Some
(
client_transition
)
=
self
.await
?
.client_transition
{
client_transition
.process
(
original_source
,
source
,
module_asset_context
,
new_reference_type
,
)
}
else
{
module_asset_context
.process
(
source
,
new_reference_type
)
};
let
ProcessResult
::
Module
(
module
)
=
*
module
.await
?
else
{
return
Ok
(
ProcessResult
::
Ignore
.cell
());
...
...
crates/next-core/src/next_server/transforms.rs
View file @
7eb53237
...
...
@@ -59,7 +59,9 @@ pub async fn get_next_server_transforms_rules(
RuleCondition
::
ResourcePathEndsWith
(
".module.css"
.into
()),
RuleCondition
::
ContentTypeStartsWith
(
"text/css+module"
.into
()),
]),
RuleCondition
::
ReferenceType
(
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
)),
RuleCondition
::
ReferenceType
(
ReferenceType
::
Css
(
CssReferenceSubType
::
ModuleStyles
,
)),
]),
vec!
[
ModuleRuleEffect
::
Ignore
],
),
...
...
turbopack/crates/turbopack-core/src/reference_type.rs
View file @
7eb53237
...
...
@@ -220,10 +220,11 @@ pub enum CssReferenceSubType {
/// Reference from ModuleCssAsset to an imported ModuleCssAsset for retrieving the composed
/// class name
Compose
,
/// Used for generating the list of classes in a ModuleCssAsset
ModuleAnalyze
,
/// Reference from ModuleCssAsset to the CssModuleAsset
ModuleStyles
,
Internal
,
/// Used for generating the list of classes in a ModuleCssAsset
InternalAnalyze
,
Custom
(
u8
),
#[default]
Undefined
,
...
...
@@ -421,7 +422,8 @@ impl ReferenceType {
self
,
ReferenceType
::
Internal
(
_
)
|
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
)
|
ReferenceType
::
Css
(
CssReferenceSubType
::
InternalAnalyze
)
|
ReferenceType
::
Css
(
CssReferenceSubType
::
ModuleAnalyze
)
|
ReferenceType
::
Css
(
CssReferenceSubType
::
ModuleStyles
)
|
ReferenceType
::
Runtime
)
}
...
...
turbopack/crates/turbopack-css/src/module_asset.rs
View file @
7eb53237
...
...
@@ -88,7 +88,7 @@ impl Module for ModuleCssAsset {
.copied
()
.chain
(
match
*
self
.inner
(
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
))
.inner
(
ReferenceType
::
Css
(
CssReferenceSubType
::
ModuleStyles
))
.try_into_module
()
.await
?
{
...
...
@@ -169,7 +169,7 @@ impl ModuleCssAsset {
#[turbo_tasks
::
function]
async
fn
classes
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
ModuleCssClasses
>>
{
let
inner
=
self
.inner
(
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
Analyze
))
.inner
(
ReferenceType
::
Css
(
CssReferenceSubType
::
Module
Analyze
))
.module
();
let
inner
=
Vc
::
try_resolve_sidecast
::
<
Box
<
dyn
ProcessCss
>>
(
inner
)
...
...
turbopack/crates/turbopack/src/module_options/mod.rs
View file @
7eb53237
...
...
@@ -567,7 +567,7 @@ impl ModuleOptions {
ModuleRule
::
new_internal
(
RuleCondition
::
all
(
vec!
[
RuleCondition
::
ReferenceType
(
ReferenceType
::
Css
(
CssReferenceSubType
::
Internal
Analyze
,
CssReferenceSubType
::
Module
Analyze
,
)),
RuleCondition
::
Any
(
vec!
[
RuleCondition
::
ResourcePathEndsWith
(
".module.css"
.to_string
()),
...
...
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