Add build-time validation to detect ambiguous app routes (#85834)
## What This PR introduces build-time validation to detect ambiguous app routes that were previously going undetected until runtime. ## Why Route conflicts could occur when different dynamic segment names (e.g., `[slug]` vs `[modalSlug]`) normalize to the same routing pattern. This was particularly problematic for: - Parallel routes with different parameter names that appeared to work but had subtle conflicts - Interception routes where structural equivalence wasn't being validated - Complex routing structures where the ambiguity only manifested at runtime These conflicts would slip through the build process and cause runtime issues that were difficult to diagnose. ## How Adds a new `validateAppPaths()` function that: 1. **Normalizes paths** to detect structural equivalence (e.g., `/blog/[slug]` and `/blog/[modalSlug]` both normalize to `/blog/[*]`) 2. **Validates individual paths** for syntax errors, duplicate slug names, catch-all placement, and other issues 3. **Cross-validates paths** to detect ambiguous routes that would conflict at runtime 4. **Provides clear error messages** with actionable guidance when conflicts are detected The validation is integrated into the build process in `packages/next/src/build/index.ts` and runs automatically for all app routes. ## Changes - **New**: `validate-app-paths.ts` - Core validation logic with comprehensive path normalization and conflict detection - **New**: `validate-app-paths.test.ts` - Extensive test coverage (299 lines) covering valid configs, ambiguous routes, syntax errors, and edge cases - **Modified**: `build/index.ts` - Integration of validation into the build process - **Modified**: `get-segment-param.tsx` - Export `SegmentParam` type for reuse ## Test Coverage The test suite covers: - Valid route configurations (different segments, depths, catch-all patterns) - Ambiguous route detection (parallel routes, different dynamic segment names) - Individual path validation (syntax errors, duplicate slugs, catch-all placement) - Edge cases (empty arrays, root routes, complex nested structures) - Clear error messaging with actionable guidance
Showing
This diff is collapsed.
Please
register
or
sign in
to comment