next.js
e0d612eb - Fix build crash with parallel routes and root-level dynamic parameters (#85074)

Commit
70 days ago
Fix build crash with parallel routes and root-level dynamic parameters (#85074) ### What? Fixes a build-time crash that occurs when using parallel routes (`@slot` syntax) combined with root-level dynamic parameters (e.g., `[locale]`) in the App Router. ### Why? When building static paths for routes with both parallel routes and root-level dynamic parameters, the build would crash during pathname generation. This happened because the code was using `RouteRegex.groups` to determine parameter properties (`repeat`/`optional`), but the regex groups didn't properly handle segment names for nested parallel route structures. The pathname replacement logic would fail when trying to match segment patterns, causing the build to abort. This is a critical issue because it blocks developers from using a common pattern: internationalization with parallel routes (e.g., `/[locale]/@modal/...`). ### How? The fix refactors the parameter validation logic to use `DynamicParamTypes` directly instead of relying on `RouteRegex`: 1. Created a new `getParamProperties()` utility in `get-segment-param.tsx` that determines `repeat` and `optional` properties based on the parameter type (catchall, optional-catchall, dynamic, etc.) 2. Updated `buildAppStaticPaths()` to use this utility instead of `RouteRegex.groups` 3. Changed pathname replacement to use the segment name from `childrenRouteParamSegments` rather than reconstructing it from the regex pattern This approach: - Eliminates the mismatch between regex-based pattern matching and actual segment structure - Properly handles parallel route segment names - Makes the code more maintainable by using the type system instead of regex internals Fixes #84509
Author
Parents
Loading