diff --git a/packages/next/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/build/webpack/plugins/flight-manifest-plugin.ts index 70ae2c3ac04a0..99859a5bc4374 100644 --- a/packages/next/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/flight-manifest-plugin.ts @@ -191,8 +191,8 @@ 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, @@ -200,6 +200,13 @@ export class FlightManifestPlugin { chunks, }, } + } else { + // It is possible that there are mtuliepl modules with the same resouce, + // 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) { diff --git a/test/e2e/app-dir/app/app/css/css-client/page.js b/test/e2e/app-dir/app/app/css/css-client/page.js index 928ff6bf0e56f..c62ea6373f0b6 100644 --- a/test/e2e/app-dir/app/app/css/css-client/page.js +++ b/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