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 global css being marked as side effect free #41481

Merged
merged 2 commits into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/next/build/webpack/config/blocks/css/index.ts
Expand Up @@ -427,6 +427,8 @@ export const css = curry(async function css(
loader({
oneOf: [
markRemovable({
// CSS imports have side effects, even on the server side.
sideEffects: true,
test: [regexCssGlobal, regexSassGlobal],
use: require.resolve('next/dist/compiled/ignore-loader'),
}),
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/app-dir/rsc-external.test.ts
Expand Up @@ -110,4 +110,13 @@ describe('app dir - rsc external dependency', () => {
}
)
})

it('should correctly collect global css imports and mark them as side effects', async () => {
await fetchViaHTTP(next.url, '/css/a').then(async (response) => {
const result = await resolveStreamResponse(response)

// It should include the global CSS import
expect(result).toMatch(/\.css/)
})
})
})
5 changes: 5 additions & 0 deletions test/e2e/app-dir/rsc-external/app/css/[...slug]/page.js
@@ -0,0 +1,5 @@
import 'global-css/style.css'

export default function Page() {
return <div>hello</div>
}
@@ -0,0 +1 @@
import './style.css'
@@ -0,0 +1,10 @@
{
"name": "global-css",
"type": "module",
"sideEffects": false,
"exports": {
".": "./index.js",
"./style.css": "./style.css",
"./package.json": "./package.json"
}
}
@@ -0,0 +1,3 @@
body {
color: red;
}