Skip to content

Commit

Permalink
fix: normalization and invariant fixes for ppr (#58105)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh authored Nov 6, 2023
1 parent 0300212 commit ffeaa8f
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
'http://localhost'
)

const { pathname: urlPathname } = new URL(req.url, 'http://localhost')

// For ISR the URL is normalized to the prerenderPath so if
// it's a data request the URL path will be the data URL,
// basePath is already stripped by this point
if (
this.enabledDirectories.pages &&
this.normalizers.data.match(parsedUrl.pathname)
this.normalizers.data.match(urlPathname)
) {
parsedUrl.query.__nextDataReq = '1'
}
Expand Down Expand Up @@ -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
// because we can't cache the HTML (as it's also dynamic).
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
// caching issues when navigating between pages and app
Expand Down Expand Up @@ -2138,32 +2140,20 @@ export default abstract class Server<ServerOptions extends Options = Options> {

const doRender: Renderer = async (postponed) => {
// 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
// support dynamic HTML.
(!isDataReq && opts.dev) ||
(!isDataReq && opts.dev === true) ||
// If this is not SSG or does not have static paths, then it supports
// dynamic HTML.
!(isSSG || hasStaticPaths) ||
(!isSSG && !hasStaticPaths) ||
// If this request has provided postponed data, it supports dynamic
// HTML.
!!postponed ||
// If this is a dynamic RSC request, then this render supports dynamic
// HTML (it's dynamic).
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

const origQuery = parseUrl(req.url || '', true).query
Expand Down Expand Up @@ -2317,7 +2307,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
)
} else if (isAppPageRouteModule(routeModule)) {
if (
!this.renderOpts.experimental.ppr &&
!opts.experimental.ppr &&
isPrefetchRSCRequest &&
process.env.NODE_ENV === 'production' &&
!this.minimalMode
Expand Down Expand Up @@ -2655,7 +2645,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this.minimalMode &&
isRSCRequest &&
!isPrefetchRSCRequest &&
this.renderOpts.experimental.ppr
opts.experimental.ppr
) {
revalidate = 0
} else if (
Expand Down

0 comments on commit ffeaa8f

Please sign in to comment.