Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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