react-router icon indicating copy to clipboard operation
react-router copied to clipboard

Improve href() with a faster trim end splat

Open ngbrown opened this issue 2 months ago • 1 comments

This is a small optimization to href() to not use a backtracking regex on splat paths.

The speedup of the new trimEndSplat() method over the regex /\/*\*?$/ is about 17x to 36x speedup: jsbenchmark.com benchmark

The speedup of all of href() with options is about 1.2x to 1.5x speedup: jsbenchmark.com benchmark

This could also apply to compilePath(), but that only runs once per path at application load, not many times per page in the React render loop.

ngbrown avatar Sep 12 '25 18:09 ngbrown

🦋 Changeset detected

Latest commit: ba26a583d1d3771afad8a56aa856163bc51ae357

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
react-router Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Sep 12 '25 18:09 changeset-bot[bot]

@timdorr and @pcattori This improvement to href() has been approved for awhile. Can it be merged now?

ngbrown avatar Nov 21 '25 15:11 ngbrown