From e99a759e2a0b9689d55c76786f8a6126a246f951 Mon Sep 17 00:00:00 2001 From: Javi Velasco Date: Sun, 23 Oct 2022 18:23:11 -0700 Subject: [PATCH] Ensure AsyncLocalStorage for static generation is shared for client/server --- packages/next/build/webpack-config.ts | 12 ++++++++++++ packages/next/lib/constants.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index fa76285c1af0a..20f5ef8362a5d 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -73,6 +73,9 @@ const babelIncludeRegexes: RegExp[] = [ /[\\/](strip-ansi|ansi-regex|styled-jsx)[\\/]/, ] +const staticGenerationAsyncStorageRegex = + /next[\\/]dist[\\/]client[\\/]components[\\/]static-generation-async-storage/ + const BABEL_CONFIG_FILES = [ '.babelrc', '.babelrc.json', @@ -1591,6 +1594,12 @@ export default async function getBaseWebpackConfig( }, ] : []), + ...[ + { + layer: WEBPACK_LAYERS.shared, + test: staticGenerationAsyncStorageRegex, + }, + ], // TODO: FIXME: do NOT webpack 5 support with this // x-ref: https://github.com/webpack/webpack/issues/11467 ...(!config.experimental.fullySpecified @@ -1624,6 +1633,7 @@ export default async function getBaseWebpackConfig( // To let the internal client components passing through flight loader NEXT_PROJECT_ROOT_DIST, ], + exclude: [staticGenerationAsyncStorageRegex], issuerLayer: WEBPACK_LAYERS.server, use: { loader: 'next-flight-loader', @@ -1657,6 +1667,7 @@ export default async function getBaseWebpackConfig( oneOf: [ { // test: codeCondition.test, + exclude: [staticGenerationAsyncStorageRegex], issuerLayer: WEBPACK_LAYERS.server, test(req: string) { // If it's not a source code file, or has been opted out of @@ -1728,6 +1739,7 @@ export default async function getBaseWebpackConfig( { test: codeCondition.test, issuerLayer: WEBPACK_LAYERS.server, + exclude: [staticGenerationAsyncStorageRegex], use: useSWCLoader ? getSwcLoader({ isServerLayer: true }) : // When using Babel, we will have to add the SWC loader diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index 9f9e6dc75fb2b..7dbb0be9b5c42 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -70,6 +70,7 @@ export const SERVER_RUNTIME: Record = { } export const WEBPACK_LAYERS = { + shared: 'sc_shared', server: 'sc_server', client: 'sc_client', api: 'api',