mirror of
https://github.com/TanStack/router.git
synced 2026-11-18 19:34:24 +00:00
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
|
|
|---|---|---|
| .. | ||
| lazy | ||
| blocker.test.tsx | ||
| ClientOnly.test.tsx | ||
| createLazyRoute.test.tsx | ||
| disableGlobalCatchBoundary.test.tsx | ||
| errorComponent.test.tsx | ||
| fileRoute.test-d.tsx | ||
| fileRoute.test.ts | ||
| link.bench.tsx | ||
| link.test-d.tsx | ||
| link.test.tsx | ||
| loaders.test.tsx | ||
| Matches.test-d.tsx | ||
| Matches.test.tsx | ||
| navigate.test.tsx | ||
| not-found.test.tsx | ||
| optional-path-params.test-d.tsx | ||
| optional-path-params.test.tsx | ||
| redirect.test.tsx | ||
| redirects.test-d.tsx | ||
| route.test-d.tsx | ||
| route.test.tsx | ||
| routeApi.test-d.tsx | ||
| routeContext.test.tsx | ||
| router.test-d.tsx | ||
| router.test.tsx | ||
| RouterProvider.test-d.tsx | ||
| Scripts.test.tsx | ||
| searchMiddleware.test.tsx | ||
| setupTests.tsx | ||
| store-updates-during-navigation.test.tsx | ||
| useBlocker.test-d.tsx | ||
| useBlocker.test.tsx | ||
| useCanGoBack.test.tsx | ||
| useLoaderData.test-d.tsx | ||
| useLocation.test-d.tsx | ||
| useMatch.test-d.tsx | ||
| useMatch.test.tsx | ||
| useNavigate.test-d.tsx | ||
| useNavigate.test.tsx | ||
| useParams.test-d.tsx | ||
| useRouteContext.test-d.tsx | ||
| useRouterState.test-d.tsx | ||
| useSearch.test-d.tsx | ||
| utils.ts | ||