From 1c1ee2ee2d91a374d492195602e540ec6d8c3615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 15 Oct 2024 18:10:35 +0900 Subject: [PATCH 1/6] Add a test --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 77d904d2..a2eafaa0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24355,6 +24355,28 @@ mod tests { }, ); + 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 { ..Default::default() }, + ); + // Stable hashes between project roots. fn test_project_root(project_root: &str, filename: &str, hash: &str) { let stylesheet = StyleSheet::parse( From 6570c515f20d00d813a894689590c2a1cd6bfba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 15 Oct 2024 18:15:20 +0900 Subject: [PATCH 2/6] fix --- src/rules/container.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rules/container.rs b/src/rules/container.rs index e08a824e..c0fb8e2a 100644 --- a/src/rules/container.rs +++ b/src/rules/container.rs @@ -268,7 +268,9 @@ 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, false) } } From d79ff5e0fa153e278eea034b5afbe181ac23e922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 15 Oct 2024 18:16:34 +0900 Subject: [PATCH 3/6] Update test --- src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a2eafaa0..3fba1b1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24366,12 +24366,14 @@ mod tests { indoc! {r#" .EgL3uq_box2 { @container main (width >= 0) { - background-color: #90ee90; + & { + background-color: #90ee90; + } } } "#}, map! { - "box2" => ".EgL3uq_box2" + "box2" => "EgL3uq_box2" }, HashMap::new(), crate::css_modules::Config { ..Default::default() }, From d78fbc5024ddda5929ecd551bf41edc4acd7b68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 16 Oct 2024 17:36:23 +0900 Subject: [PATCH 4/6] option --- src/css_modules.rs | 4 ++++ src/rules/container.rs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/css_modules.rs b/src/css_modules.rs index 65e8543a..ce7008df 100644 --- a/src/css_modules.rs +++ b/src/css_modules.rs @@ -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, } @@ -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, } diff --git a/src/rules/container.rs b/src/rules/container.rs index c0fb8e2a..a911d33b 100644 --- a/src/rules/container.rs +++ b/src/rules/container.rs @@ -270,7 +270,13 @@ impl<'i> ToCss for ContainerName<'i> { { // Container name should not be hashed // https://github.com/vercel/next.js/issues/71233 - self.0.to_css_with_options(dest, false) + self.0.to_css_with_options( + dest, + match &dest.css_module { + Some(css_module) => css_module.config.container, + None => false, + }, + ) } } From a6e465dc5df5f219abcd663acbef4ef1b4f77625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 16 Oct 2024 17:36:25 +0900 Subject: [PATCH 5/6] test --- src/lib.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 3fba1b1c..b81ae2b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24365,7 +24365,7 @@ mod tests { "#, indoc! {r#" .EgL3uq_box2 { - @container main (width >= 0) { + @container EgL3uq_main (width >= 0) { & { background-color: #90ee90; } @@ -24373,12 +24373,40 @@ mod tests { } "#}, 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( From 0f1641db19731a799142046258a52b1876625eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 17 Oct 2024 10:41:32 +0900 Subject: [PATCH 6/6] fix --- napi/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/napi/src/lib.rs b/napi/src/lib.rs index 18bbd7e4..dff48805 100644 --- a/napi/src/lib.rs +++ b/napi/src/lib.rs @@ -606,6 +606,7 @@ struct CssModulesConfig { pattern: Option, dashed_idents: Option, animation: Option, + container: Option, grid: Option, custom_idents: Option, pure: Option, @@ -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(), @@ -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(),