Skip to content

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Jan 25, 2026

interpolatePath is in the hot path of almost everything, so anything we can squeeze out of it might be worth it. This PR proposes a code-path that doesn't require parseSegment, but only works for 2 kinds of segments: /$param and /$

The lines-of-code to performance ratio isn't good enough for client-side code, so this hot path is gated behind an isServer check, and should be fully removed by dead-cod elimination for client-side builds.

before
Screenshot 2026-01-25 at 13 50 09

after
Screenshot 2026-01-25 at 13 50 05

Summary by CodeRabbit

  • Performance
    • Faster server-side path interpolation for dynamic routes and common wildcard cases, preserving existing behavior (including trailing-slash and parameter handling).
  • Tests
    • Expanded and reorganized tests to verify consistent interpolation behavior across server and client contexts; end-user behavior unchanged.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

Adds a server-aware fast-path to interpolatePath for simple dollar-based templates, threads a server flag from RouterCore into interpolatePath calls, and parameterizes tests to run with server: true and server: false.

Changes

Cohort / File(s) Summary
Path interpolation fast-path
packages/router-core/src/path.ts
Imported isServer, added server?: boolean to InterpolatePathOptions, updated interpolatePath signature, and implemented a server-mode fast path for simple $id/$ splat segments that encodes params, tracks used/missing params, and returns early; falls back to existing parser for brace-based templates.
RouterCore server propagation
packages/router-core/src/router.ts
Updated interpolatePath call sites (in buildRoute and buildLocation) to pass server: this.isServer.
Tests: server-aware parameterization
packages/router-core/tests/path.test.ts
Reworked tests to run under describe.each([{ server: true }, { server: false }]) and pass the server flag to interpolatePath, preserving expected interpolation outputs.

Sequence Diagram(s)

(omitted — changes are internal and do not introduce a multi-component sequential flow warranting a diagram)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

performance

Suggested reviewers

  • schiller-manuel
  • nlynzaad

Poem

🐰 Hoppity-hop, the server leads the race,
Dollar-wildcards find their place,
Fast-path hops through segments neat,
Params encoded, missing tracked — so sweet! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: a server-only fast path optimization added to interpolatePath function in router-core package.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Jan 25, 2026

View your CI Pipeline Execution ↗ for commit 129d310

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 11m 4s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 43s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-25 13:34:31 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 25, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6505

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6505

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6505

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6505

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6505

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6505

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6505

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6505

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6505

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6505

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6505

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6505

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6505

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6505

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6505

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6505

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6505

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6505

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6505

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6505

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6505

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6505

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6505

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6505

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6505

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6505

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6505

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6505

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6505

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6505

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6505

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6505

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6505

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6505

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6505

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6505

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6505

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6505

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6505

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6505

commit: 129d310

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/router-core/src/path.ts`:
- Line 279: The condition currently uses "isServer ?? server" which ignores the
test parameter "server" because "isServer" is always defined; change the
evaluation to prefer the function parameter first (e.g., use "server ??
isServer" or an explicit ternary like "server !== undefined ? server :
isServer") so tests can override the imported "isServer" constant; update the
condition where "isServer ?? server" appears in path.ts accordingly.

@Sheraff Sheraff merged commit b90726d into main Jan 25, 2026
6 checks passed
@Sheraff Sheraff deleted the refactor-router-core-server-only-interpolate-path-fast-path branch January 25, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants