Skip to content

Commit

Permalink
Ensure AsyncLocalStorage for static generation is shared for client/s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
javivelasco committed Oct 24, 2022
1 parent 6687f28 commit e99a759
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/next/lib/constants.ts
Expand Up @@ -70,6 +70,7 @@ export const SERVER_RUNTIME: Record<string, ServerRuntime> = {
}

export const WEBPACK_LAYERS = {
shared: 'sc_shared',
server: 'sc_server',
client: 'sc_client',
api: 'api',
Expand Down

0 comments on commit e99a759

Please sign in to comment.