Unverified Commit 296cfacd authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Add SPR Dynamic Routes to Manifest (#8885)

* Add SPR Dynamic Routes to Manifest
This adds dynamic routes for SPR pages to the prerender manifest so we can configure the Now Builder to handle these routes as SPR routes. Otherwise, they're treated like normal `getInitialProps` pages.

* Fix types
parent c566b322
...@@ -63,6 +63,7 @@ export type SprRoute = { ...@@ -63,6 +63,7 @@ export type SprRoute = {
export type PrerenderManifest = { export type PrerenderManifest = {
version: number version: number
routes: { [route: string]: SprRoute } routes: { [route: string]: SprRoute }
dynamicRoutes: string[]
} }
export default async function build(dir: string, conf = null): Promise<void> { export default async function build(dir: string, conf = null): Promise<void> {
...@@ -412,6 +413,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -412,6 +413,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
await writeBuildId(distDir, buildId) await writeBuildId(distDir, buildId)
const finalPrerenderRoutes: { [route: string]: SprRoute } = {} const finalPrerenderRoutes: { [route: string]: SprRoute } = {}
const tbdPrerenderRoutes: string[] = []
if (staticPages.size > 0 || sprPages.size > 0) { if (staticPages.size > 0 || sprPages.size > 0) {
const combinedPages = [...staticPages, ...sprPages] const combinedPages = [...staticPages, ...sprPages]
...@@ -438,6 +440,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -438,6 +440,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
// Note: prerendering disables automatic static optimization. // Note: prerendering disables automatic static optimization.
sprPages.forEach(page => { sprPages.forEach(page => {
if (isDynamicRoute(page)) { if (isDynamicRoute(page)) {
tbdPrerenderRoutes.push(page)
delete defaultMap[page] delete defaultMap[page]
} }
}) })
...@@ -550,6 +553,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -550,6 +553,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const prerenderManifest: PrerenderManifest = { const prerenderManifest: PrerenderManifest = {
version: 1, version: 1,
routes: finalPrerenderRoutes, routes: finalPrerenderRoutes,
dynamicRoutes: tbdPrerenderRoutes.sort(),
} }
await fsWriteFile( await fsWriteFile(
......
...@@ -72,12 +72,12 @@ export function initializeSprCache({ ...@@ -72,12 +72,12 @@ export function initializeSprCache({
try { try {
prerenderManifest = dev prerenderManifest = dev
? { routes: {} } ? { routes: {}, dynamicRoutes: [] }
: JSON.parse( : JSON.parse(
fs.readFileSync(path.join(distDir, PRERENDER_MANIFEST), 'utf8') fs.readFileSync(path.join(distDir, PRERENDER_MANIFEST), 'utf8')
) )
} catch (_) { } catch (_) {
prerenderManifest = { version: 1, routes: {} } prerenderManifest = { version: 1, routes: {}, dynamicRoutes: [] }
} }
cache = new LRUCache({ cache = new LRUCache({
......
...@@ -179,6 +179,10 @@ const runTests = (dev = false) => { ...@@ -179,6 +179,10 @@ const runTests = (dev = false) => {
initialRevalidateSeconds: false initialRevalidateSeconds: false
} }
}) })
expect(manifest.dynamicRoutes).toEqual([
'/blog/[post]',
'/blog/[post]/[comment]'
])
}) })
it('outputs prerendered files correctly', async () => { it('outputs prerendered files correctly', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment