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 Jan 14, 2021
1 parent e1184fb commit c08c77a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -1330,11 +1330,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 @@ -1362,7 +1363,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 @@ -1584,17 +1585,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 @@ -1701,7 +1703,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 @@ -1712,7 +1714,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 c08c77a

Please sign in to comment.