You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(router-core,react-router,solid-router): avoid copying arrays just to .reverse() them (#4980)
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>
0 commit comments