Unverified Commit d5a682e6 authored by Javi Velasco's avatar Javi Velasco Committed by GitHub

Ensure `AsyncLocalStorage` for static generation is shared for client & server (#41695)

With this PR we make sure that `AsyncLocalStorage` for static generation
is shared for client and server in RSC
parent 4f9e3bf0
......@@ -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
......
......@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment