feat(build): optimize filterUniqueParamsCombinations to generate sub-combinations (#81321)
### What?
Optimizes the `generateParamPrefixCombinations` function (previously
`filterUniqueRootParamsCombinations`) to generate all unique
sub-combinations of route parameters while ensuring partial shells
include complete sets of root parameters.
### Why?
The previous implementation only generated combinations at the root
parameter level, which was insufficient for PPR (Partial Prerendering)
shells. PPR needs all possible prefix combinations of route parameters
to create effective shells for nested routes. For example, for a route
`/[lang]/[region]/[slug]`, we need shells for:
- `/[lang]/[region]` (complete root params)
- `/[lang]/[region]/[slug]` (full route)
Without proper sub-combinations, nested routes couldn't benefit from PPR
shell optimization, leading to performance degradation.
### How?
- Renamed `filterUniqueRootParamsCombinations` to
`generateParamPrefixCombinations` to better reflect its expanded
functionality
- Added logic to generate all prefix combinations of route parameters,
not just root-level combinations
- Implemented root parameter validation to ensure partial shells only
include complete sets of root parameters
- Added comprehensive test coverage for edge cases including undefined
parameters, missing keys, and parameter collisions
- Optimized the algorithm to skip invalid combinations early when root
parameters are incomplete
The function now generates prefix combinations systematically while
maintaining backward compatibility and preventing invalid partial
routes.
NAR-159
---------
Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>