diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index a3bf3cf8169e467..f3e3ada77e391ab 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -729,6 +729,16 @@ export default async function getBaseWebpackConfig( babel: getBabelOrSwcLoader(), } + const swcLoaderForRSC = hasServerComponents + ? useSWCLoader + ? getSwcLoader({ isServerLayer: true }) + : // When using Babel, we will have to add the SWC loader + // as an additional pass to handle RSC correctly. + // This will cause some performance overhead but + // acceptable as Babel will not be recommended. + [getSwcLoader({ isServerLayer: true }), getBabelLoader()] + : [] + const pageExtensions = config.pageExtensions const outputPath = @@ -1789,16 +1799,12 @@ 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 - // as an additional pass to handle RSC correctly. - // This will cause some performance overhead but - // acceptable as Babel will not be recommended. - [ - getSwcLoader({ isServerLayer: true }), - getBabelLoader(), - ], + use: swcLoaderForRSC, + }, + { + test: codeCondition.test, + resourceQuery: /__edge_ssr_entry__/, + use: swcLoaderForRSC, }, ] : []), diff --git a/test/e2e/app-dir/app/app/edge-apis/cookies/page.js b/test/e2e/app-dir/app/app/edge-apis/cookies/page.js new file mode 100644 index 000000000000000..15fa568241f754c --- /dev/null +++ b/test/e2e/app-dir/app/app/edge-apis/cookies/page.js @@ -0,0 +1,8 @@ +import { cookies } from 'next/headers' + +export const runtime = 'experimental-edge' + +export default function Page() { + cookies() + return

Hello!

+} diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index b80f8316362bee8..a8740a0d0d10385 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -955,6 +955,11 @@ describe('app dir', () => { } }) + it('should retrieve cookies in a server component in the edge runtime', async () => { + const res = await fetchViaHTTP(next.url, '/edge-apis/cookies') + expect(await res.text()).toInclude('Hello') + }) + it('should access cookies on navigation', async () => { const browser = await webdriver(next.url, '/navigation')