From e99d66b9ad127c4d1a574a2c61e750799fef9f8b Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 19 Apr 2023 19:24:28 +0200 Subject: [PATCH 1/2] fix chunk file names in flight manifest --- .../webpack/plugins/flight-manifest-plugin.ts | 17 +++++++++++------ packages/next/src/client/app-index.tsx | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 09a9826388b03..177291a5720ce 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -256,13 +256,18 @@ export class ClientReferenceManifestPlugin { return null } - return ( - requiredChunk.id + - ':' + - (requiredChunk.name || requiredChunk.id) + - (dev ? '' : '-' + requiredChunk.hash) - ) + // Get the actual chunk file names from the chunk file list. + // It's possible that the chunk is generated via `import()`, in + // that case the chunk file name will be '[name].[contenthash]' + // instead of '[name]-[chunkhash]'. + return [...requiredChunk.files].map((file) => { + // It's possible that a chunk also emits CSS files, that will + // be handled separatedly. + if (!file.endsWith('.js')) return null + return requiredChunk.id + ':' + file + }) }) + .flat() .filter(nonNullable) } const requiredChunks = getAppPathRequiredChunks() diff --git a/packages/next/src/client/app-index.tsx b/packages/next/src/client/app-index.tsx index 2f7cc58e381d0..37b842791eba1 100644 --- a/packages/next/src/client/app-index.tsx +++ b/packages/next/src/client/app-index.tsx @@ -69,8 +69,8 @@ self.__next_require__ = // eslint-disable-next-line no-undef ;(self as any).__next_chunk_load__ = (chunk: string) => { if (!chunk) return Promise.resolve() - const [chunkId, chunkFileName] = chunk.split(':') - chunkFilenameMap[chunkId] = `static/chunks/${chunkFileName}.js` + const [chunkId, chunkFilePath] = chunk.split(':') + chunkFilenameMap[chunkId] = chunkFilePath // @ts-ignore // eslint-disable-next-line no-undef From 03bab9c011f04154518570fee187ac2cda37119e Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 19 Apr 2023 19:36:10 +0200 Subject: [PATCH 2/2] fix lint error --- .../next/src/build/webpack/plugins/flight-manifest-plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 177291a5720ce..1e2ad81366782 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -135,7 +135,6 @@ export class ClientReferenceManifestPlugin { cssFiles: {}, clientModules: {}, } - const dev = this.dev const clientRequestsSet = new Set()