diff --git a/test/production/app-dir/isr-index-cache-key/app/[slug]/page.tsx b/test/production/app-dir/isr-index-cache-key/app/[slug]/page.tsx new file mode 100644 index 000000000000..b34acd1daa3c --- /dev/null +++ b/test/production/app-dir/isr-index-cache-key/app/[slug]/page.tsx @@ -0,0 +1,7 @@ +import { notFound } from 'next/navigation' + +export const dynamicParams = true + +export default function SlugPage() { + notFound() +} diff --git a/test/production/app-dir/isr-index-cache-key/app/layout.tsx b/test/production/app-dir/isr-index-cache-key/app/layout.tsx new file mode 100644 index 000000000000..888614deda3b --- /dev/null +++ b/test/production/app-dir/isr-index-cache-key/app/layout.tsx @@ -0,0 +1,8 @@ +import { ReactNode } from 'react' +export default function Root({ children }: { children: ReactNode }) { + return ( + + {children} + + ) +} diff --git a/test/production/app-dir/isr-index-cache-key/app/page.tsx b/test/production/app-dir/isr-index-cache-key/app/page.tsx new file mode 100644 index 000000000000..f9101e4a0f0b --- /dev/null +++ b/test/production/app-dir/isr-index-cache-key/app/page.tsx @@ -0,0 +1,5 @@ +export const revalidate = 1 + +export default function Page() { + return

home

+} diff --git a/test/production/app-dir/isr-index-cache-key/isr-index-cache-key.test.ts b/test/production/app-dir/isr-index-cache-key/isr-index-cache-key.test.ts new file mode 100644 index 000000000000..b8ef50293417 --- /dev/null +++ b/test/production/app-dir/isr-index-cache-key/isr-index-cache-key.test.ts @@ -0,0 +1,47 @@ +import { nextTestSetup } from 'e2e-utils' +import { retry } from 'next-test-utils' + +describe('app dir ISR index cache key', () => { + const { next } = nextTestSetup({ + files: __dirname, + }) + + function getGeneration(html: string) { + const match = html.match(/data-generation="(\d+)"/) + if (!match) throw new Error('Missing home generation') + return Number(match[1]) + } + + it('does not let a not-found /index request poison the home cache', async () => { + const initialHome = await next.fetch('/') + expect(initialHome.status).toBe(200) + const initialGeneration = getGeneration(await initialHome.text()) + + let currentGeneration = initialGeneration + await retry(async () => { + const home = await next.fetch('/') + expect(home.status).toBe(200) + currentGeneration = getGeneration(await home.text()) + expect(currentGeneration).toBeGreaterThan(initialGeneration) + }, 5000) + + await retry( + () => { + expect(Date.now()).toBeGreaterThanOrEqual(currentGeneration + 1000) + }, + 3000, + 100 + ) + + await (await next.fetch('/index')).text() + await retry(async () => { + const index = await next.fetch('/index') + expect(index.status).toBe(404) + await index.text() + }, 5000) + + const finalHome = await next.fetch('/') + expect(finalHome.status).toBe(200) + expect(getGeneration(await finalHome.text())).toBeGreaterThan(0) + }) +}) diff --git a/test/production/app-dir/isr-index-cache-key/next.config.js b/test/production/app-dir/isr-index-cache-key/next.config.js new file mode 100644 index 000000000000..807126e4cf0b --- /dev/null +++ b/test/production/app-dir/isr-index-cache-key/next.config.js @@ -0,0 +1,6 @@ +/** + * @type {import('next').NextConfig} + */ +const nextConfig = {} + +module.exports = nextConfig