Unverified Commit 333489d8 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: fix postcss in RSC CSS (#82554)

### What?

make sure to apply PostCSS on .module.css that is requested from RSC.

Fixes a regression from #82448

Closes #82545
parent b8508126
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import styles from './page.module.css'
export default function Page() {
return <p className={styles.main}>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
describe('css-modules-rsc-postcss', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
'postcss-nested': '4.2.1',
},
})
it('should compile successfully and apply the correct styles', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('p').getComputedCss('color')).toBe(
'rgb(0, 128, 0)'
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
const plugin = () => {
return {
postcssPlugin: 'color-change',
Declaration: {
color(prop) {
prop.value = 'green'
},
},
}
}
plugin.postcss = true
module.exports = plugin
module.exports = {
plugins: ['postcss-nested', require.resolve('./plugin')],
}
...@@ -162,15 +162,17 @@ impl ModuleOptions { ...@@ -162,15 +162,17 @@ impl ModuleOptions {
// only then be processed with Webpack/PostCSS). // only then be processed with Webpack/PostCSS).
// //
// Note that this is not an exhaustive condition for PostCSS/Webpack, but excludes certain // Note that this is not an exhaustive condition for PostCSS/Webpack, but excludes certain
// cases, so it should be added conjunctively together with the `module_css_condition` rule. // cases, so it should be added conjunctively together with CSS Module rule.
// //
// If module css, then only when (Inner or Analyze or Compose) // If module css, then only when (Inner or Analyze or Compose)
// <=> (not (module css)) or (Inner or Analyzer or Compose) // <=> (not (module css)) or (Inner or Analyzer or Compose)
let module_css_external_transform_conditions = vec![ //
// So only if this is not a CSS module, or one of the special reference type constraints.
let module_css_external_transform_conditions = RuleCondition::Any(vec![
RuleCondition::not(module_css_condition.clone()),
RuleCondition::ReferenceType(ReferenceType::Css(CssReferenceSubType::Inner)), RuleCondition::ReferenceType(ReferenceType::Css(CssReferenceSubType::Inner)),
RuleCondition::ReferenceType(ReferenceType::Css(CssReferenceSubType::Analyze)), RuleCondition::ReferenceType(ReferenceType::Css(CssReferenceSubType::Analyze)),
RuleCondition::ReferenceType(ReferenceType::Css(CssReferenceSubType::Compose)), ]);
];
let mut ts_preprocess = vec![]; let mut ts_preprocess = vec![];
let mut ecma_preprocess = vec![]; let mut ecma_preprocess = vec![];
...@@ -505,22 +507,14 @@ impl ModuleOptions { ...@@ -505,22 +507,14 @@ impl ModuleOptions {
}; };
rules.push(ModuleRule::new( rules.push(ModuleRule::new(
RuleCondition::Any(vec![
RuleCondition::All(vec![ RuleCondition::All(vec![
RuleCondition::Any(vec![ RuleCondition::Any(vec![
// Both CSS and CSS Modules
RuleCondition::ResourcePathEndsWith(".css".to_string()), RuleCondition::ResourcePathEndsWith(".css".to_string()),
RuleCondition::ContentTypeStartsWith("text/css".to_string()), RuleCondition::ContentTypeStartsWith("text/css".to_string()),
module_css_condition.clone(),
]), ]),
RuleCondition::not(module_css_condition.clone()),
]),
RuleCondition::All(
[
vec![module_css_condition.clone()],
// see comment on module_css_external_transform_conditions
module_css_external_transform_conditions.clone(), module_css_external_transform_conditions.clone(),
]
.concat(),
),
]), ]),
vec![ModuleRuleEffect::SourceTransforms(ResolvedVc::cell(vec![ vec![ModuleRuleEffect::SourceTransforms(ResolvedVc::cell(vec![
ResolvedVc::upcast( ResolvedVc::upcast(
...@@ -703,14 +697,7 @@ impl ModuleOptions { ...@@ -703,14 +697,7 @@ impl ModuleOptions {
RuleCondition::ResourceBasePathGlob(Glob::new(key.clone()).await?) RuleCondition::ResourceBasePathGlob(Glob::new(key.clone()).await?)
}, },
RuleCondition::not(RuleCondition::ResourceIsVirtualSource), RuleCondition::not(RuleCondition::ResourceIsVirtualSource),
// see comment on module_css_external_transform_conditions
RuleCondition::Any(
[
vec![RuleCondition::not(module_css_condition.clone())],
module_css_external_transform_conditions.clone(), module_css_external_transform_conditions.clone(),
]
.concat(),
),
]), ]),
vec![ModuleRuleEffect::SourceTransforms(ResolvedVc::cell(vec![ vec![ModuleRuleEffect::SourceTransforms(ResolvedVc::cell(vec![
ResolvedVc::upcast( ResolvedVc::upcast(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment