Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use renderToStaticMarkup to render documentHTML #36213

Merged
merged 3 commits into from Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/server/node-web-streams-helper.ts
@@ -1,3 +1,5 @@
import { nonNullable } from '../lib/non-nullable'

export function readableStreamTee<T = any>(
readable: ReadableStream<T>
): [ReadableStream<T>, ReadableStream<T>] {
Expand Down Expand Up @@ -172,7 +174,7 @@ export async function continueFromInitialStream({
suffixUnclosed != null ? createPrefixStream(suffixUnclosed) : null,
dataStream ? createInlineDataStream(dataStream) : null,
suffixUnclosed != null ? createSuffixStream(closeTag) : null,
].filter(Boolean) as any
].filter(nonNullable)

return transforms.reduce(
(readable, transform) => readable.pipeThrough(transform),
Expand Down
13 changes: 1 addition & 12 deletions packages/next/server/render.tsx
Expand Up @@ -72,7 +72,6 @@ import {
streamToString,
chainStreams,
createBufferedTransformStream,
renderToStream,
renderToInitialStream,
continueFromInitialStream,
} from './node-web-streams-helper'
Expand Down Expand Up @@ -1628,17 +1627,7 @@ export async function renderToHTML(
</AmpStateContext.Provider>
)

let documentHTML: string
if (hasConcurrentFeatures) {
const documentStream = await renderToStream({
ReactDOMServer,
element: document,
generateStaticHTML: true,
})
documentHTML = await streamToString(documentStream)
} else {
documentHTML = ReactDOMServer.renderToStaticMarkup(document)
}
const documentHTML = ReactDOMServer.renderToStaticMarkup(document)

if (process.env.NODE_ENV !== 'production') {
const nonRenderedComponents = []
Expand Down
Expand Up @@ -10,6 +10,7 @@ export default function Index({ header }) {
<div>
<Head>
<meta name="rsc-title" content="index" />
<title>hello, {envVar}</title>
</Head>
<h1>{`component:index.server`}</h1>
<div>{'env:' + envVar}</div>
Expand Down
Expand Up @@ -10,6 +10,11 @@ export default async function basic(context, { env }) {
expect(pathNotFoundHTML).toContain('custom-404-page')
})

it('should render title correctly', async () => {
const res = await renderViaHTTP(context.appPort, '/')
expect(res).toContain('<title>hello, env_var_test</title>')
})

it('should support api routes', async () => {
const res = await renderViaHTTP(context.appPort, '/api/ping')
expect(res).toContain('pong')
Expand Down