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 independent CSSModule missing from flight manifest #38575

Merged
merged 2 commits into from Jul 13, 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
38 changes: 24 additions & 14 deletions packages/next/build/webpack/plugins/flight-manifest-plugin.ts
Expand Up @@ -58,8 +58,10 @@ export class FlightManifestPlugin {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
// Have to be in the optimize stage to run after updating the CSS
// asset hash via extract mini css plugin.
// @ts-ignore TODO: Remove ignore when webpack 5 is stable
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
},
(assets: any) => this.createAsset(assets, compilation, compiler.context)
)
Expand All @@ -77,7 +79,22 @@ export class FlightManifestPlugin {
id: string | number,
mod: any
) {
const resource: string = mod.resource
const isCSSModule =
mod.type === 'css/mini-extract' ||
(mod.loaders &&
(dev
? mod.loaders.some((item: any) =>
item.loader.includes('next-style-loader/index.js')
)
: mod.loaders.some((item: any) =>
item.loader.includes('mini-css-extract-plugin/loader.js')
)))

const resource =
mod.type === 'css/mini-extract'
? mod._identifier.slice(mod._identifier.lastIndexOf('!') + 1)
: mod.resource

if (!resource) return

const moduleExports: any = manifest[resource] || {}
Expand All @@ -87,21 +104,14 @@ export class FlightManifestPlugin {
// Note that this isn't that reliable as webpack is still possible to assign
// additional queries to make sure there's no conflict even using the `named`
// module ID strategy.
let ssrNamedModuleId = relative(context, mod.resourceResolveData.path)
let ssrNamedModuleId = relative(
context,
mod.resourceResolveData?.path || resource
)
if (!ssrNamedModuleId.startsWith('.'))
ssrNamedModuleId = `./${ssrNamedModuleId}`

if (
mod.request &&
/\.css$/.test(mod.request) &&
(dev
? mod.loaders.some((item: any) =>
item.loader.includes('next-style-loader/index.js')
)
: mod.loaders.some((item: any) =>
item.loader.includes('mini-css-extract-plugin/loader.js')
))
) {
if (isCSSModule) {
if (!manifest[resource]) {
if (dev) {
const chunkIdNameMapping = (chunk.ids || []).map((chunkId) => {
Expand Down
1 change: 1 addition & 0 deletions packages/next/client/app-index.tsx
Expand Up @@ -31,6 +31,7 @@ self.__next_require__ = __webpack_require__

// eslint-disable-next-line no-undef
;(self as any).__next_chunk_load__ = (chunk: string) => {
if (!chunk) return Promise.resolve()
if (chunk.endsWith('.css')) {
const existingTag = document.querySelector(`link[href="${chunk}"]`)
if (!existingTag) {
Expand Down