Unverified Commit 8a429e08 authored by Niko Sams's avatar Niko Sams Committed by GitHub

Fix revalidateTimings route for catchall index route (#65843)

fixes #65842

When setting revalidateTimings correctly use toRoute to convert `/index`
to `/`, like done for get
(https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/incremental-cache/index.ts#L213)

See #65842 for reproduction codesandbox.

The bug also exists in 14.2.3 (and below) - before #64370

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 663488cf
...@@ -598,7 +598,7 @@ export class IncrementalCache implements IncrementalCacheType { ...@@ -598,7 +598,7 @@ export class IncrementalCache implements IncrementalCacheType {
// Set the value for the revalidate seconds so if it changes we can // Set the value for the revalidate seconds so if it changes we can
// update the cache with the new value. // update the cache with the new value.
if (typeof ctx.revalidate !== 'undefined' && !ctx.fetchCache) { if (typeof ctx.revalidate !== 'undefined' && !ctx.fetchCache) {
this.revalidateTimings.set(pathname, ctx.revalidate) this.revalidateTimings.set(toRoute(pathname), ctx.revalidate)
} }
await this.cacheHandler?.set(pathname, data, ctx) await this.cacheHandler?.set(pathname, data, ctx)
......
export const revalidate = 2
export const dynamic = 'error'
export default function Page() {
return <pre id="random">{Math.random()}</pre>
}
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
module.exports = {
assetPrefix: '/',
}
/* eslint-env jest */
import { join } from 'path'
import cheerio from 'cheerio'
import {
killApp,
findPort,
nextBuild,
nextStart,
renderViaHTTP,
waitFor,
} from 'next-test-utils'
const appDir = join(__dirname, '../')
let app
let appPort
const getRandom = async (path) => {
const html = await renderViaHTTP(appPort, path)
const $ = cheerio.load(html)
return $('#random').text()
}
const runTests = () => {
it('should cache / correctly', async () => {
const random = await getRandom('/')
{
//cached response (revalidate is 2 seconds)
await waitFor(1000)
const newRandom = await getRandom('/')
expect(random).toBe(newRandom)
}
{
//stale response, triggers revalidate
await waitFor(1000)
const newRandom = await getRandom('/')
expect(random).toBe(newRandom)
}
{
//new response
await waitFor(100)
const newRandom = await getRandom('/')
expect(random).not.toBe(newRandom)
}
})
}
describe('Root Catch-all Cache', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
}
)
})
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