Unverified Commit 4fb0beb1 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

fix: duplicate app server (#36710)

Fixes #36659

`App` is alreay included in `ServerComponentWrapper`

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent 41c0a669
...@@ -208,7 +208,6 @@ function renderPageTree( ...@@ -208,7 +208,6 @@ function renderPageTree(
isServerComponent: boolean isServerComponent: boolean
) { ) {
const { router: _, ...rest } = props const { router: _, ...rest } = props
if (isServerComponent) { if (isServerComponent) {
return ( return (
<App> <App>
...@@ -400,7 +399,7 @@ const useFlightResponse = createFlightHook() ...@@ -400,7 +399,7 @@ const useFlightResponse = createFlightHook()
// Create the wrapper component for a Flight stream. // Create the wrapper component for a Flight stream.
function createServerComponentRenderer( function createServerComponentRenderer(
App: any, App: any,
ComponentMod: any, Component: any,
{ {
cachePrefix, cachePrefix,
inlinedTransformStream, inlinedTransformStream,
...@@ -413,12 +412,6 @@ function createServerComponentRenderer( ...@@ -413,12 +412,6 @@ function createServerComponentRenderer(
serverComponentManifest: NonNullable<RenderOpts['serverComponentManifest']> serverComponentManifest: NonNullable<RenderOpts['serverComponentManifest']>
} }
) { ) {
// We need to expose the `__webpack_require__` API globally for
// react-server-dom-webpack. This is a hack until we find a better way.
// @ts-ignore
globalThis.__webpack_require__ = ComponentMod.__next_rsc__.__webpack_require__
const Component = interopDefault(ComponentMod)
function ServerComponentWrapper({ router, ...props }: any) { function ServerComponentWrapper({ router, ...props }: any) {
const id = (React as any).useId() const id = (React as any).useId()
...@@ -527,7 +520,13 @@ export async function renderToHTML( ...@@ -527,7 +520,13 @@ export async function renderToHTML(
if (isServerComponent) { if (isServerComponent) {
serverComponentsInlinedTransformStream = new TransformStream() serverComponentsInlinedTransformStream = new TransformStream()
const search = urlQueryToSearchParams(query).toString() const search = urlQueryToSearchParams(query).toString()
Component = createServerComponentRenderer(App, ComponentMod, { // We need to expose the `__webpack_require__` API globally for
// react-server-dom-webpack. This is a hack until we find a better way.
// @ts-ignore
globalThis.__webpack_require__ =
ComponentMod.__next_rsc__.__webpack_require__
Component = createServerComponentRenderer(App, Component, {
cachePrefix: pathname + (search ? `?${search}` : ''), cachePrefix: pathname + (search ? `?${search}` : ''),
inlinedTransformStream: serverComponentsInlinedTransformStream, inlinedTransformStream: serverComponentsInlinedTransformStream,
staticTransformStream: serverComponentsPageDataTransformStream, staticTransformStream: serverComponentsPageDataTransformStream,
...@@ -1257,7 +1256,7 @@ export async function renderToHTML( ...@@ -1257,7 +1256,7 @@ export async function renderToHTML(
...props.pageProps, ...props.pageProps,
...serverComponentProps, ...serverComponentProps,
}, },
isServerComponent true
), ),
serverComponentManifest serverComponentManifest
).pipeThrough(createBufferedTransformStream()) ).pipeThrough(createBufferedTransformStream())
...@@ -1425,7 +1424,8 @@ export async function renderToHTML( ...@@ -1425,7 +1424,8 @@ export async function renderToHTML(
<Body> <Body>
<AppContainerWithIsomorphicFiberStructure> <AppContainerWithIsomorphicFiberStructure>
{renderPageTree( {renderPageTree(
EnhancedApp, // AppServer is included in the EnhancedComponent in ServerComponentWrapper
isServerComponent ? React.Fragment : EnhancedApp,
EnhancedComponent, EnhancedComponent,
{ ...(isServerComponent ? props.pageProps : props), router }, { ...(isServerComponent ? props.pageProps : props), router },
isServerComponent isServerComponent
......
export default function App({ Component, pageProps }) {
return (
<div className="app-client-root">
<Component {...pageProps} />
</div>
)
}
...@@ -38,12 +38,16 @@ async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) { ...@@ -38,12 +38,16 @@ async function testRoute(appPort, url, { isStatic, isEdge, isRSC }) {
// Should be re-rendered. // Should be re-rendered.
expect(renderedAt1).toBeLessThan(renderedAt2) expect(renderedAt1).toBeLessThan(renderedAt2)
} }
const customAppServerHtml = '<div class="app-server-root"' // If the page is using 1 root, it won't use the other.
if (isRSC) { // e.g. server component page won't have client app root.
expect(html1).toContain(customAppServerHtml) const rootClasses = ['app-server-root', 'app-client-root']
} else { const [rootClass, oppositeRootClass] = isRSC
expect(html1).not.toContain(customAppServerHtml) ? [rootClasses[0], rootClasses[1]]
} : [rootClasses[1], rootClasses[0]]
const appServerOccurrence =
html1.match(new RegExp(`class="${rootClass}"`, 'g')) || []
expect(appServerOccurrence.length).toBe(1)
expect(html1).not.toContain(`"${oppositeRootClass}"`)
} }
describe('Switchable runtime (prod)', () => { describe('Switchable runtime (prod)', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment