diff --git a/packages/next/build/utils.ts b/packages/next/build/utils.ts index 2e9f9d3e24cb..8be1b034dfe7 100644 --- a/packages/next/build/utils.ts +++ b/packages/next/build/utils.ts @@ -9,7 +9,7 @@ import { Rewrite, getRedirectStatus, } from '../lib/check-custom-routes' -import { SPR_GET_INITIAL_PROPS_CONFLICT } from '../lib/constants' +import { SSG_GET_INITIAL_PROPS_CONFLICT } from '../lib/constants' import prettyBytes from '../lib/pretty-bytes' import { recursiveReadDir } from '../lib/recursive-readdir' import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils' @@ -507,7 +507,7 @@ export async function isPageStatic( // A page cannot be prerendered _and_ define a data requirement. That's // contradictory! if (hasGetInitialProps && hasStaticProps) { - throw new Error(SPR_GET_INITIAL_PROPS_CONFLICT) + throw new Error(SSG_GET_INITIAL_PROPS_CONFLICT) } // A page cannot have static parameters if it is not a dynamic page. diff --git a/packages/next/build/webpack/loaders/next-serverless-loader.ts b/packages/next/build/webpack/loaders/next-serverless-loader.ts index fdc47e8fde56..a454ca739ad5 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader.ts @@ -213,10 +213,10 @@ const nextServerlessLoader: loader.Loader = function() { assetPrefix: "${assetPrefix}", ..._renderOpts } - let sprData = false + let _nextData = false if (req.url.match(/_next\\/data/)) { - sprData = true + _nextData = true req.url = req.url .replace(new RegExp('/_next/data/${escapedBuildId}/'), '/') .replace(/\\.json$/, '') @@ -273,8 +273,8 @@ const nextServerlessLoader: loader.Loader = function() { } let result = await renderToHTML(req, res, "${page}", Object.assign({}, unstable_getStaticProps ? {} : parsedUrl.query, nowParams ? nowParams : params, _params), renderOpts) - if (sprData && !fromExport) { - const payload = JSON.stringify(renderOpts.sprData) + if (_nextData && !fromExport) { + const payload = JSON.stringify(renderOpts.pageData) res.setHeader('Content-Type', 'application/json') res.setHeader('Content-Length', Buffer.byteLength(payload)) res.setHeader( diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index da26b61dd831..d6cbd2a0204b 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -276,7 +276,7 @@ export default async function( } const progress = !options.silent && createProgress(filteredPaths.length) - const sprDataDir = options.buildExport + const pagesDataDir = options.buildExport ? outDir : join(outDir, '_next/data', buildId) @@ -318,7 +318,7 @@ export default async function( distDir, buildId, outDir, - sprDataDir, + pagesDataDir, renderOpts, serverRuntimeConfig, subFolders, @@ -360,7 +360,7 @@ export default async function( subFolders && route !== '/index' ? `${sep}index` : '' }.html` ) - const jsonDest = join(sprDataDir, `${route}.json`) + const jsonDest = join(pagesDataDir, `${route}.json`) await mkdirp(dirname(htmlDest)) await mkdirp(dirname(jsonDest)) diff --git a/packages/next/export/worker.js b/packages/next/export/worker.js index 072faae8dd11..1948939a69d1 100644 --- a/packages/next/export/worker.js +++ b/packages/next/export/worker.js @@ -25,7 +25,7 @@ export default async function({ distDir, buildId, outDir, - sprDataDir, + pagesDataDir, renderOpts, buildExport, serverRuntimeConfig, @@ -131,7 +131,7 @@ export default async function({ if (typeof mod === 'string') { html = mod } else { - // for non-dynamic SPR pages we should have already + // for non-dynamic SSG pages we should have already // prerendered the file if (renderedDuringBuild(mod.unstable_getStaticProps)) return results @@ -158,7 +158,7 @@ export default async function({ serverless ) - // for non-dynamic SPR pages we should have already + // for non-dynamic SSG pages we should have already // prerendered the file if (renderedDuringBuild(components.unstable_getStaticProps)) { return results @@ -234,14 +234,14 @@ export default async function({ } } - if (curRenderOpts.sprData) { + if (curRenderOpts.pageData) { const dataFile = join( - sprDataDir, + pagesDataDir, htmlFilename.replace(/\.html$/, '.json') ) await mkdirp(dirname(dataFile)) - await writeFileP(dataFile, JSON.stringify(curRenderOpts.sprData), 'utf8') + await writeFileP(dataFile, JSON.stringify(curRenderOpts.pageData), 'utf8') } results.fromBuildExportRevalidate = curRenderOpts.revalidate diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index be1c47741295..7692ffb747cc 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -24,4 +24,4 @@ export const DOT_NEXT_ALIAS = 'private-dot-next' export const PUBLIC_DIR_MIDDLEWARE_CONFLICT = `You can not have a '_next' folder inside of your public folder. This conflicts with the internal '/_next' route. https://err.sh/zeit/next.js/public-next-folder-conflict` -export const SPR_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getStaticProps. To use SPR, please remove your getInitialProps` +export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getStaticProps. To use SSG, please remove your getInitialProps` diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index eb173606a59b..9a7ccf148023 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -380,7 +380,7 @@ export default class Server { req, res, pathname, - { _nextSprData: '1' }, + { _nextDataReq: '1' }, parsedUrl ) return { @@ -828,10 +828,10 @@ export default class Server { const isLikeServerless = typeof result.Component === 'object' && typeof result.Component.renderReqToHTML === 'function' - const isSpr = !!result.unstable_getStaticProps + const isSSG = !!result.unstable_getStaticProps // non-spr requests should render like normal - if (!isSpr) { + if (!isSSG) { // handle serverless if (isLikeServerless) { const curUrl = parseUrl(req.url!, true) @@ -853,23 +853,23 @@ export default class Server { } // Toggle whether or not this is an SPR Data request - const isSprData = isSpr && query._nextSprData - delete query._nextSprData + const isDataReq = query._nextDataReq + delete query._nextDataReq // Compute the SPR cache key - const sprCacheKey = parseUrl(req.url || '').pathname! + const ssgCacheKey = parseUrl(req.url || '').pathname! // Complete the response with cached data if its present - const cachedData = await getSprCache(sprCacheKey) + const cachedData = await getSprCache(ssgCacheKey) if (cachedData) { - const data = isSprData + const data = isDataReq ? JSON.stringify(cachedData.pageData) : cachedData.html this.__sendPayload( res, data, - isSprData ? 'application/json' : 'text/html; charset=utf-8', + isDataReq ? 'application/json' : 'text/html; charset=utf-8', cachedData.curRevalidate ) @@ -883,7 +883,7 @@ export default class Server { // Serverless requests need its URL transformed back into the original // request path (to emulate lambda behavior in production) - if (isLikeServerless && isSprData) { + if (isLikeServerless && isDataReq) { let { pathname } = parseUrl(req.url || '', true) pathname = !pathname || pathname === '/' ? '/index' : pathname req.url = `/_next/data/${this.buildId}${pathname}.json` @@ -891,10 +891,10 @@ export default class Server { const doRender = withCoalescedInvoke(async function(): Promise<{ html: string | null - sprData: any + pageData: any sprRevalidate: number | false }> { - let sprData: any + let pageData: any let html: string | null let sprRevalidate: number | false @@ -904,7 +904,7 @@ export default class Server { renderResult = await result.Component.renderReqToHTML(req, res, true) html = renderResult.html - sprData = renderResult.renderOpts.sprData + pageData = renderResult.renderOpts.pageData sprRevalidate = renderResult.renderOpts.revalidate } else { const renderOpts = { @@ -914,21 +914,21 @@ export default class Server { renderResult = await renderToHTML(req, res, pathname, query, renderOpts) html = renderResult - sprData = renderOpts.sprData + pageData = renderOpts.pageData sprRevalidate = renderOpts.revalidate } - return { html, sprData, sprRevalidate } + return { html, pageData, sprRevalidate } }) - return doRender(sprCacheKey, []).then( - async ({ isOrigin, value: { html, sprData, sprRevalidate } }) => { + return doRender(ssgCacheKey, []).then( + async ({ isOrigin, value: { html, pageData, sprRevalidate } }) => { // Respond to the request if a payload wasn't sent above (from cache) if (!isResSent(res)) { this.__sendPayload( res, - isSprData ? JSON.stringify(sprData) : html, - isSprData ? 'application/json' : 'text/html; charset=utf-8', + isDataReq ? JSON.stringify(pageData) : html, + isDataReq ? 'application/json' : 'text/html; charset=utf-8', sprRevalidate ) } @@ -936,8 +936,8 @@ export default class Server { // Update the SPR cache if the head request if (isOrigin) { await setSprCache( - sprCacheKey, - { html: html!, pageData: sprData }, + ssgCacheKey, + { html: html!, pageData }, sprRevalidate ) } @@ -968,7 +968,7 @@ export default class Server { res, pathname, result.unstable_getStaticProps - ? { _nextSprData: query._nextSprData } + ? { _nextDataReq: query._nextDataReq } : query, result, { ...this.renderOpts, amphtml, hasAmp } @@ -994,7 +994,7 @@ export default class Server { // only add params for SPR enabled pages { ...(result.unstable_getStaticProps - ? { _nextSprData: query._nextSprData } + ? { _nextDataReq: query._nextDataReq } : query), ...params, }, diff --git a/packages/next/next-server/server/render.tsx b/packages/next/next-server/server/render.tsx index aebb107c555c..be8f52450c75 100644 --- a/packages/next/next-server/server/render.tsx +++ b/packages/next/next-server/server/render.tsx @@ -28,7 +28,7 @@ import { isInAmpMode } from '../lib/amp' // Uses a module path because of the compiled output directory location import { PageConfig } from 'next/types' import { isDynamicRoute } from '../lib/router/utils/is-dynamic' -import { SPR_GET_INITIAL_PROPS_CONFLICT } from '../../lib/constants' +import { SSG_GET_INITIAL_PROPS_CONFLICT } from '../../lib/constants' import { AMP_RENDER_TARGET } from '../lib/constants' export type ManifestItem = { @@ -324,7 +324,7 @@ export async function renderToHTML( } if (hasPageGetInitialProps && isSpr) { - throw new Error(SPR_GET_INITIAL_PROPS_CONFLICT + ` ${pathname}`) + throw new Error(SSG_GET_INITIAL_PROPS_CONFLICT + ` ${pathname}`) } if (!!unstable_getStaticPaths && !isSpr) { @@ -470,7 +470,7 @@ export async function renderToHTML( props.pageProps = data.props // pass up revalidate and props for export ;(renderOpts as any).revalidate = data.revalidate - ;(renderOpts as any).sprData = props + ;(renderOpts as any).pageData = props } } catch (err) { if (!dev || !err) throw err