rsc: keep static page props (#36157)

This commit is contained in:
Jiachi Liu 2022-04-14 16:35:09 +02:00 committed by GitHub
parent be3c804b8d
commit a4aa1df7da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 11 deletions

View file

@ -431,14 +431,7 @@ function createServerComponentRenderer(
return root return root
} }
// Although it's not allowed to attach some static methods to Component, for (const methodName of Object.keys(Component)) {
// we still re-assign all the component APIs to keep the behavior unchanged.
for (const methodName of [
'getInitialProps',
'getStaticProps',
'getServerSideProps',
'getStaticPaths',
]) {
const method = (Component as any)[methodName] const method = (Component as any)[methodName]
if (method) { if (method) {
;(ServerComponentWrapper as any)[methodName] = method ;(ServerComponentWrapper as any)[methodName] = method
@ -1375,7 +1368,7 @@ export async function renderToHTML(
<AppContainerWithIsomorphicFiberStructure> <AppContainerWithIsomorphicFiberStructure>
{isServerComponent && !!AppMod.__next_rsc__ ? ( {isServerComponent && !!AppMod.__next_rsc__ ? (
// _app.server.js is used. // _app.server.js is used.
<Component {...props.pageProps} router={router} /> <Component {...props.pageProps} />
) : ( ) : (
<App {...props} Component={Component} router={router} /> <App {...props} Component={Component} router={router} />
)} )}

View file

@ -1,6 +1,6 @@
export default function AppServer({ children }) { export default function AppServer({ children }) {
return ( return (
<div className="app-server-root"> <div className="app-server-root" data-title={children.type.title || ''}>
<style>{`.app-server-root { border: 2px solid blue; }`}</style> <style>{`.app-server-root { border: 2px solid blue; }`}</style>
{children} {children}
</div> </div>

View file

@ -13,6 +13,8 @@ export default function Page() {
) )
} }
Page.title = 'node-rsc'
export const config = { export const config = {
runtime: 'nodejs', runtime: 'nodejs',
} }

View file

@ -38,7 +38,7 @@ 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">' const customAppServerHtml = '<div class="app-server-root"'
if (isRSC) { if (isRSC) {
expect(html1).toContain(customAppServerHtml) expect(html1).toContain(customAppServerHtml)
} else { } else {
@ -101,6 +101,9 @@ describe('Switchable runtime (prod)', () => {
isEdge: false, isEdge: false,
isRSC: true, isRSC: true,
}) })
const html = await renderViaHTTP(context.appPort, '/node-rsc')
expect(html).toContain('data-title="node-rsc"')
}) })
it('should build /node-rsc-ssr as a dynamic page with the nodejs runtime', async () => { it('should build /node-rsc-ssr as a dynamic page with the nodejs runtime', async () => {