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>
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 -->
Wait for this PR before merging:
https://github.com/TanStack/router/pull/4987. It adds unit tests that
should help make sure we're not breaking anything here.
---
The functions used to serialize and deserialize search params are called
*a lot*, but they are creating many unnecessary objects. This PR
refactors
- `encode` to be only as generic as what we need => in practice we only
need to handle 1 value per key (i.e. `.set()` and not `.append()`) so we
don't need a special case for arrays
- `decode` can avoid creating many arrays
- `stringifySearchWith` (and `defaultStringifySearch`) don't need to
pre-stringify the input into a `<string,string>` dictionary as `encode`
now accepts a stringifier function
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- Breaking Changes
- Removed encode and decode from React Router and Solid Router public
exports.
- Query string prefix support removed in encode/decode.
- Refactor
- Updated query string handling: arrays encode as comma-separated
values; duplicate keys decode into arrays.
- Streamlined error handling and avoided input mutation; consistent
leading “?” management.
- Tests
- Updated tests to match new encoding/decoding behavior and removed
prefix-related cases.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Based on the current usage of `pick`, directly addinf the picked keys to
the objects will be less overhead with the same result.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- Refactor
- Simplified internal routing logic related to navigation options; no
change to runtime behavior.
- Chores
- Removed an internal utility no longer used.
- Public API
- One non-essential utility export was removed from package entry
points, slightly reducing the public API surface.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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>
The pattern of copying an array just to `.reverse()` it and iterate it
from the end ends up creating a transient object (a copy of the array)
that needs to be garbage collected.
For example:
```ts
[...array].reverse().find(() => {/*...*/})
```
or
```ts
[...array].reverse().forEach(() => {/*...*/})
```
Instead we can use a regular `for` loop to iterate it from the end. This
will be mostly beneficial in `router-core > router > buildLocation` that
gets called pretty often.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Refactor**
- Improved head metadata processing in React and Solid routers to be
more efficient and readable, reducing work for large route metadata
sets.
- Simplified route matching logic to consistently pick the last relevant
match, improving clarity and maintainability.
- **Chores**
- Added a utility to locate the last list item meeting a condition,
supporting cleaner routing internals.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>