Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to always add SPR pages to prerender-manifest #8840

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
// n.b. we cannot handle this above in combinedPages because the dynamic
// page must be in the `pages` array, but not in the mapping.
exportPathMap: (defaultMap: any) => {
// Remove dynamically routed pages from the default path map. These
// pages cannot be prerendered because we don't have enough information
// to do so.
//
// Note: prerendering disables automatic static optimization.
sprPages.forEach(page => {
if (isDynamicRoute(page)) {
delete defaultMap[page]
}
})
// Append the "well-known" routes we should prerender for, e.g. blog
// post slugs.
additionalSprPaths.forEach((routes, page) => {
Expand Down Expand Up @@ -492,26 +482,22 @@ export default async function build(dir: string, conf = null): Promise<void> {
const isSpr = sprPages.has(page)
const isDynamic = isDynamicRoute(page)
let file = page === '/' ? '/index' : page
// The dynamic version of SPR pages are not prerendered. Below, we handle
// the specific prerenders of these.
if (!(isSpr && isDynamic)) {
await moveExportedPage(page, file, isSpr, 'html')
}
// move the prerender HTML file for static/SPR
await moveExportedPage(page, file, isSpr, 'html')

const hasAmp = hybridAmpPages.has(page)
if (hasAmp) {
await moveExportedPage(`${page}.amp`, `${file}.amp`, isSpr, 'html')
}

if (isSpr) {
// For a non-dynamic SPR page, we must copy its data file from export.
if (!isDynamic) {
await moveExportedPage(page, page, true, 'json')
await moveExportedPage(page, page, true, 'json')

finalPrerenderRoutes[page] = {
initialRevalidateSeconds:
exportConfig.initialPageRevalidationMap[page],
}
} else {
finalPrerenderRoutes[page] = {
initialRevalidateSeconds:
exportConfig.initialPageRevalidationMap[page],
}
if (isDynamic) {
// For a dynamic SPR page, we did not copy its html nor data exports.
// Instead, we must copy specific versions of this page as defined by
// `unstable_getStaticParams` (additionalSprPaths).
Expand Down
16 changes: 0 additions & 16 deletions packages/next/export/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,13 @@ export default async function ({
let curRenderOpts = {}
let renderMethod = renderToHTML

// eslint-disable-next-line camelcase
const renderedDuringBuild = unstable_getStaticProps => {
// eslint-disable-next-line camelcase
return !buildExport && unstable_getStaticProps && !isDynamicRoute(path)
}

if (serverless) {
const mod = require(join(
distDir,
'serverless/pages',
(page === '/' ? 'index' : page) + '.js'
))

// for non-dynamic SPR pages we should have already
// prerendered the file
if (renderedDuringBuild(mod.unstable_getStaticProps)) return results

renderMethod = mod.renderReqToHTML
const result = await renderMethod(req, res, true)
curRenderOpts = result.renderOpts || {}
Expand All @@ -133,12 +123,6 @@ export default async function ({
serverless
)

// for non-dynamic SPR pages we should have already
// prerendered the file
if (renderedDuringBuild(components.unstable_getStaticProps)) {
return results
}

if (typeof components.Component === 'string') {
html = components.Component
} else {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ const runTests = (dev = false) => {

expect(manifest.version).toBe(1)
expect(manifest.routes).toEqual({
'/blog/[post]': {
initialRevalidateSeconds: 10
},
'/blog/[post3]': {
initialRevalidateSeconds: 10
},
Expand All @@ -131,6 +134,9 @@ const runTests = (dev = false) => {
'/blog/post-2': {
initialRevalidateSeconds: 10
},
'/blog/[post]/[comment]': {
initialRevalidateSeconds: 2
},
'/blog/post-1/comment-1': {
initialRevalidateSeconds: 2
},
Expand Down