Skip to content

Commit f467607

Browse files
committed
Correctly skip CSS in SSR
1 parent b7e23da commit f467607

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

crates/next-api/src/app.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,19 @@ impl AppProject {
647647
Ok(ModuleAssetContext::new(
648648
TransitionOptions {
649649
named_transitions: transitions,
650+
transition_rules: vec![
651+
// Change context, this is used to determine
652+
// the list of CSS module classes.
653+
TransitionRule::new(
654+
RuleCondition::all(vec![
655+
RuleCondition::ReferenceType(ReferenceType::Css(
656+
CssReferenceSubType::Analyze,
657+
)),
658+
module_styles_rule_condition(),
659+
]),
660+
ResolvedVc::upcast(self.client_transition().to_resolved().await?),
661+
),
662+
],
650663
..Default::default()
651664
}
652665
.cell(),

crates/next-core/src/next_server/transforms.rs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use next_custom_transforms::transforms::strip_page_exports::ExportFilter;
33
use turbo_rcstr::RcStr;
44
use turbo_tasks::{ResolvedVc, Vc};
55
use turbopack::module_options::{ModuleRule, ModuleRuleEffect, RuleCondition};
6-
use turbopack_core::reference_type::{ReferenceType, UrlReferenceSubType};
6+
use turbopack_core::reference_type::{CssReferenceSubType, ReferenceType, UrlReferenceSubType};
77

88
use crate::{
99
mode::NextMode,
@@ -21,7 +21,7 @@ use crate::{
2121
next_page_static_info::get_next_page_static_info_assert_rule,
2222
next_pure::get_next_pure_rule, server_actions::ActionsTransform,
2323
},
24-
util::NextRuntime,
24+
util::{NextRuntime, module_styles_rule_condition, styles_rule_condition},
2525
};
2626

2727
/// Returns a list of module rules which apply server-side, Next.js-specific
@@ -51,35 +51,18 @@ pub async fn get_next_server_transforms_rules(
5151

5252
if !matches!(context_ty, ServerContextType::AppRSC { .. }) {
5353
rules.extend([
54-
// Ignore the internal ModuleCssAsset -> CssModuleAsset references
55-
// The CSS Module module itself is still needed for class names
56-
ModuleRule::new_internal(
57-
RuleCondition::any(vec![
58-
RuleCondition::ResourcePathEndsWith(".module.css".into()),
59-
RuleCondition::ContentTypeStartsWith("text/css+module".into()),
60-
]),
61-
vec![ModuleRuleEffect::Ignore],
62-
),
63-
]);
64-
rules.extend([
65-
// Ignore all non-module CSS references
54+
// Ignore the inner ModuleCssAsset -> CssModuleAsset references
55+
// The CSS Module module itself (and the Analyze reference) is still needed to generate
56+
// the class names object.
6657
ModuleRule::new(
67-
RuleCondition::any(vec![
68-
RuleCondition::all(vec![
69-
RuleCondition::ResourcePathEndsWith(".css".into()),
70-
RuleCondition::not(RuleCondition::ResourcePathEndsWith(
71-
".module.css".into(),
72-
)),
73-
]),
74-
RuleCondition::all(vec![
75-
RuleCondition::ContentTypeStartsWith("text/css".into()),
76-
RuleCondition::not(RuleCondition::ContentTypeStartsWith(
77-
"text/css+module".into(),
78-
)),
79-
]),
58+
RuleCondition::all(vec![
59+
RuleCondition::ReferenceType(ReferenceType::Css(CssReferenceSubType::Inner)),
60+
module_styles_rule_condition(),
8061
]),
8162
vec![ModuleRuleEffect::Ignore],
8263
),
64+
// Ignore all non-module CSS references
65+
ModuleRule::new(styles_rule_condition(), vec![ModuleRuleEffect::Ignore]),
8366
]);
8467
}
8568

0 commit comments

Comments
 (0)