Skip to content

Commit

Permalink
Fix aspath for GIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanta Kodama committed Dec 29, 2020
1 parent 3140e40 commit ad3b35d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,11 +1321,12 @@ export default class Server {
typeof components.Component === 'object' &&
typeof (components.Component as any).renderReqToHTML === 'function'
const isSSG = !!components.getStaticProps
const isServerProps = !!components.getServerSideProps
const hasServerProps = !!components.getServerSideProps
const hasStaticPaths = !!components.getStaticPaths
const hasGetInitialProps = !!(components.Component as any).getInitialProps

// Toggle whether or not this is a Data request
const isDataReq = !!query._nextDataReq && (isSSG || isServerProps)
const isDataReq = !!query._nextDataReq && (isSSG || hasServerProps)
delete query._nextDataReq

// we need to ensure the status code if /404 is visited directly
Expand Down Expand Up @@ -1353,7 +1354,7 @@ export default class Server {
let previewData: string | false | object | undefined
let isPreviewMode = false

if (isServerProps || isSSG) {
if (hasServerProps || isSSG) {
previewData = tryGetPreviewData(req, res, this.renderOpts.previewProps)
isPreviewMode = previewData !== false
}
Expand Down Expand Up @@ -1569,17 +1570,18 @@ export default class Server {
locale,
locales,
defaultLocale,
// For getServerSideProps we need to ensure we use the original URL
// For getServerSideProps and getInitialProps we need to ensure we use the original URL
// and not the resolved URL to prevent a hydration mismatch on
// asPath
resolvedAsPath: isServerProps
? formatUrl({
// we use the original URL pathname less the _next/data prefix if
// present
pathname: `${urlPathname}${hadTrailingSlash ? '/' : ''}`,
query: origQuery,
})
: resolvedUrl,
resolvedAsPath:
hasServerProps || hasGetInitialProps
? formatUrl({
// we use the original URL pathname less the _next/data prefix if
// present
pathname: `${urlPathname}${hadTrailingSlash ? '/' : ''}`,
query: origQuery,
})
: resolvedUrl,
}

renderResult = await renderToHTML(
Expand Down Expand Up @@ -1686,7 +1688,7 @@ export default class Server {
let resHtml = html

const revalidateOptions =
!this.renderOpts.dev || (isServerProps && !isDataReq)
!this.renderOpts.dev || (hasServerProps && !isDataReq)
? {
private: isPreviewMode,
stateful: !isSSG,
Expand All @@ -1697,7 +1699,7 @@ export default class Server {
if (
!isResSent(res) &&
!isNotFound &&
(isSSG || isDataReq || isServerProps)
(isSSG || isDataReq || hasServerProps)
) {
if (isRedirect && !isDataReq) {
await handleRedirect(pageData)
Expand Down

0 comments on commit ad3b35d

Please sign in to comment.