Skip to content

Commit fff897d

Browse files
ijjkTimer
andcommitted
Apply some renames for SSG related code (vercel#10099)
* Rename some spr related stuff to ssg * Update packages/next/lib/constants.ts Co-authored-by: Joe Haddad <timer150@gmail.com>
1 parent a2ea7a4 commit fff897d

File tree

7 files changed

+42
-42
lines changed

7 files changed

+42
-42
lines changed

packages/next/build/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Rewrite,
1010
getRedirectStatus,
1111
} from '../lib/check-custom-routes'
12-
import { SPR_GET_INITIAL_PROPS_CONFLICT } from '../lib/constants'
12+
import { SSG_GET_INITIAL_PROPS_CONFLICT } from '../lib/constants'
1313
import prettyBytes from '../lib/pretty-bytes'
1414
import { recursiveReadDir } from '../lib/recursive-readdir'
1515
import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils'
@@ -507,7 +507,7 @@ export async function isPageStatic(
507507
// A page cannot be prerendered _and_ define a data requirement. That's
508508
// contradictory!
509509
if (hasGetInitialProps && hasStaticProps) {
510-
throw new Error(SPR_GET_INITIAL_PROPS_CONFLICT)
510+
throw new Error(SSG_GET_INITIAL_PROPS_CONFLICT)
511511
}
512512

513513
// A page cannot have static parameters if it is not a dynamic page.

packages/next/build/webpack/loaders/next-serverless-loader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ const nextServerlessLoader: loader.Loader = function() {
213213
assetPrefix: "${assetPrefix}",
214214
..._renderOpts
215215
}
216-
let sprData = false
216+
let _nextData = false
217217
218218
if (req.url.match(/_next\\/data/)) {
219-
sprData = true
219+
_nextData = true
220220
req.url = req.url
221221
.replace(new RegExp('/_next/data/${escapedBuildId}/'), '/')
222222
.replace(/\\.json$/, '')
@@ -273,8 +273,8 @@ const nextServerlessLoader: loader.Loader = function() {
273273
}
274274
let result = await renderToHTML(req, res, "${page}", Object.assign({}, unstable_getStaticProps ? {} : parsedUrl.query, nowParams ? nowParams : params, _params), renderOpts)
275275
276-
if (sprData && !fromExport) {
277-
const payload = JSON.stringify(renderOpts.sprData)
276+
if (_nextData && !fromExport) {
277+
const payload = JSON.stringify(renderOpts.pageData)
278278
res.setHeader('Content-Type', 'application/json')
279279
res.setHeader('Content-Length', Buffer.byteLength(payload))
280280
res.setHeader(

packages/next/export/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export default async function(
276276
}
277277

278278
const progress = !options.silent && createProgress(filteredPaths.length)
279-
const sprDataDir = options.buildExport
279+
const pagesDataDir = options.buildExport
280280
? outDir
281281
: join(outDir, '_next/data', buildId)
282282

@@ -318,7 +318,7 @@ export default async function(
318318
distDir,
319319
buildId,
320320
outDir,
321-
sprDataDir,
321+
pagesDataDir,
322322
renderOpts,
323323
serverRuntimeConfig,
324324
subFolders,
@@ -360,7 +360,7 @@ export default async function(
360360
subFolders && route !== '/index' ? `${sep}index` : ''
361361
}.html`
362362
)
363-
const jsonDest = join(sprDataDir, `${route}.json`)
363+
const jsonDest = join(pagesDataDir, `${route}.json`)
364364

365365
await mkdirp(dirname(htmlDest))
366366
await mkdirp(dirname(jsonDest))

packages/next/export/worker.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default async function({
2525
distDir,
2626
buildId,
2727
outDir,
28-
sprDataDir,
28+
pagesDataDir,
2929
renderOpts,
3030
buildExport,
3131
serverRuntimeConfig,
@@ -131,7 +131,7 @@ export default async function({
131131
if (typeof mod === 'string') {
132132
html = mod
133133
} else {
134-
// for non-dynamic SPR pages we should have already
134+
// for non-dynamic SSG pages we should have already
135135
// prerendered the file
136136
if (renderedDuringBuild(mod.unstable_getStaticProps)) return results
137137

@@ -158,7 +158,7 @@ export default async function({
158158
serverless
159159
)
160160

161-
// for non-dynamic SPR pages we should have already
161+
// for non-dynamic SSG pages we should have already
162162
// prerendered the file
163163
if (renderedDuringBuild(components.unstable_getStaticProps)) {
164164
return results
@@ -234,14 +234,14 @@ export default async function({
234234
}
235235
}
236236

237-
if (curRenderOpts.sprData) {
237+
if (curRenderOpts.pageData) {
238238
const dataFile = join(
239-
sprDataDir,
239+
pagesDataDir,
240240
htmlFilename.replace(/\.html$/, '.json')
241241
)
242242

243243
await mkdirp(dirname(dataFile))
244-
await writeFileP(dataFile, JSON.stringify(curRenderOpts.sprData), 'utf8')
244+
await writeFileP(dataFile, JSON.stringify(curRenderOpts.pageData), 'utf8')
245245
}
246246
results.fromBuildExportRevalidate = curRenderOpts.revalidate
247247

packages/next/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ export const DOT_NEXT_ALIAS = 'private-dot-next'
2424

2525
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`
2626

27-
export const SPR_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getStaticProps. To use SPR, please remove your getInitialProps`
27+
export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with unstable_getStaticProps. To use SSG, please remove your getInitialProps`

packages/next/next-server/server/next-server.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export default class Server {
380380
req,
381381
res,
382382
pathname,
383-
{ _nextSprData: '1' },
383+
{ _nextDataReq: '1' },
384384
parsedUrl
385385
)
386386
return {
@@ -828,10 +828,10 @@ export default class Server {
828828
const isLikeServerless =
829829
typeof result.Component === 'object' &&
830830
typeof result.Component.renderReqToHTML === 'function'
831-
const isSpr = !!result.unstable_getStaticProps
831+
const isSSG = !!result.unstable_getStaticProps
832832

833833
// non-spr requests should render like normal
834-
if (!isSpr) {
834+
if (!isSSG) {
835835
// handle serverless
836836
if (isLikeServerless) {
837837
const curUrl = parseUrl(req.url!, true)
@@ -853,23 +853,23 @@ export default class Server {
853853
}
854854

855855
// Toggle whether or not this is an SPR Data request
856-
const isSprData = isSpr && query._nextSprData
857-
delete query._nextSprData
856+
const isDataReq = query._nextDataReq
857+
delete query._nextDataReq
858858

859859
// Compute the SPR cache key
860-
const sprCacheKey = parseUrl(req.url || '').pathname!
860+
const ssgCacheKey = parseUrl(req.url || '').pathname!
861861

862862
// Complete the response with cached data if its present
863-
const cachedData = await getSprCache(sprCacheKey)
863+
const cachedData = await getSprCache(ssgCacheKey)
864864
if (cachedData) {
865-
const data = isSprData
865+
const data = isDataReq
866866
? JSON.stringify(cachedData.pageData)
867867
: cachedData.html
868868

869869
this.__sendPayload(
870870
res,
871871
data,
872-
isSprData ? 'application/json' : 'text/html; charset=utf-8',
872+
isDataReq ? 'application/json' : 'text/html; charset=utf-8',
873873
cachedData.curRevalidate
874874
)
875875

@@ -883,18 +883,18 @@ export default class Server {
883883

884884
// Serverless requests need its URL transformed back into the original
885885
// request path (to emulate lambda behavior in production)
886-
if (isLikeServerless && isSprData) {
886+
if (isLikeServerless && isDataReq) {
887887
let { pathname } = parseUrl(req.url || '', true)
888888
pathname = !pathname || pathname === '/' ? '/index' : pathname
889889
req.url = `/_next/data/${this.buildId}${pathname}.json`
890890
}
891891

892892
const doRender = withCoalescedInvoke(async function(): Promise<{
893893
html: string | null
894-
sprData: any
894+
pageData: any
895895
sprRevalidate: number | false
896896
}> {
897-
let sprData: any
897+
let pageData: any
898898
let html: string | null
899899
let sprRevalidate: number | false
900900

@@ -904,7 +904,7 @@ export default class Server {
904904
renderResult = await result.Component.renderReqToHTML(req, res, true)
905905

906906
html = renderResult.html
907-
sprData = renderResult.renderOpts.sprData
907+
pageData = renderResult.renderOpts.pageData
908908
sprRevalidate = renderResult.renderOpts.revalidate
909909
} else {
910910
const renderOpts = {
@@ -914,30 +914,30 @@ export default class Server {
914914
renderResult = await renderToHTML(req, res, pathname, query, renderOpts)
915915

916916
html = renderResult
917-
sprData = renderOpts.sprData
917+
pageData = renderOpts.pageData
918918
sprRevalidate = renderOpts.revalidate
919919
}
920920

921-
return { html, sprData, sprRevalidate }
921+
return { html, pageData, sprRevalidate }
922922
})
923923

924-
return doRender(sprCacheKey, []).then(
925-
async ({ isOrigin, value: { html, sprData, sprRevalidate } }) => {
924+
return doRender(ssgCacheKey, []).then(
925+
async ({ isOrigin, value: { html, pageData, sprRevalidate } }) => {
926926
// Respond to the request if a payload wasn't sent above (from cache)
927927
if (!isResSent(res)) {
928928
this.__sendPayload(
929929
res,
930-
isSprData ? JSON.stringify(sprData) : html,
931-
isSprData ? 'application/json' : 'text/html; charset=utf-8',
930+
isDataReq ? JSON.stringify(pageData) : html,
931+
isDataReq ? 'application/json' : 'text/html; charset=utf-8',
932932
sprRevalidate
933933
)
934934
}
935935

936936
// Update the SPR cache if the head request
937937
if (isOrigin) {
938938
await setSprCache(
939-
sprCacheKey,
940-
{ html: html!, pageData: sprData },
939+
ssgCacheKey,
940+
{ html: html!, pageData },
941941
sprRevalidate
942942
)
943943
}
@@ -968,7 +968,7 @@ export default class Server {
968968
res,
969969
pathname,
970970
result.unstable_getStaticProps
971-
? { _nextSprData: query._nextSprData }
971+
? { _nextDataReq: query._nextDataReq }
972972
: query,
973973
result,
974974
{ ...this.renderOpts, amphtml, hasAmp }
@@ -994,7 +994,7 @@ export default class Server {
994994
// only add params for SPR enabled pages
995995
{
996996
...(result.unstable_getStaticProps
997-
? { _nextSprData: query._nextSprData }
997+
? { _nextDataReq: query._nextDataReq }
998998
: query),
999999
...params,
10001000
},

packages/next/next-server/server/render.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { isInAmpMode } from '../lib/amp'
2828
// Uses a module path because of the compiled output directory location
2929
import { PageConfig } from 'next/types'
3030
import { isDynamicRoute } from '../lib/router/utils/is-dynamic'
31-
import { SPR_GET_INITIAL_PROPS_CONFLICT } from '../../lib/constants'
31+
import { SSG_GET_INITIAL_PROPS_CONFLICT } from '../../lib/constants'
3232
import { AMP_RENDER_TARGET } from '../lib/constants'
3333

3434
export type ManifestItem = {
@@ -324,7 +324,7 @@ export async function renderToHTML(
324324
}
325325

326326
if (hasPageGetInitialProps && isSpr) {
327-
throw new Error(SPR_GET_INITIAL_PROPS_CONFLICT + ` ${pathname}`)
327+
throw new Error(SSG_GET_INITIAL_PROPS_CONFLICT + ` ${pathname}`)
328328
}
329329

330330
if (!!unstable_getStaticPaths && !isSpr) {
@@ -470,7 +470,7 @@ export async function renderToHTML(
470470
props.pageProps = data.props
471471
// pass up revalidate and props for export
472472
;(renderOpts as any).revalidate = data.revalidate
473-
;(renderOpts as any).sprData = props
473+
;(renderOpts as any).pageData = props
474474
}
475475
} catch (err) {
476476
if (!dev || !err) throw err

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy