Unverified Commit 512daba6 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Disable streaming for `pages` (#45895)

Disable streaming SSR for `pages`, preferring the static rendering. This
was leftover from when we implemented the server components alpha on
`pages` and causes issues for people upgrading from Next.js 12 to 13
when the `chunked` response is unexpected, e.g. with certain CDN setups.

Streaming is the default in `app` and that has the right implementation
to fully leverage streaming in React including when navigating
client-side as the router is built around React transitions.
parent f3daa1c3
...@@ -945,6 +945,19 @@ export async function renderToHTMLOrFlight( ...@@ -945,6 +945,19 @@ export async function renderToHTMLOrFlight(
} = renderOpts } = renderOpts
patchFetch(ComponentMod) patchFetch(ComponentMod)
/**
* Rules of Static & Dynamic HTML:
*
* 1.) We must generate static HTML unless the caller explicitly opts
* in to dynamic HTML support.
*
* 2.) If dynamic HTML support is requested, we must honor that request
* or throw an error. It is the sole responsibility of the caller to
* ensure they aren't e.g. requesting dynamic HTML for an AMP page.
*
* These rules help ensure that other existing features like request caching,
* coalescing, and ISR continue working as intended.
*/
const generateStaticHTML = supportsDynamicHTML !== true const generateStaticHTML = supportsDynamicHTML !== true
const staticGenerationAsyncStorage: StaticGenerationAsyncStorage = const staticGenerationAsyncStorage: StaticGenerationAsyncStorage =
......
...@@ -71,7 +71,6 @@ import { allowedStatusCodes, getRedirectStatus } from '../lib/redirect-status' ...@@ -71,7 +71,6 @@ import { allowedStatusCodes, getRedirectStatus } from '../lib/redirect-status'
import RenderResult from './render-result' import RenderResult from './render-result'
import isError from '../lib/is-error' import isError from '../lib/is-error'
import { import {
readableStreamTee,
streamFromArray, streamFromArray,
streamToString, streamToString,
chainStreams, chainStreams,
...@@ -397,7 +396,6 @@ export async function renderToHTML( ...@@ -397,7 +396,6 @@ export async function renderToHTML(
previewProps, previewProps,
basePath, basePath,
devOnlyCacheBusterQueryString, devOnlyCacheBusterQueryString,
supportsDynamicHTML,
images, images,
runtime: globalRuntime, runtime: globalRuntime,
App, App,
...@@ -1100,20 +1098,8 @@ export async function renderToHTML( ...@@ -1100,20 +1098,8 @@ export async function renderToHTML(
return inAmpMode ? children : <div id="__next">{children}</div> return inAmpMode ? children : <div id="__next">{children}</div>
} }
/** // Always disable streaming for pages rendering
* Rules of Static & Dynamic HTML: const generateStaticHTML = true
*
* 1.) We must generate static HTML unless the caller explicitly opts
* in to dynamic HTML support.
*
* 2.) If dynamic HTML support is requested, we must honor that request
* or throw an error. It is the sole responsibility of the caller to
* ensure they aren't e.g. requesting dynamic HTML for an AMP page.
*
* These rules help ensure that other existing features like request caching,
* coalescing, and ISR continue working as intended.
*/
const generateStaticHTML = supportsDynamicHTML !== true
const renderDocument = async () => { const renderDocument = async () => {
// For `Document`, there are two cases that we don't support: // For `Document`, there are two cases that we don't support:
// 1. Using `Document.getInitialProps` in the Edge runtime. // 1. Using `Document.getInitialProps` in the Edge runtime.
...@@ -1178,8 +1164,8 @@ export async function renderToHTML( ...@@ -1178,8 +1164,8 @@ export async function renderToHTML(
if (renderShell) { if (renderShell) {
return renderShell(EnhancedApp, EnhancedComponent).then( return renderShell(EnhancedApp, EnhancedComponent).then(
async (stream) => { async (stream) => {
const forwardStream = readableStreamTee(stream)[1] await stream.allReady
const html = await streamToString(forwardStream) const html = await streamToString(stream)
return { html, head } return { html, head }
} }
) )
......
...@@ -39,7 +39,8 @@ export default function (context, { env, runtime }) { ...@@ -39,7 +39,8 @@ export default function (context, { env, runtime }) {
} }
}) })
expect(gotFallback).toBe(true) // Streaming is disabled for pages, no fallback should be rendered.
expect(gotFallback).toBe(false)
expect(gotData).toBe(true) expect(gotData).toBe(true)
} }
) )
......
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