Skip to content

Commit

Permalink
Wrong index path revalidation timer (#20818)
Browse files Browse the repository at this point in the history
Hello friends

Ran into this bug on our production site, prerenderManifest stores revalidation info for the index as `"/": { .. }`, but the code tries to access this information as `"/index"`.

This leads to our index page always having s-max-age: 1
  • Loading branch information
AriFreyr committed Jan 13, 2021
1 parent e6e402e commit 69ff95f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/next/next-server/server/incremental-cache.ts
Expand Up @@ -156,7 +156,9 @@ export class IncrementalCache {
) {
data.isStale = true
}
const manifestEntry = this.prerenderManifest.routes[pathname]

const manifestPath = toRoute(pathname)
const manifestEntry = this.prerenderManifest.routes[manifestPath]

if (data && manifestEntry) {
data.curRevalidate = manifestEntry.initialRevalidateSeconds
Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/index.js
Expand Up @@ -5,7 +5,7 @@ export async function getStaticProps() {
return {
props: { world: 'world', time: new Date().getTime() },
// bad-prop
revalidate: 1,
revalidate: 2,
}
}

Expand Down
11 changes: 10 additions & 1 deletion test/integration/prerender/test/index.test.js
Expand Up @@ -58,7 +58,7 @@ const startServer = async (optEnv = {}) => {
const expectedManifestRoutes = () => ({
'/': {
dataRoute: `/_next/data/${buildId}/index.json`,
initialRevalidateSeconds: 1,
initialRevalidateSeconds: 2,
srcRoute: null,
},
'/blog/[post3]': {
Expand Down Expand Up @@ -521,6 +521,15 @@ const runTests = (dev = false, isEmulatedServerless = false) => {
expect(data.pageProps.post).toBe('post-3')
})

if (!dev) {
it('should use correct caching headers for a revalidate page', async () => {
const initialRes = await fetchViaHTTP(appPort, '/')
expect(initialRes.headers.get('cache-control')).toBe(
's-maxage=2, stale-while-revalidate'
)
})
}

it('should navigate to a normal page and back', async () => {
const browser = await webdriver(appPort, '/')
let text = await browser.elementByCss('p').text()
Expand Down

0 comments on commit 69ff95f

Please sign in to comment.