-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: JJ Kasper <[email protected]>
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
assetPrefix: '/', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
) | ||
}) |