From 2a230397c03fa2ee5557d33cac73092b4248e884 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 7 Dec 2022 15:20:50 +0100 Subject: [PATCH] Assign layer to app client entries (#43197) This is one of the required changes to refactor bundling strategy for pages and app. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- packages/next/build/entries.ts | 19 ++++++++++++++++--- .../parseNotFoundError.ts | 1 + packages/next/lib/constants.ts | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index 57305cc155669da..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, @@ -517,6 +517,12 @@ export function finalizeEntrypoint({ } } + const isAppLayer = + hasAppDir && + (name === CLIENT_STATIC_FILES_RUNTIME_MAIN_APP || + name === APP_CLIENT_INTERNALS || + name.startsWith('app/')) + if ( // Client special cases name !== CLIENT_STATIC_FILES_RUNTIME_POLYFILLS && @@ -525,10 +531,10 @@ export function finalizeEntrypoint({ 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 (hasAppDir && entry.import.includes('next-flight-client-entry-loader')) { + if (isAppLayer) { return { dependOn: CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, + layer: WEBPACK_LAYERS.appClient, ...entry, } } @@ -542,5 +548,12 @@ export function finalizeEntrypoint({ } } + if (isAppLayer) { + return { + layer: WEBPACK_LAYERS.appClient, + ...entry, + } + } + return entry } 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: {}, }) 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', }