Files
next.js/test/e2e/app-dir/revalidate-path-with-rewrites/revalidate-path-with-rewrites.test.ts
Hendrik LiebauandGitHub b58b1dc901 Use rewritten pathname for implicit cache tags (#88732)
When a page is accessed via a rewrite, use the destination path (not the source path) when computing implicit tags. This ensures that calling `revalidatePath('/dest')` correctly invalidates cache entries for pages rewritten to that destination.

Fixes `'use cache'` and fetch cache with rewrites. ISR page cache was not affected because it already uses the rewritten pathname as the cache key (via `resolvedUrlPathname` in `base-server.ts`).
2026-01-19 21:50:37 +01:00

71 lines
2.3 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
const isCacheComponentsEnabled = process.env.__NEXT_CACHE_COMPONENTS === 'true'
describe('revalidatePath with rewrites', () => {
const { next } = nextTestSetup({
files: __dirname,
buildArgs: [
'--debug-build-paths',
isCacheComponentsEnabled
? '!app/legacy/**/*'
: '!app/cache-components/**/*',
],
})
describe('static page', () => {
it('should revalidate a static page that was rewritten', async () => {
const browser = await next.browser('/static')
const initialRandomData = await browser.elementById('random-data').text()
expect(initialRandomData).toBeTruthy()
// Verify the data is cached after refresh
await browser.refresh()
const refreshedRandomData = await browser
.elementById('random-data')
.text()
expect(refreshedRandomData).toBe(initialRandomData)
// Trigger revalidation via route handler
const revalidateRes = await next.fetch('/api/revalidate?path=/static')
expect(revalidateRes.status).toBe(200)
// Verify the data changed after revalidation
await retry(async () => {
await browser.refresh()
const randomData = await browser.elementById('random-data').text()
expect(randomData).not.toBe(initialRandomData)
})
})
})
describe('dynamic page', () => {
it('should revalidate a dynamic page that was rewritten', async () => {
const browser = await next.browser('/dynamic')
const initialRandomData = await browser.elementById('random-data').text()
expect(initialRandomData).toBeTruthy()
// Verify the data is cached after refresh
await browser.refresh()
const refreshedRandomData = await browser
.elementById('random-data')
.text()
expect(refreshedRandomData).toBe(initialRandomData)
// Trigger revalidation via route handler
const revalidateRes = await next.fetch('/api/revalidate?path=/dynamic')
expect(revalidateRes.status).toBe(200)
// Verify the data changed after revalidation
await retry(async () => {
await browser.refresh()
const randomData = await browser.elementById('random-data').text()
expect(randomData).not.toBe(initialRandomData)
})
})
})
})