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>
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>
The `start-bare` example includes Tailwind with a broken config (missing
`tailwindcss()` in vite.config.ts plugins), which contradicts the 'bare'
concept. Since `start-tailwind-v4` already provides a properly
configured Tailwind example, this PR removes Tailwind from `start-bare`
to make it actually bare.
When ordering routes to determine "which one will match in priority", we
try to follow the "more specific 1st" principle.
Currently, 2 routes with the same pattern, but with prefixes of
different lengths, are counted as having the same specificity, and thus
are not re-ordered. For example:
- `/f{$param}`
- `/foo{$param}`
In this case, assuming `f{$param}.tsx` is returned 1st by the OS when
listing route files (which it is by alphabetical order), a path
`/foobar` will match `/f{$param}`.
This PR proposes we take the `length` of the `prefix` and `suffix` into
account when sorting routes. In this example this would mean
`/foo{$param}` takes priority because it is considered more specific.