0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
Commit graph

6,219 commits

Author SHA1 Message Date
Lee
68fd70bf8e
docs(router): update types for RouteOptions and RouteMatch (#4754)
Closes #3811

---------

Signed-off-by: leesb971204 <leesb971204@gmail.com>
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-07-23 23:41:22 +12:00
Flo
58093828f2
test(router-core): add unit tests for matchByPath (#4749)
This PR is simply adding unit test to the existing `matchByPath`
function.

However, it does highlight some weird cases / bugs:

- this test passes OK, I'm just wondering whether that's a real case
that can happen (in which case the test is good to keep) or if it's just
accidental
  ```ts
expect(matchByPath('/', '/a/1/b/2', { to: '/a/$id/b/$id' })).toEqual({
id: '2' })
  ```

- this test passes OK, I'm just a little surprised that it includes a
`/` char, because *any other* case does not
  ```ts
expect(matchByPath('/', '/a/', { to: '/a/$' })).toEqual({ _splat: '/',
'*': '/' })
  ```

- this does NOT work, it seems like a bug with the recent optional
params
  ```ts
expect(matchByPath('/', '/a/b', { to: '/A/{-$id}/B', caseSensitive:
false })).toEqual({})
expect(matchByPath('/', '/a/b/2', { to: '/A/{-$id}/B/{-$other}',
caseSensitive: false })).toEqual({ other: '2' })
expect(matchByPath('/', '/a/b', { to: '/A/{-$id}/B/{-$other}',
caseSensitive: false })).toEqual({})
  ```

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-23 11:58:09 +02:00
Tanner Linsley
2de6dccebe release: v1.129.8 v1.129.8 2025-07-23 09:18:33 +00:00
Flo
182df4d316
refactor(router-core): add LRU cache in front of parsePathname (#4752)
We noticed that `parsePathname` is a performance bottleneck during
navigation events. Here's a flamegraph from an application w/ ~300
routes around a navigation event:

<img width="853" height="372" alt="Screenshot 2025-07-22 at 19 36 24"
src="https://github.com/user-attachments/assets/7ed2e09a-8ea9-4170-862a-2d53c3eb4793"
/>


This PR proposes a basic least-recently-used cache implementation (that
data structure is about 4-5x slower than a `Map` according to
benchmarks, and it uses a little more memory).

We can add caching to `parsePathname` now that what it returns is
readonly (https://github.com/TanStack/router/pull/4705), which should
improve the performance of this bottleneck.

The cache is set to a size of 1000. When / if we end up making a
pre-built matcher (WIP https://github.com/TanStack/router/pull/4714), we
maybe can reduce this size. But `parsePathname` is still called w/ built
pathnames so we probably shouldn't remove the cache entirely.


When benchmarking `matchPathname` with and without the cache, we notice
a ~9x increase in throughput with the cache.
```
 ✓  @tanstack/router-core  tests/cache.bench.ts > cache.bench 7191ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · original   1,795.61  0.5055  0.7022  0.5569  0.5604  0.6234  0.6464  0.7022  ±0.22%      898
   · cached    16,307.87  0.0562  0.2294  0.0613  0.0608  0.0767  0.1007  0.1152  ±0.17%     8154   fastest

 BENCH  Summary

   @tanstack/router-core  cached - tests/cache.bench.ts > cache.bench
    9.08x faster than original
```
Assuming this 9x increase translates to a proportional reduction of the
self-time seen in the flamegraph, it would go from 55ms to 6ms.
2025-07-23 11:16:59 +02:00
Leonardo Montini
1cd917659b
docs(router): using square brackets for character escaping (#4753) 2025-07-23 12:17:50 +12:00
Tanner Linsley
c35d414681 release: v1.129.7 v1.129.7 2025-07-23 00:13:31 +00:00
Manuel Schiller
4f930d1b80
fix: ensure unique matchId when optional and required param are on the same level (#4751) v1.129.6 2025-07-22 19:02:21 +02:00
Justin Mißmahl
d87ca5ecf4
docs: fix incorrect import path in automatic code splitting guide (#4745) 2025-07-22 18:04:23 +02:00
Tanner Linsley
ad420694a3 release: v1.129.5 v1.129.5 2025-07-22 15:38:46 +00:00
Dimitris Karagiannis
d485cc23d6
fix(router-core): type mismatch for navigate function (#4625)
According to the docs this should only return a promise
https://tanstack.com/router/latest/docs/framework/react/api/router/RouterType#navigate-method
Makes sense otherwise you cannot .then() it

---------

Co-authored-by: Nico Lynzaad <44094871+nlynzaad@users.noreply.github.com>
2025-07-22 17:32:16 +02:00
Kamlesh Paul
be1b9e39b3
docs: typo in Server-Routes => Escaped Matching (#4741) 2025-07-22 17:12:30 +02:00
Tanner Linsley
95a16365ac release: v1.129.4 v1.129.4 2025-07-22 13:53:30 +00:00
Flo
082b618cbc
refactor(router-core): improve router.comparePaths performance by not using regex (#4750)
Following up on https://github.com/TanStack/router/pull/4747
Implementation by @schiller-manuel

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-22 15:52:01 +02:00
Tanner Linsley
c82415a5cd release: v1.129.3 v1.129.3 2025-07-22 11:17:11 +00:00
Flo
253ff7b4cf
refactor(router-core): improve router.comparePaths regexp performance (#4747)
We can improve perf of this function *that gets called a lot* by not
grouping the entire string, and only removing the trailing slash.

The entire string is returned by `.replace()`, so we don't ned the group
```
> "/foo/bar/".replace(/\/$/, '')
'/foo/bar'
```

Doing so, we get ~6x performance out of it.

```
 ✓  @tanstack/router-core  tests/other.bench.ts > comparePaths 2183ms
     name                       hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · oldComparePaths  1,300,774.12  0.0006  0.8563  0.0008  0.0008  0.0010  0.0010  0.0017  ±0.35%   650388
   · newComparePaths  7,773,004.63  0.0000  0.2112  0.0001  0.0001  0.0002  0.0002  0.0004  ±0.14%  3886503   fastest

 BENCH  Summary

   @tanstack/router-core  newComparePaths - tests/other.bench.ts > comparePaths
    5.98x faster than oldComparePaths
```
2025-07-22 13:15:42 +02:00
Lee
dae8833a46
docs(router): update Router.matchRoutes arguments (#4739) 2025-07-22 12:16:52 +12:00
Nico Lynzaad
f0a60cbb71
test(e2e): use locally hosted api over an external provider (#4725)
A lot of our e2e tests are querying external endpoints like
[typicode.com](https://jsonplaceholder.typicode.com) or
[example.com](https://example.com)

This is not ideal as it makes the e2e tests beholden to external factors
for example unavailability or rate limiting of these endpoints.

This PR addresses this by starting and stopping a local dummy server for
each test that needs to query external endpoints and mocks the results.
The setup and teardown have been implemented on each test package
individually so as to allow custom requirements where needed.

---------

Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-07-22 00:15:28 +02:00
Tanner Linsley
4f1eed4390 release: v1.129.2 v1.129.2 2025-07-21 21:59:24 +00:00
Lee
af673b84e4
fix(router-core): update MatchRoutesFn signature and proper deprecate old usage (#4730) 2025-07-21 23:49:01 +02:00
Tanner Linsley
24ba0b7bba release: v1.129.1 v1.129.1 2025-07-21 20:36:10 +00:00
Manuel Schiller
748a4be5a0
fix: fix start vite plugin during dev and prod (#4736) 2025-07-21 22:34:41 +02:00
Lukas Steinbrecher
86e0f8f286
docs(router): add guide on automatic code splitting (#4717)
Co-authored-by: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-07-21 17:16:09 +12:00
Tanner Linsley
dc5d0241a5 release: v1.129.0 v1.129.0 2025-07-20 23:11:25 +00:00
Manuel Schiller
f9dfb3121f
feat: pass in router instance in client function middleware (#4723)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-21 01:09:46 +02:00
Manuel Schiller
a1d54c40df
chore: don't run autofix on draft PRs (#4722) 2025-07-20 11:55:33 +02:00
Tanner Linsley
da6070c820 release: v1.128.8 v1.128.8 2025-07-20 05:39:51 +00:00
Lee
e63f4e49d3
fix(router-core): change error type in ErrorComponentProps (#4691)
fixes #4686

---------

Signed-off-by: leesb971204 <leesb971204@gmail.com>
2025-07-20 07:33:04 +02:00
Tanner Linsley
da3c81c332 release: v1.128.7 v1.128.7 2025-07-20 05:21:56 +00:00
Manuel Schiller
ddc6b5d229
fix: re-enable fuzzy matching to allow notFoundMode: fuzzy (#4721)
fixes #4712
2025-07-20 07:20:28 +02:00
Tanner Linsley
f5e3a5ff94
docs: Correct optional params docs syntax (#4720)
Correct optional parameter syntax in documentation by removing
unnecessary parentheses.

---

**Open Background Agent:** 


[Web](https://www.cursor.com/agents?id=bc-e64937de-18eb-4b0c-8696-c1e1f2eb8a9d)
·
[Cursor](https://cursor.com/background-agent?bcId=bc-e64937de-18eb-4b0c-8696-c1e1f2eb8a9d)

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2025-07-19 15:32:02 -06:00
Tanner Linsley
1591405bd1 release: v1.128.6 v1.128.6 2025-07-19 15:56:28 +00:00
Manuel Schiller
7ae6f51dd2
fix: ensure unique match id when optional parameter is not present (#4716) 2025-07-19 17:55:03 +02:00
Flo
eeb082457c
feat(router-core) path: parsePathname uses integers for Segment type (#4711)
Using integers instead of strings when possible is always better for
performance. It uses less memory, and enables faster comparisons.

This is also preparatory work for a build-time `parsePathname` as it
will result in a smaller output (though once gzipped it might not make a
difference in downloaded kB in the end).
2025-07-19 13:30:59 +02:00
Flo
113bf2130c
feat(router-core) path: parsePathname returns a readonly array (#4705)
`parsePathname` should return a `ReadonlyArray` instead of `Array`, and
`Segment` should be `readonly` too. This is because if we want to
improve perf by either caching at runtime or pre-computing routes at
build time, we need to ensure those objects can't be manipulated.

An unrelated change in this PR is also to move some inline functions to
module-scoped functions: `segmentToString` (from `resolvePath`) and
`isMatch` (from `matchByPath`). Those functions are in the hot path so
it's nice if the runtime compiler can promote them to optimized
functions.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-19 10:13:03 +02:00
Tanner Linsley
614ac9bc09 release: v1.128.5 v1.128.5 2025-07-18 23:51:30 +00:00
Manuel Schiller
241a250f58
fix: dev server improvements (#4706) 2025-07-19 01:50:06 +02:00
Tanner Linsley
12a30c5d1f
docs: Identify top 10 how-to docs, add deployment guide (#4701)
<!-- One very short sentence on the WHAT and WHY of the PR. E.g. "Remove
pathHash attribute because it is confirmed unused." or "Add DNS round
robin to improve load distribution." -->
Add a comprehensive how-to guide for deploying TanStack Router to
production and establish a multi-PR process for future documentation.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-18 15:15:07 -06:00
Tanner Linsley
fcba1347e8 release: v1.128.4 v1.128.4 2025-07-18 20:32:28 +00:00
Arciom Picikin
a9270d3c12
fix(react-router): preserve ref type in createLink with required interface properties (#4674)
Fixes #4673

I a bit simplified the `UseLinkReactProps` to make more use of typing
from React (and this simplification just fixes the bug)
Also added a test to check that the bug is no longer reproduced
2025-07-18 22:25:22 +02:00
Tanner Linsley
33302b6cda
docs: Create TanStack Router installation how-to (#4700)
Add new 'How-To' documentation section for React with a terse
installation guide to provide bite-sized, task-oriented instructions.

This new section aims to provide extremely concise, step-by-step
instructions for common tasks, making it easier for users and AI to
quickly find and follow specific procedures. Existing guides that
previously contained detailed installation steps now reference this new,
focused how-to guide to avoid content duplication and improve
discoverability.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-18 13:41:21 -06:00
Tanner Linsley
3b8b2bc24a
docs: Document optional path params for i18n (#4699)
Add documentation for prefix-based internationalization (i18n) using
Optional Path Parameters.

This PR adds a comprehensive guide on implementing i18n patterns,
covering:
- Prefix-based i18n routing (e.g., `/{-$locale}/about`)
- Complex i18n patterns with multiple optional parameters
- Language navigation using function-style `params` for `Link`
components
- Advanced i18n with route groups
- SEO best practices (canonical URLs, hreflang)
- Type safety for locale validation

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-18 13:40:12 -06:00
Manuel Schiller
5b2dd557fe
fix: during route ranking, rank params higher if followed by a static segment (#4685)
fixes #4681
2025-07-18 10:49:42 -06:00
Tanner Linsley
9d9554c43f release: v1.128.3 v1.128.3 2025-07-17 22:38:48 +00:00
Sean Cassiere
6ed0caf0a5
docs(router): prefixes and suffixes for path params (#4690) 2025-07-18 10:34:32 +12:00
wookhyung
7c6d4c1325
fix(router-core): reset statusCode to 200 on navigation start (#4664)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-18 00:25:35 +02:00
Tanner Linsley
80e76377b5 release: v1.128.2 v1.128.2 2025-07-17 22:13:43 +00:00
Manuel Schiller
1b319d0485
fix: default to addHmr in dev if not set (#4689) 2025-07-18 00:12:11 +02:00
Nico Lynzaad
e90171ab38
fix: resolve flaky e2e tests on useServerFn redirect tests (#4688)
This PR addresses some flaky tests in the redirect e2e tests for
react-start and solid start.

Specifically, when testing external redirects use useServerFn it was
trying to reach out to http://example.com. This updates it to redirect
to the local dummy server.
2025-07-18 00:02:28 +02:00
Usman S. (Max Programming)
132bd0c6d3
docs(start): build-from-scratch guide to use customVite(React/Solid)Plugin (#4678)
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-07-17 23:00:02 +12:00
Tanner Linsley
4704c97779 release: v1.128.1 v1.128.1 2025-07-17 07:34:51 +00:00