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

6,709 commits

Author SHA1 Message Date
Manuel Schiller
f6fcb1bf68
fix: correctly replace bracked escaped part (#4968)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Routing now correctly handles bracketed dynamic segments with multiple
characters in paths. Contents like [userId] are preserved in full (no
longer truncated to a single character), ensuring accurate initial route
generation and consistent navigation behavior for dynamic routes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-16 17:24:25 +02:00
Tanner Linsley
74be2861ca release: v1.131.18 v1.131.18 2025-08-16 12:04:58 +00: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
Tanner Linsley
1ccf7c827a release: v1.131.17 v1.131.17 2025-08-16 08:50:25 +00: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
Tanner Linsley
4dd0cbeb3e release: v1.131.16 v1.131.16 2025-08-15 21:21:30 +00:00
Flo
d6a77e1d6b
refactor(router-core): flatten loadMatches (#4961)
This PR *should* be a no-op. Just restructuring the code to have all the
functions used by `loadMatches` at the same level, instead of nested
callbacks. In order to still have access to the data that was previously
in scope because of nesting, we use a `innerLoadContext` object, which
is basically just the arguments of `loadMatches`, and a few mutables.

However, in order to do so, we have to rearrange promises in an area
that is sensitive to any microtask order change, and we did change some
of them. So this is not *really* a no-op, even though this does not
attempt any optimization.

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

## Summary by CodeRabbit

- New Features
- Smoother navigations with predictable pending states and minimum
display durations.
  - More consistent head/meta updates after route loading.
- Bug Fixes
- More reliable redirects and 404 handling, including during preloading
and SSR.
  - Reduced UI flicker by refining pending and preloading behavior.
- Refactor
- Reworked the routing load pipeline for improved performance,
stability, and SSR behavior.
- Streamlined before-load steps for clearer, more consistent execution.
- Tests
  - Updated tests to reflect the new loading flow.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-15 23:19:56 +02:00
Tanner Linsley
0df9067bcc release: v1.131.15 v1.131.15 2025-08-15 15:17:04 +00:00
Manuel Schiller
b8ef497d90
fix: do not rename functions / variables when code splitting (#4960)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-15 17:13:26 +02:00
Tanner Linsley
be3931bf4b release: v1.131.14 v1.131.14 2025-08-15 14:43:10 +00: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
Tanner Linsley
191ad1eda4 release: v1.131.13 v1.131.13 2025-08-15 07:51:01 +00:00
Flo
4e959b4426
refactor(router-core): simplify handleRedirectAndNotFound (#4958)
Minor cleanup of `handleRedirectAndNotFound` in `router-core`. The code
looked like there were 3 possible cases, but `err` is only handled if
it's a redirect or a notFound.

This PR is a no-op, it's just code cleanup without any functional
changes.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-15 09:49:38 +02:00
Tanner Linsley
e8e7a74b20 release: v1.131.12 v1.131.12 2025-08-15 07:39:21 +00: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
Tanner Linsley
6999fd9db8 release: v1.131.11 v1.131.11 2025-08-13 23:03:50 +00:00
Manuel Schiller
b3e8e4aaf7
fix: initialize generator in esbuild plugin (#4949) 2025-08-14 01:00:41 +02:00
Tanner Linsley
8a15b54da3 release: v1.131.10 v1.131.10 2025-08-13 22:36:13 +00:00
Gürkan Sevil
f889a2470d
fix(react-router): correctly assign createLazyFileRoute on window (#4948) 2025-08-14 00:29:49 +02:00
Tanner Linsley
69c1d753ac release: v1.131.9 v1.131.9 2025-08-13 20:47:33 +00:00
Brenley Dueck
e86dfea947
fix: remount deps for solid (#4947) 2025-08-13 22:41:56 +02:00
Lee
055ba50212
docs(router): update NotFoundError type (#4866)
- Mark the `global` property of `NotFoundError` as deprecated
- Add a description for `headers`
- Sort the properties in order

Signed-off-by: leesb971204 <leesb971204@gmail.com>
2025-08-13 16:19:14 +12:00
Piotr Kuczynski
ffec133383
docs(eslint): resolve conflict with typescript-eslint/only-throw-error rule (#4934)
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-08-13 13:58:04 +12:00
Sean Cassiere
63c6df8d13
test(solid-router): add test from #4930 (#4941) 2025-08-13 13:36:12 +12:00
Tanner Linsley
1707df15c4 release: v1.131.8 v1.131.8 2025-08-13 01:07:21 +00:00
jihoon
638a902ee6
fix(router-plugin): add support for boolean and null literals in code splitter (#4915)
Co-authored-by: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>
2025-08-13 13:01:57 +12:00
Tanner Linsley
38abdc2869 release: v1.131.7 v1.131.7 2025-08-12 07:21:13 +00: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
alexgaudon
cb895ff86c
docs: Fix grammar and improve clarity in routeTree.gen.ts FAQ. (#4922) 2025-08-11 20:17:15 +02:00
Tanner Linsley
1608e66173 release: v1.131.6 v1.131.6 2025-08-11 16:28:55 +00:00
Manuel Schiller
c71a9b8fd5
fix: server functions reference serialization (#4913) 2025-08-11 18:22:07 +02:00
Tanner Linsley
93c624c5d3 release: v1.131.5 v1.131.5 2025-08-11 14:06:14 +00:00
Flo
039889abb8
refactor(router-core): Avoid creating empty objects when not necessary (#4923)
`undefined` is allowed as the parameter of the `...` spread operator. It
is not necessary to create an empty object `{}` as a fallback.

Creating objects incurs more work by the garbage collector, so
minimizing how many are created if a performance improvement.
2025-08-11 15:58:46 +02:00
Flo
94ea50ff19
refactor(react-router,solid-router): Minor simplification of MatchInner match logic in select (#4921)
We don't need the `matchIndex` in `Match > MatchInner > useRouterState >
select`. It must have been left after a previous refactor.
2025-08-11 15:58:39 +02:00
Tanner Linsley
b84a5ce0c1 release: v1.131.4 v1.131.4 2025-08-11 12:01:14 +00: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
Abdullah Al-taheri
fe43f1bf53
docs: Update static-prerendering.md (#4903)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-11 01:53:44 +02:00
Tanner Linsley
cf99c6a3f4 release: v1.131.3 v1.131.3 2025-08-10 21:40:01 +00:00
Flo
fd341ad200
refactor(router-core): strip internal types from public build (#4907)
This PR proposes we use the `@internal` JSDoc tag, and `--stripInternal`
typescript compiler option to remove internal keys from the public
`.d.ts` files.

Docs for `stripInternal`:
https://www.typescriptlang.org/tsconfig/#stripInternal

This helps ensuring internal values aren't considered as part of the
*public API surface* by users, allowing us more flexibility in
refactoring.

> [!WARNING]
> This PR proposes we add `stripInternal` to the entire repo, not just
`router-core`. However there are already some values marked as internal
that weren't added by this PR:
> - `InferStructuralSharing` in `react-router`
> - `handleHashScroll` in `router-core > scrollRestoration`
> - many `InferFoo` types in `router-core > typePrimitives`
>
> as a result of this, we might have to switch some of those `@internal`
tags to something else (like `@private` maybe?) because they are, in
fact, necessary for the build to be correct.

Example:
```ts
export type Foo = {
  a: number,
  /** @internal */
  b: number,
}

/** @internal */
export function hello() {
  return 'world'
}

export const answer = 42
```
gets compiled as `.d.ts` to
```ts
export type Foo = {
  a: number
}
export const answer = 42
```

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-10 23:38:37 +02:00
Adam Rackis
3023706938
Update getting-started.md (#4909)
Add TanStack Start CLI option
2025-08-10 09:14:53 -07:00
Tanner Linsley
ef74fc661b release: v1.131.2 v1.131.2 2025-08-08 23:39:20 +00:00
Manuel Schiller
d063dd6707
fix: RELEASE_ALL (#4896) 2025-08-09 01:35:02 +02:00
Tanner Linsley
7bb4673046 release: v1.131.1 v1.131.1 2025-08-08 23:31:50 +00:00
Manuel Schiller
36f3253dc1
fix: publish package (#4895) 2025-08-09 01:30:26 +02:00
Lee
238c63f36d
docs(router): update links in how-to guides (#4878) 2025-08-09 00:46:51 +02:00
Tanner Linsley
c94fa35de1 release: v1.131.0 v1.131.0 2025-08-08 21:53:49 +00:00
Manuel Schiller
90adfe919e
feat: restructure query-integration (#4643)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-08 23:52:29 +02:00
Tanner Linsley
cc499c3b92 release: v1.130.17 v1.130.17 2025-08-08 21:37:57 +00:00
Tanner Linsley
e75531647a
fix: do not pre-decodeURI before passing to createMemoryHistory (#4893)
fixes #4514
2025-08-08 15:36:37 -06:00