0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-18 19:34:24 +00:00
router/packages/react-router/tests
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>
History 2025-08-11 13:59:36 +02:00
..
lazy test: Add test cases for route id consistency (#2401) 2024-10-15 21:35:04 +02:00
blocker.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
ClientOnly.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
createLazyRoute.test.tsx test(react-router): correct usage of act and waitFor (#1986) 2024-07-19 10:42:40 +12:00
disableGlobalCatchBoundary.test.tsx feat(react-router): add disableGlobalCatchBoundary option (#4765) 2025-07-26 22:45:20 +02:00
errorComponent.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
fileRoute.test-d.tsx refactor(router-core): begin migrating types from react-router and solid-router to router-core (#3538) 2025-02-23 23:18:16 +01:00
fileRoute.test.ts refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
link.bench.tsx feat(react-router): add remountDeps (#3269) 2025-01-29 01:03:33 +01:00
link.test-d.tsx fix(react-router): preserve ref type in createLink with required interface properties (#4674) 2025-07-18 22:25:22 +02:00
link.test.tsx test(react-router,solid-router): test re-render for preload='viewport' (#4672) 2025-07-17 19:15:11 +12:00
loaders.test.tsx feat: optional path params (#4597) 2025-07-16 13:41:58 -06:00
Matches.test-d.tsx fix: make to required if from is not set (#3099) 2025-01-04 18:48:57 +01:00
Matches.test.tsx chore: lint (#2369) 2024-09-19 00:28:18 +02:00
navigate.test.tsx feat: optional path params (#4597) 2025-07-16 13:41:58 -06:00
not-found.test.tsx fix: re-enable fuzzy matching to allow notFoundMode: fuzzy (#4721) 2025-07-20 07:20:28 +02:00
optional-path-params.test-d.tsx feat: optional path params (#4597) 2025-07-16 13:41:58 -06:00
optional-path-params.test.tsx chore: bump typescript version (#4853) 2025-08-01 22:30:02 +02:00
redirect.test.tsx refactor(history): use TSR_key namespace in state for hash (#4356) 2025-06-23 14:48:54 +12:00
redirects.test-d.tsx fix: make to required if from is not set (#3099) 2025-01-04 18:48:57 +01:00
route.test-d.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
route.test.tsx feat: Add style to HeadContent (#4559) 2025-07-02 00:28:12 +02:00
routeApi.test-d.tsx perf: improve ts perf for Route.Link (#4104) 2025-05-07 01:31:10 +02:00
routeContext.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
router.test-d.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
router.test.tsx chore: sync TanStack repo changes (#4784) 2025-07-26 21:55:38 +10:00
RouterProvider.test-d.tsx feat: trailingSlashes option on the type level (#1509) 2024-04-25 20:05:34 +02:00
Scripts.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
searchMiddleware.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
setupTests.tsx chore: silence error in test (#4794) 2025-07-26 23:05:17 +02:00
store-updates-during-navigation.test.tsx refactor(router-core): Reduce navigation work by making some properties non-reactive (#4916) 2025-08-11 13:59:36 +02:00
useBlocker.test-d.tsx feat(react-router): add useCanGoBack (#3017) 2025-01-03 21:09:58 +01:00
useBlocker.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
useCanGoBack.test.tsx feat(react-router): add useCanGoBack (#3017) 2025-01-03 21:09:58 +01:00
useLoaderData.test-d.tsx fix: only call head() when loaderData is available (#3410) 2025-02-13 13:06:13 -07:00
useLocation.test-d.tsx feat(react-router): add support for structural sharing for finegrained selectors (#2647) 2024-11-09 22:41:12 +01:00
useMatch.test-d.tsx refactor(router-core): migrate matches and route options to core (#3552) 2025-02-24 23:17:58 +01:00
useMatch.test.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
useNavigate.test-d.tsx fix: make to required if from is not set (#3099) 2025-01-04 18:48:57 +01:00
useNavigate.test.tsx fix: buildLocation check for non changing routes - consider trailing slashes (#4581) 2025-07-06 18:22:11 +02:00
useParams.test-d.tsx feat(react-router): add shouldThrow option to useParams and useSearch (#3368) 2025-02-08 22:36:40 +01:00
useRouteContext.test-d.tsx feat(react-router): add support for structural sharing for finegrained selectors (#2647) 2024-11-09 22:41:12 +01:00
useRouterState.test-d.tsx feat(react-router): add support for structural sharing for finegrained selectors (#2647) 2024-11-09 22:41:12 +01:00
useSearch.test-d.tsx fix: only call head() when loaderData is available (#3410) 2025-02-13 13:06:13 -07:00
utils.ts feat(react-router) add search middleware (#2521) 2024-10-14 20:34:35 +02:00