next.js
2921fb33 - fix: prevent URL mutation in router rewrites (#83963)

Commit
97 days ago
fix: prevent URL mutation in router rewrites (#83963) ### 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)
Author
Parents
Loading