Move pagesDir handling out of wrappedRender (#40995)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
parent
daad117127
commit
5831097c25
1 changed files with 28 additions and 26 deletions
|
@ -604,6 +604,8 @@ export async function renderToHTMLOrFlight(
|
|||
isPagesDir: boolean,
|
||||
isStaticGeneration: boolean = false
|
||||
): Promise<RenderResult | null> {
|
||||
const isFlight = req.headers.__rsc__ !== undefined
|
||||
|
||||
const capturedErrors: Error[] = []
|
||||
|
||||
const serverComponentsErrorHandler = createErrorHandler(
|
||||
|
@ -628,6 +630,32 @@ export async function renderToHTMLOrFlight(
|
|||
ComponentMod,
|
||||
} = renderOpts
|
||||
|
||||
// Handle client-side navigation to pages directory
|
||||
// This is handled before
|
||||
if (isFlight && isPagesDir) {
|
||||
stripInternalQueries(query)
|
||||
const search = stringifyQuery(query)
|
||||
|
||||
// For pages dir, there is only the SSR pass and we don't have the bundled
|
||||
// React subset. Here we directly import the flight renderer with the
|
||||
// unbundled React.
|
||||
// TODO-APP: Is it possible to hard code the flight response here instead of
|
||||
// rendering it?
|
||||
const ReactServerDOMWebpack = require('next/dist/compiled/react-server-dom-webpack/writer.browser.server')
|
||||
|
||||
// Empty so that the client-side router will do a full page navigation.
|
||||
const flightData: FlightData = pathname + (search ? `?${search}` : '')
|
||||
return new FlightRenderResult(
|
||||
ReactServerDOMWebpack.renderToReadableStream(
|
||||
flightData,
|
||||
serverComponentManifest,
|
||||
{
|
||||
onError: flightDataRendererErrorHandler,
|
||||
}
|
||||
).pipeThrough(createBufferedTransformStream())
|
||||
)
|
||||
}
|
||||
|
||||
patchFetch(ComponentMod)
|
||||
|
||||
const staticGenerationAsyncStorage = ComponentMod.staticGenerationAsyncStorage
|
||||
|
@ -653,34 +681,8 @@ export async function renderToHTMLOrFlight(
|
|||
// don't modify original query object
|
||||
query = Object.assign({}, query)
|
||||
|
||||
const isFlight = req.headers.__rsc__ !== undefined
|
||||
const isPrefetch = req.headers.__next_router_prefetch__ !== undefined
|
||||
|
||||
// Handle client-side navigation to pages directory
|
||||
if (isFlight && isPagesDir) {
|
||||
stripInternalQueries(query)
|
||||
const search = stringifyQuery(query)
|
||||
|
||||
// For pages dir, there is only the SSR pass and we don't have the bundled
|
||||
// React subset. Here we directly import the flight renderer with the
|
||||
// unbundled React.
|
||||
// TODO-APP: Is it possible to hard code the flight response here instead of
|
||||
// rendering it?
|
||||
const ReactServerDOMWebpack = require('next/dist/compiled/react-server-dom-webpack/writer.browser.server')
|
||||
|
||||
// Empty so that the client-side router will do a full page navigation.
|
||||
const flightData: FlightData = pathname + (search ? `?${search}` : '')
|
||||
return new FlightRenderResult(
|
||||
ReactServerDOMWebpack.renderToReadableStream(
|
||||
flightData,
|
||||
serverComponentManifest,
|
||||
{
|
||||
onError: flightDataRendererErrorHandler,
|
||||
}
|
||||
).pipeThrough(createBufferedTransformStream())
|
||||
)
|
||||
}
|
||||
|
||||
// TODO-APP: verify the tree is valid
|
||||
// TODO-APP: verify query param is single value (not an array)
|
||||
// TODO-APP: verify tree can't grow out of control
|
||||
|
|
Loading…
Reference in a new issue