mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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`).
21 lines
585 B
TypeScript
21 lines
585 B
TypeScript
import { revalidatePath } from 'next/cache'
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const isCacheComponentsEnabled = !!process.env.__NEXT_CACHE_COMPONENTS
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const sourcePath = request.nextUrl.searchParams.get('path')
|
|
|
|
if (!sourcePath) {
|
|
return NextResponse.json(
|
|
{ error: 'Missing path parameter' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
const prefix = isCacheComponentsEnabled ? '/cache-components' : '/legacy'
|
|
revalidatePath(`${prefix}${sourcePath}`)
|
|
|
|
return NextResponse.json({ revalidated: true })
|
|
}
|