From f5917ad3eec4c22ad8aa13b83d3c6dd0e7e8368b Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Mon, 28 Mar 2022 16:24:57 +0200 Subject: [PATCH] Fix server component render condition (#35663) We are currently using `!!ComponentMod.__next_rsc__` as the hint for the renderer to tell if the component is a server component, however that export field (`__next_rsc__`) is assigned to client components (`.client.[ext]`) as well. This PR adds a new `__next_rsc_server__` field which is only true when the component is a server component so the renderer can handle client components correctly. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` --- .../next/build/webpack/loaders/next-flight-server-loader.ts | 1 + packages/next/server/render.tsx | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/next/build/webpack/loaders/next-flight-server-loader.ts b/packages/next/build/webpack/loaders/next-flight-server-loader.ts index 112f3c740a89..693003fa64b6 100644 --- a/packages/next/build/webpack/loaders/next-flight-server-loader.ts +++ b/packages/next/build/webpack/loaders/next-flight-server-loader.ts @@ -186,6 +186,7 @@ export default async function transformSource( __webpack_require__, _: () => {\n${imports}\n} }`, + __next_rsc_server__: isServerComponent(resourcePath) ? 'true' : 'false', } if (isClientCompilation) { diff --git a/packages/next/server/render.tsx b/packages/next/server/render.tsx index c3d1b2849d31..dc182741f126 100644 --- a/packages/next/server/render.tsx +++ b/packages/next/server/render.tsx @@ -469,9 +469,9 @@ export async function renderToHTML( // We don't need to opt-into the flight inlining logic if the page isn't a RSC. const isServerComponent = - !!serverComponentManifest && hasConcurrentFeatures && - !!ComponentMod.__next_rsc__ + !!serverComponentManifest && + !!ComponentMod.__next_rsc_server__ let Component: React.ComponentType<{}> | ((props: any) => JSX.Element) = renderOpts.Component