Skip to content

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Jan 23, 2026

interpolatePath is in the hot path for most things (Link, navigation, preload, ...)

This PR adds a total of 8 lines of code (excluding comments) but significantly improves performance (by 0 to 70%) depending on the input string.

bench

@tanstack/router-core  new (decodeConfig) - interpolatePath: simple path
  1.77x faster than old (decodeCharMap)

@tanstack/router-core  new (decodeConfig) - interpolatePath: params with special characters
  1.53x faster than old (decodeCharMap)

@tanstack/router-core  new (decodeConfig) - interpolatePath: multiple params
  1.66x faster than old (decodeCharMap)

@tanstack/router-core  new (decodeConfig) - interpolatePath: complex params with many special chars
  1.61x faster than old (decodeCharMap)

@tanstack/router-core  old (decodeCharMap) - interpolatePath: curly brace params
  1.03x faster than new (decodeConfig)

@tanstack/router-core  old (decodeCharMap) - interpolatePath: optional params
  1.01x faster than new (decodeConfig)

@tanstack/router-core  old (decodeCharMap) - interpolatePath: splat/wildcard
  1.01x faster than new (decodeConfig)

@tanstack/router-core  new (decodeConfig) - interpolatePath: mixed complex path
  1.27x faster than old (decodeCharMap)

@tanstack/router-core  new (decodeConfig) - interpolatePath: aggregate all cases
  1.39x faster than old (decodeCharMap)

Summary by CodeRabbit

  • Refactor
    • Improved path parameter handling with a more efficient internal mechanism, enhancing router performance and code maintainability.

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

@nx-cloud
Copy link

nx-cloud bot commented Jan 23, 2026

View your CI Pipeline Execution ↗ for commit d386732

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

☁️ Nx Cloud last updated this comment at 2026-01-23 16:38:05 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

This PR refactors path parameter decoding across router-core from a Map-based approach (decodeCharMap) to a function-based decoder pattern. The new compileDecodeCharMap helper generates decoder functions, updating public API signatures in RouterCore, InterpolatePathOptions, and related call sites to propagate the decoder throughout the interpolation pipeline.

Changes

Cohort / File(s) Summary
Core path interpolation refactoring
packages/router-core/src/path.ts
Added compileDecodeCharMap() helper to build decoder functions from allowed characters. Replaced decodeCharMap?: Map<string, string> parameter with decoder?: (encoded: string) => string across encodeParam(), interpolatePath(), and encodePathParam(). Decoder now applied uniformly in parameter encoding for splat, named, and optional params.
Router core public API update
packages/router-core/src/router.ts
Replaced public field pathParamsDecodeCharMap?: Map<string, string> with pathParamsDecoder?: (encoded: string) => string. Updated RouterCore.update() to compile decoder via compileDecodeCharMap(). Updated all interpolatePath() call sites to pass decoder instead of decodeCharMap.
Test updates
packages/router-core/tests/path.test.ts
Updated test cases to use compileDecodeCharMap(['@', '+']) and pass decoder via decoder property in interpolatePath() options.
DevTools integration
packages/router-devtools-core/src/BaseTanStackRouterDevtoolsPanel.tsx
Updated interpolatePath() call to use decoder: pathParamsDecoder instead of decodeCharMap: pathParamsDecodeCharMap.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #5135 — Modifies path interpolation and decoding logic in the same core files, affecting how interpolatePath processes and returns parameters.
  • #5851 — Alters interpolatePath options and signature along with router.ts path-building behavior.
  • #5934 — Refactors optional-segment skipping logic within the same interpolatePath function.

Suggested labels

package: router-core, package: router-devtools-core, performance

Suggested reviewers

  • schiller-manuel
  • nlynzaad

Poem

🐰 A map once held the decoding cheer,
But functions now make paths so clear!
From characters compiled with care,
The decoder hops with data to spare.
Refactored paths, renewed and bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: refactoring interpolatePath to use a pre-compiled regex decoder instead of decodeCharMap for performance improvement.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 23, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: d386732

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