-
-
Couldn't load subscription status.
- Fork 1.7k
feat(nextjs): Client-side parameterized routes #16934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Brice Friha <[email protected]>
size-limit report 📦
|
Co-authored-by: Abhijeet Prasad <[email protected]>
Co-authored-by: Abhijeet Prasad <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see maybeParameterizeRoute be split up.
export const maybeParameterizeRoute = (route: string): string | undefined {
// caches manifest (and handles edge cases where global isn't defined)
const manifest = getManifest();
if (!manifest) {
return undefined;
}
const { staticRoutes, dynamicRoutes } = manifest;
if (!Array.isArray(staticRoutes) || !Array.isArray(dynamicRoutes)) {
return undefined;
}
const matches = findMatchingRoutes(route, staticRoutes, dynamicRoutes);
// We can always do the `sort()` call, it will short-circuit when it has one array item
// might make sense to also cache `getRouteSpecificity` results
return matches.sort((a, b) => getRouteSpecificity(a) - getRouteSpecificity(b))[0];
}
function findMatchingRoutes(route: string, staticRoutes: string[], dynamicRoutes: string[]): string[] {
const matches: string[] = [];
// first do short-circuit operations with staticRoutes
// then test on regex with dynamicRoutes
// maybe we can filter dynamicRoutes before we run regex? To get rid of
// dynamicRoutes that will definitely never match?
}|
@AbhiPrasad I did some cursor ping pong and went down the route of caching manifest, route matches and regexes instead of pre-filtering as this would have been failure-prone with catchall routes |
closes #16683
Implements the app-router parameterization by leveraging the injected manifest within our existing app-router instrumentation.
I just added the same tests for every Next.js e2e-test version + turbopack