Unverified Commit ffeaa8f3 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

fix: normalization and invariant fixes for ppr (#58105)

parent 03002123
...@@ -958,12 +958,14 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -958,12 +958,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
'http://localhost' 'http://localhost'
) )
const { pathname: urlPathname } = new URL(req.url, 'http://localhost')
// For ISR the URL is normalized to the prerenderPath so if // For ISR the URL is normalized to the prerenderPath so if
// it's a data request the URL path will be the data URL, // it's a data request the URL path will be the data URL,
// basePath is already stripped by this point // basePath is already stripped by this point
if ( if (
this.enabledDirectories.pages && this.enabledDirectories.pages &&
this.normalizers.data.match(parsedUrl.pathname) this.normalizers.data.match(urlPathname)
) { ) {
parsedUrl.query.__nextDataReq = '1' parsedUrl.query.__nextDataReq = '1'
} }
...@@ -1888,7 +1890,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1888,7 +1890,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// we can use this fact to only generate the flight data for the request // we can use this fact to only generate the flight data for the request
// because we can't cache the HTML (as it's also dynamic). // because we can't cache the HTML (as it's also dynamic).
const isDynamicRSCRequest = const isDynamicRSCRequest =
this.renderOpts.experimental.ppr && isRSCRequest && !isPrefetchRSCRequest opts.experimental.ppr && isRSCRequest && !isPrefetchRSCRequest
// For pages we need to ensure the correct Vary header is set too, to avoid // For pages we need to ensure the correct Vary header is set too, to avoid
// caching issues when navigating between pages and app // caching issues when navigating between pages and app
...@@ -2138,13 +2140,13 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2138,13 +2140,13 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const doRender: Renderer = async (postponed) => { const doRender: Renderer = async (postponed) => {
// In development, we always want to generate dynamic HTML. // In development, we always want to generate dynamic HTML.
const supportsDynamicHTML = const supportsDynamicHTML: boolean =
// If this isn't a data request and we're not in development, then we // If this isn't a data request and we're not in development, then we
// support dynamic HTML. // support dynamic HTML.
(!isDataReq && opts.dev) || (!isDataReq && opts.dev === true) ||
// If this is not SSG or does not have static paths, then it supports // If this is not SSG or does not have static paths, then it supports
// dynamic HTML. // dynamic HTML.
!(isSSG || hasStaticPaths) || (!isSSG && !hasStaticPaths) ||
// If this request has provided postponed data, it supports dynamic // If this request has provided postponed data, it supports dynamic
// HTML. // HTML.
!!postponed || !!postponed ||
...@@ -2152,18 +2154,6 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2152,18 +2154,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// HTML (it's dynamic). // HTML (it's dynamic).
isDynamicRSCRequest isDynamicRSCRequest
// Ensure we bail if a prefetch RSC request is made while PPR is
// enabled that has dynamic HTML enabled.
if (
this.renderOpts.experimental.ppr &&
isPrefetchRSCRequest &&
supportsDynamicHTML
) {
throw new Error(
"Invariant: prefetch RSC requests can't support dynamic HTML"
)
}
let headers: OutgoingHttpHeaders | undefined let headers: OutgoingHttpHeaders | undefined
const origQuery = parseUrl(req.url || '', true).query const origQuery = parseUrl(req.url || '', true).query
...@@ -2317,7 +2307,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2317,7 +2307,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
) )
} else if (isAppPageRouteModule(routeModule)) { } else if (isAppPageRouteModule(routeModule)) {
if ( if (
!this.renderOpts.experimental.ppr && !opts.experimental.ppr &&
isPrefetchRSCRequest && isPrefetchRSCRequest &&
process.env.NODE_ENV === 'production' && process.env.NODE_ENV === 'production' &&
!this.minimalMode !this.minimalMode
...@@ -2655,7 +2645,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2655,7 +2645,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this.minimalMode && this.minimalMode &&
isRSCRequest && isRSCRequest &&
!isPrefetchRSCRequest && !isPrefetchRSCRequest &&
this.renderOpts.experimental.ppr opts.experimental.ppr
) { ) {
revalidate = 0 revalidate = 0
} else if ( } else if (
......
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