Skip to content

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

Merged
merged 46 commits into from
Jul 15, 2025

Conversation

chargome
Copy link
Member

@chargome chargome commented Jul 11, 2025

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

@chargome chargome self-assigned this Jul 11, 2025
@chargome chargome changed the base branch from develop to cg-next-manifest-turbopack July 11, 2025 13:10
Copy link
Contributor

github-actions bot commented Jul 11, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.88 kB - -
@sentry/browser - with treeshaking flags 22.35 kB - -
@sentry/browser (incl. Tracing) 39.75 kB - -
@sentry/browser (incl. Tracing, Replay) 77.88 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.58 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.68 kB - -
@sentry/browser (incl. Feedback) 40.58 kB - -
@sentry/browser (incl. sendFeedback) 28.56 kB - -
@sentry/browser (incl. FeedbackAsync) 33.46 kB - -
@sentry/react 25.61 kB - -
@sentry/react (incl. Tracing) 41.72 kB - -
@sentry/vue 28.31 kB - -
@sentry/vue (incl. Tracing) 41.53 kB - -
@sentry/svelte 23.9 kB - -
CDN Bundle 25.18 kB - -
CDN Bundle (incl. Tracing) 39.44 kB - -
CDN Bundle (incl. Tracing, Replay) 75.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.91 kB - -
CDN Bundle - uncompressed 73.54 kB - -
CDN Bundle (incl. Tracing) - uncompressed 116.99 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.18 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.99 kB - -
@sentry/nextjs (client) 43.75 kB +0.99% +428 B 🔺
@sentry/sveltekit (client) 40.2 kB - -
@sentry/node 167.64 kB - -
@sentry/node - without tracing 100.33 kB +0.01% +1 B 🔺
@sentry/aws-serverless 128.44 kB -0.01% -1 B 🔽

View base workflow run

@chargome chargome requested review from a team, AbhiPrasad, msonnb and RulaKhaled and removed request for a team July 14, 2025 12:30
@chargome chargome marked this pull request as ready for review July 14, 2025 12:35
Copy link
Member

@AbhiPrasad AbhiPrasad left a 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?
}

@chargome
Copy link
Member Author

@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

cursor[bot]

This comment was marked as outdated.

Base automatically changed from cg-next-manifest-turbopack to develop July 15, 2025 08:50
cursor[bot]

This comment was marked as resolved.

@chargome chargome merged commit d23207c into develop Jul 15, 2025
143 checks passed
@chargome chargome deleted the cg-next-client-parameterized-routes branch July 15, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement parametrized routes for Next.js Client
2 participants