next.js
30c64ba0 - Fix interception route rewrites for nested dynamic routes (#84413)

Commit
105 days ago
Fix interception route rewrites for nested dynamic routes (#84413) ### What? Fixes interception routes with dynamic parameters that were generating rewrite rules in an incorrect format, preventing proper URL rewriting by Vercel and Next.js. ### Why? The failing test `parallel-routes-and-interception-nested-dynamic-routes` revealed that interception routes with dynamic segments weren't working correctly when deployed. The root cause was that the previous implementation using `safePathToRegexp` produced rewrite destinations that weren't in a format compatible with direct parameter substitution during the rewrite process. When the router tried to rewrite URLs to their intercepted destinations, the parameter format prevented Vercel/Next.js from properly substituting the captured values, causing routes to fail. ### How? Completely rewrote the `generate-interception-routes-rewrites` logic to use `getNamedRouteRegex` instead of `safePathToRegexp`. This ensures: 1. **Correct rewrite format**: Rewrites are now generated in a format that allows direct parameter substitution 2. **Parameter consistency**: Source regex is generated first, then its parameter reference is passed to destination generation to ensure parameter names match for substitution 3. **Clean URLs**: Added `stripNormalizedSeparators` to prevent `_NEXTSEP_` internal separator from leaking into client-facing URLs 4. **Stricter matching**: Updated router reducers to pass `next-url` header for the stricter Next-Url regex matching required by the new rewrite mechanism **Testing:** - Added 23 comprehensive tests for rewrite generation covering all interception marker types - Added 18 tests for route matching utilities - All existing tests pass including the previously failing `parallel-routes-and-interception-nested-dynamic-routes` Fixes the failing test: `test/e2e/app-dir/parallel-routes-and-interception-nested-dynamic-routes/parallel-routes-and-interception-nested-dynamic-routes.test.ts` NAR-432
Author
Parents
Loading