From 2c592853e65340cf466b2b9c7fd99a6dd5a7a4d9 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Mon, 21 Nov 2022 21:08:18 +0100 Subject: [PATCH 1/3] assign layer to app client entries --- packages/next/build/entries.ts | 25 ++++++++++++++++++++----- packages/next/lib/constants.ts | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index e6f5fc1d11d8ebc..743be6478b67251 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -513,18 +513,26 @@ export function finalizeEntrypoint({ } } + const isAppEntry = + hasAppDir && + ([CLIENT_STATIC_FILES_RUNTIME_MAIN_APP].includes(name) || + entry.import.includes('next-flight-client-entry-loader')) + if ( // Client special cases - name !== CLIENT_STATIC_FILES_RUNTIME_POLYFILLS && - name !== CLIENT_STATIC_FILES_RUNTIME_MAIN && - name !== CLIENT_STATIC_FILES_RUNTIME_MAIN_APP && - name !== CLIENT_STATIC_FILES_RUNTIME_AMP && - name !== CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH + ![ + CLIENT_STATIC_FILES_RUNTIME_POLYFILLS, + CLIENT_STATIC_FILES_RUNTIME_MAIN, + CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, + CLIENT_STATIC_FILES_RUNTIME_AMP, + CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH, + ].includes(name) ) { // TODO-APP: this is a temporary fix. @shuding is going to change the handling of server components if (hasAppDir && entry.import.includes('next-flight-client-entry-loader')) { return { dependOn: CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, + layer: isAppEntry ? WEBPACK_LAYERS.appClient : undefined, ...entry, } } @@ -538,5 +546,12 @@ export function finalizeEntrypoint({ } } + if (isAppEntry) { + return { + layer: WEBPACK_LAYERS.appClient, + ...entry, + } + } + return entry } diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index 7dbb0be9b5c428e..ef1d10b1033945b 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -76,4 +76,5 @@ export const WEBPACK_LAYERS = { api: 'api', middleware: 'middleware', edgeAsset: 'edge-asset', + appClient: 'app-client', } From d0b120cc1cff5694832d1df0cc83dc2b231fe24d Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 30 Nov 2022 00:09:54 +0100 Subject: [PATCH 2/3] fix --- packages/next/build/entries.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index 19a6c5208e9d35b..fd4cee98cbf1c62 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -517,9 +517,9 @@ export function finalizeEntrypoint({ } } - const isAppEntry = + const isAppLayer = hasAppDir && - ([CLIENT_STATIC_FILES_RUNTIME_MAIN_APP].includes(name) || + (name === CLIENT_STATIC_FILES_RUNTIME_MAIN_APP || entry.import.includes('next-flight-client-entry-loader')) if ( @@ -533,10 +533,10 @@ export function finalizeEntrypoint({ ].includes(name) ) { // TODO-APP: this is a temporary fix. @shuding is going to change the handling of server components - if (hasAppDir && entry.import.includes('next-flight-client-entry-loader')) { + if (isAppLayer) { return { dependOn: CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, - layer: isAppEntry ? WEBPACK_LAYERS.appClient : undefined, + layer: WEBPACK_LAYERS.appClient, ...entry, } } @@ -550,7 +550,7 @@ export function finalizeEntrypoint({ } } - if (isAppEntry) { + if (isAppLayer) { return { layer: WEBPACK_LAYERS.appClient, ...entry, From b8cbfe10198344aaa7d0dfcd9d09e55bc7dbf071 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 7 Dec 2022 00:26:09 +0100 Subject: [PATCH 3/3] fix --- packages/next/build/entries.ts | 18 ++++++++---------- .../parseNotFoundError.ts | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index fd4cee98cbf1c62..ae00a6095ff4feb 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -19,7 +19,7 @@ import { SERVER_RUNTIME, WEBPACK_LAYERS, } from '../lib/constants' -import { RSC_MODULE_TYPES } from '../shared/lib/constants' +import { APP_CLIENT_INTERNALS, RSC_MODULE_TYPES } from '../shared/lib/constants' import { CLIENT_STATIC_FILES_RUNTIME_AMP, CLIENT_STATIC_FILES_RUNTIME_MAIN, @@ -520,19 +520,17 @@ export function finalizeEntrypoint({ const isAppLayer = hasAppDir && (name === CLIENT_STATIC_FILES_RUNTIME_MAIN_APP || - entry.import.includes('next-flight-client-entry-loader')) + name === APP_CLIENT_INTERNALS || + name.startsWith('app/')) if ( // Client special cases - ![ - CLIENT_STATIC_FILES_RUNTIME_POLYFILLS, - CLIENT_STATIC_FILES_RUNTIME_MAIN, - CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, - CLIENT_STATIC_FILES_RUNTIME_AMP, - CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH, - ].includes(name) + name !== CLIENT_STATIC_FILES_RUNTIME_POLYFILLS && + name !== CLIENT_STATIC_FILES_RUNTIME_MAIN && + name !== CLIENT_STATIC_FILES_RUNTIME_MAIN_APP && + name !== CLIENT_STATIC_FILES_RUNTIME_AMP && + name !== CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH ) { - // TODO-APP: this is a temporary fix. @shuding is going to change the handling of server components if (isAppLayer) { return { dependOn: CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, diff --git a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts index ee0c0627c1fc911..f7c7cf7e48bd242 100644 --- a/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts +++ b/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts @@ -65,6 +65,7 @@ export async function getNotFoundError( column: loc.start.column, source: originalSource, rootDirectory: compilation.options.context!, + modulePath: fileName, frame: {}, })