mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? This PR fixes critical URL mutation issues in Next.js routing that were causing state pollution between requests and breaking compatibility between App Router and Pages Router during rewrite handling. ### Why? Several interconnected problems were discovered in the routing system: 1. **URL Object Mutation**: The original `parsedUrl` objects were being mutated during rewrite processing, causing state to leak between requests and potentially affecting subsequent routing decisions. 2. **Router Type Confusion**: The routing system lacked explicit tracking of whether a route belonged to the App Router or Pages Router, leading to incorrect query parameter handling and normalization logic being applied inconsistently. 3. **Query Parameter Pollution**: App Router RSC payloads were being polluted with rewrite query parameters that should only be applied to Pages Router routes, breaking the separation of concerns between the two routing systems. 4. **Catch-all Route Normalization**: Pages Router catch-all routes require specific array normalization (e.g., `["hello", "world"]`) but this was being applied inconsistently or to the wrong router type. 5. **Middleware Filtering Bypass**: The x-matched-path header handling was bypassing proper middleware query filtering in deployment scenarios. These issues manifested as test failures where Pages Router catch-all routes weren't receiving proper array values, App Router routes were getting contaminated with rewrite parameters, and the routing behavior was inconsistent between development and deployment environments. ### Dependant PR's https://github.com/vercel/vercel/pull/13927 [NAR-398](https://linear.app/vercel/issue/NAR-398)
17 lines
485 B
TypeScript
17 lines
485 B
TypeScript
import { revalidatePath } from 'next/cache'
|
|
import { NextRequest } from 'next/server'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
// Parse the path to revalidate from the request query params.
|
|
const paths = request.nextUrl.searchParams.getAll('path')
|
|
|
|
// Revalidate the paths.
|
|
for (const path of paths) {
|
|
const isPage = path.includes('[') && path.includes(']')
|
|
|
|
revalidatePath(path, isPage ? 'page' : undefined)
|
|
}
|
|
|
|
return new Response('Revalidated paths')
|
|
}
|