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

247 commits

Author SHA1 Message Date
Manuel Schiller
983ff87b20
feat: url rewrites (#5058)
Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-09-03 23:10:33 +02:00
chorobin
581f1e56a6 tests and examples fixed 2025-08-28 23:07:23 +02:00
chorobin
568c485ef0 tests and linting 2025-08-28 00:15:27 +02:00
Nico Lynzaad
d56aa42a8a Merge branch 'relative-routing-to-current-location' into alpha 2025-08-26 23:45:03 +02:00
Nico Lynzaad
508ee37b27 Merge branch 'main' into relative-routing-to-current-location 2025-08-26 17:19:58 +02:00
chorobin
b54d056109 "serialization rulez" second attempt 2025-08-24 23:24:19 +02:00
Flo
9cc216b41c
test(react-router): add more variants to store-updates test (#5019)
Add a few more setup configurations to measure the number of `__store`
updates:
- with caching (`staleTime > 0`)
- when preloading multiple times the same route (simulates hovering a
list of links to the same page w/ different params)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-23 16:26:36 +02:00
Nico Lynzaad
41481f760a Merge branch 'main' into relative-routing-to-current-location 2025-08-19 12:39:04 +02:00
Flo
3f05c0b16b
test(router-core): fix flakiness of store-updates 'preload then navigate' test (#4995)
It turns out the 'hover preload, then navigate, w/ async loaders' test
in
`packages/react-router/tests/store-updates-during-navigation.test.tsx`
was sometimes (but very rarely) yielding 16 updates instead of the
expected 15. This PR makes minimal changes to this test so that it's now
reliably 14.

I'm not exactly sure where we lost that 1 update, so we might not be
measuring exactly the same thing. But it's still worth it to have a
robust test suite.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Improved reliability of hover preloading and navigation behavior tests
by introducing realistic loader delays and aligning interaction timing,
reducing flakiness.
* Updated assertions for store updates during navigation to reflect
observed behavior, ensuring more stable and predictable test outcomes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-19 09:18:47 +02:00
autofix-ci[bot]
452f876729
ci: apply automated fixes 2025-08-19 03:32:37 +00:00
Nico Lynzaad
8f41f218f5 cleanup tests 2025-08-19 00:12:47 +02:00
autofix-ci[bot]
723540c4c1
ci: apply automated fixes 2025-08-17 20:12:41 +00:00
Nico Lynzaad
0c9b67a0fb apply code rabbit suggestions 2025-08-17 22:06:44 +02:00
Nico Lynzaad
d5701da026 Merge branch 'main' into relative-routing-to-current-location
# Conflicts:
#	packages/router-core/src/router.ts
2025-08-17 21:16:53 +02:00
Flo
642964e4e3
refactor(router-core): reduce buildLocation object allocations (#4981)
When we can (and it's reasonable), it's always beneficial to reduce the
number of objects we create in JS, so as to minimize the memory pressure
and the GC work.

`buildLocation` gets called pretty often, so removing a few object
allocations can be very beneficial (especially inside loops).

Also, from a purely "immediate performance" point of view,
`Object.assign` tends to be faster than `{...foo}`.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Route parameter and search handling now use in-place updates to reduce
allocations and streamline iteration/control flow; behavior and public
API remain unchanged.
* **Tests**
* Updated tests to capture cloned parameter objects and assert on exact
values rather than relying on mock call history, preventing
mutation-related flakiness.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-17 18:35:45 +02:00
autofix-ci[bot]
44ad37c868
ci: apply automated fixes 2025-08-17 13:50:59 +00:00
Nico Lynzaad
ba524f121c test cleanup 2025-08-17 14:27:36 +02:00
Nico Lynzaad
9e1b1dd47b some more test refining 2025-08-17 14:06:19 +02:00
Nico Lynzaad
c53266f8f6 update react-router tests 2025-08-17 03:31:02 +02:00
Flo
78ef1c9cd6
refactor(router-core): loadMatches extra microtask (#4967)
The `loadMatches` has an unnecessary complicated async setup, probably
due to how complicated the function was before recent cleanups:

```ts
async function loadMatches() {
  try {
    await new Promise((resolve, reject) => {
      ;(async () => {
        try {
          // the logic
          resolve()
        } catch (err) {
          reject(err)
        }
      })()
    })
    // after promise
  } catch (err) {
    // error handling
  }
}
```

Aside from some scheduling differences due to unnecessary promises in
the above example, this can be simplified down to this:
```ts
async function loadMatches() {
  try {
    // the logic
    // after promise
  } catch (err) {
    // error handling
  }
}
```

This is what this PR does.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- New Features
  - No user-facing changes.

- Refactor
- Simplified internal async flow for route loading, removing redundant
promise wrapping.
- Maintains existing behavior and public API; no action required from
users.
- More consistent error handling and slightly reduced overhead during
parallel loads.
- Improves maintainability and prepares the codebase for future
enhancements.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-16 17:27:36 +02:00
Flo
f70688f787
refactor(router-core): Verify changes are necessary before updating store (#4964)
Following https://github.com/TanStack/router/pull/4916,
https://github.com/TanStack/router/pull/4925,
https://github.com/TanStack/router/pull/4926, and
https://github.com/TanStack/router/pull/4928, this PR keeps reducing the
number of store updates (`__store.setState` through `updateMatch`).

We check the values we want to set in the store are *actually different*
from what is already in the store before calling `updateMatch`

---

In the `store-updates-during-navigation` test tracking the number of
executions of a `useRouterState > select` method during a navigation,
our main test case goes from **14 calls** without this PR, to **10
calls** with this PR. Most test cases show significant improvements as
well.

---

Should be a partial improvement of
https://github.com/TanStack/router/issues/4359

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Prevented loss of previously loaded data during navigation when a
loader yields no value.
* Stabilized preloading to avoid redundant updates and unnecessary state
churn.
* Improved loading-state cleanup after navigation, reducing flicker and
inconsistent “fetching” indicators.

* **Performance**
* Reduced unnecessary state updates and re-renders during and after
preloads/loads for smoother navigation.

* **Tests**
* Updated async navigation tests to reflect refined timing and
data-return behavior and added a helper to simulate delayed async
results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-16 14:03:23 +02:00
Flo
405ef6b82b
refactor(router-core): skip beforeLoad and related store updates if options is not defined (#4928)
Following https://github.com/TanStack/router/pull/4916, this PR keeps
reducing the number of store updates (`__store.setState` through
`updateMatch`).

Early bail out of route before load step if `route.options.beforeLoad`
is not defined

---

The `store-updates-during-navigation` test tracking the number of
executions of a `useRouterState > select` method during a navigation
goes from **17 calls** without this PR, to **14 calls** with this PR (or
even 13 calls if `beforeLoad` is synchronous).

---

Should be a partial improvement of
https://github.com/TanStack/router/issues/4359

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a not-found helper and router options to configure a default Not
Found component and a default preload strategy.

* **Refactor**
* Streamlined the before-load lifecycle for more deterministic
pending-state updates, earlier pending-timeout readiness, clearer
parameter/search error surfacing, and adjusted context composition;
loader error timing is more conservative.

* **Tests**
* Expanded test coverage with new scenarios (sync before-load, not-found
flow, hover-preload/navigation) and updated navigation update
expectations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-16 10:48:50 +02:00
Flo
fe3bb45a7c
refactor(router-core): skip loader and store update if nothing to await (#4926)
Following https://github.com/TanStack/router/pull/4916 and
https://github.com/TanStack/router/pull/4925, this PR keeps reducing the
number of store updates (`__store.setState` through `updateMatch`).

Reduce amount of work in `runLoader`:
- don't `updateMatch` to set `isFetching: 'loader'` if we know the
entire function will be synchronous
- don't await `route.options.loader()` if it is synchronous
- don't update store with `loaderData` if `route.options.loader` is not
defined
- don't `await route._lazyPromise` if it has already resolved
- don't `await route._componentsPromise` if it has already resolved
- don't `await minPendingPromise` if it is not defined or has already
resolved

For a sync `loader`, with already loaded route chunks, `runLoader`
should be synchronous and trigger a single `updateMatch` call.

---

The `store-updates-during-navigation` test tracking the number of
executions of a `useRouterState > select` method during a navigation
goes from **19 calls** without this PR, to **17 calls** with this PR.

---

Should be a partial improvement of
https://github.com/TanStack/router/issues/4359

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-15 16:41:41 +02:00
Flo
6b124c66e6
refactor(router-core): head, scripts, headers are executed in parallel and can skip store update (#4925)
Following https://github.com/TanStack/router/pull/4916, this PR keeps
reducing the number of store updates (`__store.setState` through
`updateMatch`).

We can skip `route.options.head()`, `route.options.scripts()`, and
`route.options.headers()` calls, if they are not defined, and not even
call `updateMatch` after.

Additionally, `head`, `scripts` and `headers` are now called in
parallel. They don't depend on one another, and so there is no reason to
delay their execution by calling them serially.

---

This PR also fixes 2 issues:
- in `cancelMatch`, we were resetting the timeout id to `undefined`
**before** calling `clearTimeout()` with it
- `handleRedirectAndNotFound` is sometimes called w/ `match` being
`undefined` (in case of a redirecting match during preload), which went
undetected because of heavy `match!` assertions, and the many
`try/catch` blocks

---

With this PR, the `redirection in preload` test in
`store-updates-during-navigation` goes from **11 updates** during the
preload to **8 updates**.

---

Should be a partial improvement of
https://github.com/TanStack/router/issues/4359

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-15 09:37:59 +02:00
Flo
3c3497a6e8
test(react-router): improve store-updates-during-navigation tests (#4957)
The `store-updates-during-navigation.test.tsx` file tests how many times
`updateMatch` is called during a navigation (i.e. how many times the
store is updated, and all subscribers re-run).

In this PR we clean up this test file to allow us to more easily test
various navigation types. We also add a test for "redirection inside
beforeLoad" whose result will be improved by
https://github.com/TanStack/router/pull/4925

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-15 09:16:41 +02:00
Nico Lynzaad
bd034bd6a3
fix(router-core): buildLocation must consider basePath when resolving fromPath (#4930)
when building the location we are already considering the `basepath` for
the `to` path resolution but we don't do the same for the `from` path.

This PR resolves the `from` path also with the `basepath` so as to
ensure a like for like comparison with `to`.

This PR resolves #4924 and also adds a test to check for this regression
going forward

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-12 09:19:42 +02:00
Flo
916253ad2d
refactor(router-core): Reduce navigation work by making some properties non-reactive (#4916)
Some of the properties of a route match in the store do not need to be
reactive (i.e. reactive = trigger the execution of all subscribers when
they change).

This PR proposes we add a `_nonReactive` key for storing these
properties.

Changes to properties in `_nonReactive` can be made like on a regular
object, without the need to call `__store.setState`, and without making
a shallow copy of the object.

The following properties were moved to `_nonReactive` (but more would be
welcome if we can find which ones):
- `beforeLoadPromise`
- `loaderPromise`
- `pendingTimeout`
- `loadPromise`
- `displayPendingPromise`
- `minPendingPromise`
- `dehydrated`

This results in the removal of 4 `updateMatch` calls in `router-core`.
At least 1 of which is in the hot-path of a navigation (`loadMatches` >
`validResolvedMatches.forEach`). And the removal of 2 `updateMatch`
calls in `packages/react-router/src/Match.tsx` (and solid-router too).

The `ssr` property was also updated to not be reactive, but kept outside
of `_nonReactive` because it is part of the public API. This removes
another call to `updateMatch`. This key is an exception, and if in the
future we find a need to have more "public but non-reactive" properties,
we could consider
- hiding internal props in a separate type, or
- adding a dev proxy to ensure non-reactive props aren't accessed inside
`select` functions

---

This PR adds a unit-test in `react-router` that counts how many times
the `select` inside a `useRouterState` hook is called during a
navigation. Without this PR, the result of this test is **26 calls**.
With this PR, we're down to **19 calls**.

---

Should be a partial improvement of
https://github.com/TanStack/router/issues/4359

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-11 13:59:36 +02:00
Manuel Schiller
4e2605a26d
chore: bump typescript version (#4853) 2025-08-01 22:30:02 +02:00
Manuel Schiller
ce9e37366a
fix: correctly match routes with optional path params followed by req… (#4838)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-31 00:00:49 +02:00
Manuel Schiller
3c6633a705
chore: silence error in test (#4794)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-26 23:05:17 +02:00
Jaen
e83199310a
feat(react-router): add disableGlobalCatchBoundary option (#4765)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
2025-07-26 22:45:20 +02:00
Lachlan Collins
a89408affd
chore: sync TanStack repo changes (#4784)
## 🎯 Changes

- Update Prettier and use experimental CLI
- Update Nx to v21
- Fix bug in test exposed by new prettier version
- Sync issues template

## ✅ Checklist

- [x] I have followed the steps listed in the [Contributing
guide](https://github.com/TanStack/config/blob/main/CONTRIBUTING.md).
- [x] I have tested and linted this code locally.
2025-07-26 21:55:38 +10:00
Manuel Schiller
4f930d1b80
fix: ensure unique matchId when optional and required param are on the same level (#4751) 2025-07-22 19:02:21 +02:00
Manuel Schiller
ddc6b5d229
fix: re-enable fuzzy matching to allow notFoundMode: fuzzy (#4721)
fixes #4712
2025-07-20 07:20:28 +02:00
Manuel Schiller
7ae6f51dd2
fix: ensure unique match id when optional parameter is not present (#4716) 2025-07-19 17:55:03 +02: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
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
Flo
89c7b5d660
test(react-router,solid-router): test re-render for preload='viewport' (#4672) 2025-07-17 19:15:11 +12:00
Tanner Linsley
a2424c0f02
feat: optional path params (#4597)
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
Co-authored-by: Indrek Ardel <indrek@ardel.eu>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-16 13:41:58 -06:00
Nico Lynzaad
16e50e09bf
fix: resolve false positive "could not find match from" (#4610)
fixes #4284
2025-07-10 22:58:08 +02:00
Nico Lynzaad
96032358b2
fix: buildLocation check for non changing routes - consider trailing slashes (#4581)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-06 18:22:11 +02:00
Manuel Schiller
ffb1fb4c62
fix: clear pendingTimeout when match resolves (#4579) 2025-07-05 21:41:45 +02:00
Nico Lynzaad
09e152a897
fix: Make buildLocation aware of non-changing routes (#4573)
This is an attempt to resolve #4526 by making buildLocation aware of the
fact that even though there is a "to" path the route is not always
changing. This is specifically the case with to="." navigations.

This also adds a test largely based on the test provided by
[amargielewski](https://github.com/amargielewski)

fixes #4526

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-05 06:11:25 +02:00
Felipe Stanzani
ceec4f2102
feat: Add style to HeadContent (#4559)
Currently Route HeadContent don't have support to inline style tags.

After a contribution proposition made by @schiller-manuel in the Discord
Group I have decided to implement this.

I also have used this in the basic example for react-start and
solid-start and added style and style w/loader test cases to both
modules.

---------

Co-authored-by: Flo <fpellet@ensc.fr>
2025-07-02 00:28:12 +02:00
Manuel Schiller
05348a71f5
fix: correctly handle pending vs. cached matches (#4550) 2025-06-30 22:02:03 +02:00
Manuel Schiller
eb28ad02db
feat: add optional shellComponent to root route (#4528) 2025-06-27 22:17:38 +02:00
hoony
40f456e9d9
fix: Preserve cached data during concurrent navigation and refetch (#4513)
Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-06-26 23:10:12 +02:00
Naoya Shimizu(Shimmy)
980159ae10
refactor(history): use TSR_key namespace in state for hash (#4356)
Co-authored-by: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-06-23 14:48:54 +12:00
Jan Vollmer
785681fa05
fix(router-core): resolve with basepath if to is not supplied (#4472)
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-06-23 11:23:57 +12:00
Manuel Schiller
8b5accb27c
feat: Merge alpha to main (#4365)
Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>
Co-authored-by: Tanner Linsley <tannerlinsley@users.noreply.github.com>
Co-authored-by: Iha Shin (신의하) <me@xiniha.dev>
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
Co-authored-by: MoeedDar <moeed.dar@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Saša Šijak <me@ssijak.com>
Co-authored-by: Christopher Horobin <chrishorobin@hotmail.com>
Co-authored-by: Ryan Gillie <gillie.ryan@hotmail.com>
Co-authored-by: Jaga Santagostino <jagasantagostino@gmail.com>
Co-authored-by: Birk Skyum <birk.skyum@pm.me>
Co-authored-by: Yeoh Joer <yeoh.joer@outlook.com>
Co-authored-by: Dane Grant <danecando@gmail.com>
Co-authored-by: Birk Skyum <74932975+birkskyum@users.noreply.github.com>
Co-authored-by: Luis Merino <mail@luismerino.name>
Co-authored-by: ThaumRystra <9525416+ThaumRystra@users.noreply.github.com>
Co-authored-by: Adam Hunter <arhunter@gmail.com>
Co-authored-by: Leonardo Montini <lion.48m@gmail.com>
Co-authored-by: Joel Tannas <jtannas@gmail.com>
Co-authored-by: scarf <greenscarf005@gmail.com>
Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
Co-authored-by: Iñaki Larramendi <30437204+ilarramendi@users.noreply.github.com>
Co-authored-by: Hiển Đào Vinh <neo.go.vn@gmail.com>
Co-authored-by: Lleyton W Morris <42259073+ViewableGravy@users.noreply.github.com>
Co-authored-by: Lleyton Morris <lmorris@nexigen.digital>
Co-authored-by: Matthew Struble <matt@vevox.io>
Co-authored-by: Matt Anderson <matt@mattdev.ca>
Co-authored-by: Chung <chungwong@users.noreply.github.com>
Co-authored-by: Maxx Coffee <josh@joshcoffee.dev>
Co-authored-by: Joshua Coffee <joshcoffee@gannett.com>
Co-authored-by: Jack Herrington <jherr@pobox.com>
Co-authored-by: Neeraj Dalal <admin@nrjdalal.com>
Co-authored-by: Thomas Marnet <thomas.marnet@gmail.com>
Co-authored-by: Vianney Carel <vcarel@users.noreply.github.com>
Co-authored-by: Vianney Carel <vianney.carel@logfuse.fr>
Co-authored-by: Diego Rincón <97266392+diegoarff@users.noreply.github.com>
Co-authored-by: Erfan Hosseini <43422324+Erfanhosseini98@users.noreply.github.com>
Co-authored-by: IderAghbal <3328396+IderAghbal@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Andrew Jefferson <8148776+eastlondoner@users.noreply.github.com>
2025-06-10 23:19:32 +02:00