Skip to content

Commit

Permalink
Fix server component render condition (#35663)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
shuding committed Mar 28, 2022
1 parent 41a2eb2 commit f5917ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Expand Up @@ -186,6 +186,7 @@ export default async function transformSource(
__webpack_require__,
_: () => {\n${imports}\n}
}`,
__next_rsc_server__: isServerComponent(resourcePath) ? 'true' : 'false',
}

if (isClientCompilation) {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/render.tsx
Expand Up @@ -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
Expand Down

0 comments on commit f5917ad

Please sign in to comment.