Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css-modules): Do not transform the container name in CSS Modules #835

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ struct CssModulesConfig {
pattern: Option<String>,
dashed_idents: Option<bool>,
animation: Option<bool>,
container: Option<bool>,
grid: Option<bool>,
custom_idents: Option<bool>,
pure: Option<bool>,
Expand Down Expand Up @@ -718,6 +719,7 @@ fn compile<'i>(
},
dashed_idents: c.dashed_idents.unwrap_or_default(),
animation: c.animation.unwrap_or(true),
container: c.container.unwrap_or(true),
grid: c.grid.unwrap_or(true),
custom_idents: c.custom_idents.unwrap_or(true),
pure: c.pure.unwrap_or_default(),
Expand Down Expand Up @@ -849,6 +851,7 @@ fn compile_bundle<
},
dashed_idents: c.dashed_idents.unwrap_or_default(),
animation: c.animation.unwrap_or(true),
container: c.container.unwrap_or(true),
grid: c.grid.unwrap_or(true),
custom_idents: c.custom_idents.unwrap_or(true),
pure: c.pure.unwrap_or_default(),
Expand Down
4 changes: 4 additions & 0 deletions src/css_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct Config<'i> {
/// Whether to scope custom identifiers
/// Default is `true`.
pub custom_idents: bool,
/// Whether to scope container names.
/// Default is `true`.
pub container: bool,
/// Whether to check for pure CSS modules.
pub pure: bool,
}
Expand All @@ -52,6 +55,7 @@ impl<'i> Default for Config<'i> {
dashed_idents: Default::default(),
animation: true,
grid: true,
container: true,
custom_idents: true,
pure: false,
}
Expand Down
52 changes: 52 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24355,6 +24355,58 @@ mod tests {
},
);

css_modules_test(
r#"
.box2 {
@container main (width >= 0) {
background-color: #90ee90;
}
}
"#,
indoc! {r#"
.EgL3uq_box2 {
@container EgL3uq_main (width >= 0) {
& {
background-color: #90ee90;
}
}
}
"#},
map! {
"main" => "EgL3uq_main",
"box2" => "EgL3uq_box2"
},
HashMap::new(),
crate::css_modules::Config { ..Default::default() },
);

css_modules_test(
r#"
.box2 {
@container main (width >= 0) {
background-color: #90ee90;
}
}
"#,
indoc! {r#"
.EgL3uq_box2 {
@container main (width >= 0) {
& {
background-color: #90ee90;
}
}
}
"#},
map! {
"box2" => "EgL3uq_box2"
},
HashMap::new(),
crate::css_modules::Config {
container: false,
..Default::default()
},
);

// Stable hashes between project roots.
fn test_project_root(project_root: &str, filename: &str, hash: &str) {
let stylesheet = StyleSheet::parse(
Expand Down
10 changes: 9 additions & 1 deletion src/rules/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,15 @@ impl<'i> ToCss for ContainerName<'i> {
where
W: std::fmt::Write,
{
self.0.to_css(dest)
// Container name should not be hashed
// https://github.com/vercel/next.js/issues/71233
self.0.to_css_with_options(
dest,
match &dest.css_module {
Some(css_module) => css_module.config.container,
None => false,
},
)
}
}

Expand Down
Loading