Unverified Commit 294f8355 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Add `srcRoute` attribute to SPRv2 Manifest (#8928)

* Add new `srcRoute` attribute to SprRoute

* Update prerender manfiest test snapshot

* Fix types
parent 026d52fb
...@@ -58,6 +58,7 @@ const staticCheckWorker = require.resolve('./utils') ...@@ -58,6 +58,7 @@ const staticCheckWorker = require.resolve('./utils')
export type SprRoute = { export type SprRoute = {
initialRevalidateSeconds: number | false initialRevalidateSeconds: number | false
srcRoute: string | null
dataRoute: string dataRoute: string
} }
...@@ -521,6 +522,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -521,6 +522,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
finalPrerenderRoutes[page] = { finalPrerenderRoutes[page] = {
initialRevalidateSeconds: initialRevalidateSeconds:
exportConfig.initialPageRevalidationMap[page], exportConfig.initialPageRevalidationMap[page],
srcRoute: null,
dataRoute: path.posix.join( dataRoute: path.posix.join(
'/_next/data', '/_next/data',
`${page === '/' ? '/index' : page}.json` `${page === '/' ? '/index' : page}.json`
...@@ -537,6 +539,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -537,6 +539,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
finalPrerenderRoutes[route] = { finalPrerenderRoutes[route] = {
initialRevalidateSeconds: initialRevalidateSeconds:
exportConfig.initialPageRevalidationMap[route], exportConfig.initialPageRevalidationMap[route],
srcRoute: page,
dataRoute: path.posix.join( dataRoute: path.posix.join(
'/_next/data', '/_next/data',
`${route === '/' ? '/index' : route}.json` `${route === '/' ? '/index' : route}.json`
......
...@@ -151,6 +151,7 @@ export async function setSprCache( ...@@ -151,6 +151,7 @@ export async function setSprCache(
'/_next/data', '/_next/data',
`${pathname === '/' ? '/index' : pathname}.json` `${pathname === '/' ? '/index' : pathname}.json`
), ),
srcRoute: null, // FIXME: provide actual source route, however, when dynamically appending it doesn't really matter
initialRevalidateSeconds: revalidateSeconds, initialRevalidateSeconds: revalidateSeconds,
} }
} }
......
...@@ -153,39 +153,48 @@ const runTests = (dev = false) => { ...@@ -153,39 +153,48 @@ const runTests = (dev = false) => {
expect(manifest.routes).toEqual({ expect(manifest.routes).toEqual({
'/': { '/': {
dataRoute: '/_next/data/index.json', dataRoute: '/_next/data/index.json',
initialRevalidateSeconds: 1 initialRevalidateSeconds: 1,
srcRoute: null
}, },
'/blog/[post3]': { '/blog/[post3]': {
dataRoute: '/_next/data/blog/[post3].json', dataRoute: '/_next/data/blog/[post3].json',
initialRevalidateSeconds: 10 initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]'
}, },
'/blog/post-1': { '/blog/post-1': {
dataRoute: '/_next/data/blog/post-1.json', dataRoute: '/_next/data/blog/post-1.json',
initialRevalidateSeconds: 10 initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]'
}, },
'/blog/post-2': { '/blog/post-2': {
dataRoute: '/_next/data/blog/post-2.json', dataRoute: '/_next/data/blog/post-2.json',
initialRevalidateSeconds: 10 initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]'
}, },
'/blog/post-1/comment-1': { '/blog/post-1/comment-1': {
dataRoute: '/_next/data/blog/post-1/comment-1.json', dataRoute: '/_next/data/blog/post-1/comment-1.json',
initialRevalidateSeconds: 2 initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]'
}, },
'/blog/post-2/comment-2': { '/blog/post-2/comment-2': {
dataRoute: '/_next/data/blog/post-2/comment-2.json', dataRoute: '/_next/data/blog/post-2/comment-2.json',
initialRevalidateSeconds: 2 initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]'
}, },
'/another': { '/another': {
dataRoute: '/_next/data/another.json', dataRoute: '/_next/data/another.json',
initialRevalidateSeconds: 0 initialRevalidateSeconds: 0,
srcRoute: null
}, },
'/default-revalidate': { '/default-revalidate': {
dataRoute: '/_next/data/default-revalidate.json', dataRoute: '/_next/data/default-revalidate.json',
initialRevalidateSeconds: 1 initialRevalidateSeconds: 1,
srcRoute: null
}, },
'/something': { '/something': {
dataRoute: '/_next/data/something.json', dataRoute: '/_next/data/something.json',
initialRevalidateSeconds: false initialRevalidateSeconds: false,
srcRoute: null
} }
}) })
expect(manifest.dynamicRoutes).toEqual({ expect(manifest.dynamicRoutes).toEqual({
......
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