From b53ff873d451dc0f14cfc47d3e324d89b5c720f4 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 6 May 2024 23:27:54 +0200 Subject: [PATCH] update server layer detection --- packages/next/src/build/swc/options.ts | 4 ++-- packages/next/src/build/webpack-config.ts | 2 +- test/e2e/app-dir/rsc-basic/pages/api/import-test.js | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/next/src/build/swc/options.ts b/packages/next/src/build/swc/options.ts index 8b88160db5a0c..805e3fde6a9a7 100644 --- a/packages/next/src/build/swc/options.ts +++ b/packages/next/src/build/swc/options.ts @@ -6,6 +6,7 @@ import type { StyledComponentsConfig, } from '../../server/config-shared' import type { ResolvedBaseUrl } from '../load-jsconfig' +import { isWebpackServerOnlyLayer } from '../utils' const nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/ @@ -78,8 +79,7 @@ function getBaseSWCOptions({ serverComponents?: boolean bundleLayer?: WebpackLayerName }) { - const isReactServerLayer = - bundleLayer === WEBPACK_LAYERS.reactServerComponents + const isReactServerLayer = isWebpackServerOnlyLayer(bundleLayer) const parserConfig = getParserOptions({ filename, jsConfig }) const paths = jsConfig?.compilerOptions?.paths const enableDecorators = Boolean( diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 4d4605a743d0f..b3e4440bb5552 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -509,7 +509,7 @@ export default async function getBaseWebpackConfig( // This will cause some performance overhead but // acceptable as Babel will not be recommended. getSwcLoader({ - serverComponents: true, + serverComponents: false, bundleLayer: WEBPACK_LAYERS.middleware, }), babelLoader, diff --git a/test/e2e/app-dir/rsc-basic/pages/api/import-test.js b/test/e2e/app-dir/rsc-basic/pages/api/import-test.js index 70e48bc0d887d..403ebab5f8eb9 100644 --- a/test/e2e/app-dir/rsc-basic/pages/api/import-test.js +++ b/test/e2e/app-dir/rsc-basic/pages/api/import-test.js @@ -1,7 +1,3 @@ -// You can still import React and Next's client component APIs from the server -// they won't be poisoned by the environment. -// eslint-disable-next-line no-unused-vars -import { useState } from 'react' import 'next/headers' export default function (_, res) {