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 imports not collected due to race conditions #42392

Merged
merged 2 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -191,15 +191,22 @@ export class FlightManifestPlugin {
ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}`

if (isCSSModule) {
const chunks = [...chunk.files].filter((f) => f.endsWith('.css'))
if (!manifest[resource]) {
const chunks = [...chunk.files].filter((f) => f.endsWith('.css'))
manifest[resource] = {
default: {
id,
name: 'default',
chunks,
},
}
} else {
// It is possible that there are mtuliepl modules with the same resouce,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// It is possible that there are mtuliepl modules with the same resouce,
// It is possible that there are multiple modules with the same resource,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address these in my next PR, thanks!

// e.g. extracted by mini-css-extract-plugin. In that case we need to
// merge the chunks.
manifest[resource].default.chunks = [
...new Set([...manifest[resource].default.chunks, ...chunks]),
]
}

if (chunkGroup.name) {
Expand Down
12 changes: 11 additions & 1 deletion test/e2e/app-dir/app/app/css/css-client/page.js
@@ -1,7 +1,17 @@
'use client'

import 'next/link'

import './client-page.css'
import styles from './inner/ClientComponent.module.css'

export default function Page() {
return <h1>Page!!!</h1>
return (
<>
<h1>Page!!!</h1>
<div id="css-modules" className={styles.yuge}>
huge
</div>
</>
)
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -1487,6 +1487,16 @@ describe('app dir', () => {
})

describe('client components', () => {
it('should support css modules inside client page', async () => {
const browser = await webdriver(next.url, '/css/css-client')

expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#css-modules')).fontSize`
)
).toBe('100px')
})

it('should support css modules inside client components', async () => {
const browser = await webdriver(next.url, '/css/css-client/inner')

Expand Down