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

Fix revalidateTimings route for catchall index route #65843

Merged
merged 6 commits into from
May 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/incremental-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export class IncrementalCache implements IncrementalCacheType {
// Set the value for the revalidate seconds so if it changes we can
// update the cache with the new value.
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)
Expand Down
6 changes: 6 additions & 0 deletions test/integration/root-catchall-cache/app/[[...slug]]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const revalidate = 2
export const dynamic = 'error'

export default function Page() {
return <pre id="random">{Math.random()}</pre>
}
12 changes: 12 additions & 0 deletions test/integration/root-catchall-cache/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions test/integration/root-catchall-cache/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
assetPrefix: '/',
}
63 changes: 63 additions & 0 deletions test/integration/root-catchall-cache/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* 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()
}
)
})
Loading