We can improve perf of this function *that gets called a lot* by not
grouping the entire string, and only removing the trailing slash.
The entire string is returned by `.replace()`, so we don't ned the group
```
> "/foo/bar/".replace(/\/$/, '')
'/foo/bar'
```
Doing so, we get ~6x performance out of it.
```
✓ @tanstack/router-core tests/other.bench.ts > comparePaths 2183ms
name hz min max mean p75 p99 p995 p999 rme samples
· oldComparePaths 1,300,774.12 0.0006 0.8563 0.0008 0.0008 0.0010 0.0010 0.0017 ±0.35% 650388
· newComparePaths 7,773,004.63 0.0000 0.2112 0.0001 0.0001 0.0002 0.0002 0.0004 ±0.14% 3886503 fastest
BENCH Summary
@tanstack/router-core newComparePaths - tests/other.bench.ts > comparePaths
5.98x faster than oldComparePaths
```
A lot of our e2e tests are querying external endpoints like
[typicode.com](https://jsonplaceholder.typicode.com) or
[example.com](https://example.com)
This is not ideal as it makes the e2e tests beholden to external factors
for example unavailability or rate limiting of these endpoints.
This PR addresses this by starting and stopping a local dummy server for
each test that needs to query external endpoints and mocks the results.
The setup and teardown have been implemented on each test package
individually so as to allow custom requirements where needed.
---------
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
Using integers instead of strings when possible is always better for
performance. It uses less memory, and enables faster comparisons.
This is also preparatory work for a build-time `parsePathname` as it
will result in a smaller output (though once gzipped it might not make a
difference in downloaded kB in the end).
`parsePathname` should return a `ReadonlyArray` instead of `Array`, and
`Segment` should be `readonly` too. This is because if we want to
improve perf by either caching at runtime or pre-computing routes at
build time, we need to ensure those objects can't be manipulated.
An unrelated change in this PR is also to move some inline functions to
module-scoped functions: `segmentToString` (from `resolvePath`) and
`isMatch` (from `matchByPath`). Those functions are in the hot path so
it's nice if the runtime compiler can promote them to optimized
functions.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
<!-- One very short sentence on the WHAT and WHY of the PR. E.g. "Remove
pathHash attribute because it is confirmed unused." or "Add DNS round
robin to improve load distribution." -->
Add a comprehensive how-to guide for deploying TanStack Router to
production and establish a multi-PR process for future documentation.
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Fixes#4673
I a bit simplified the `UseLinkReactProps` to make more use of typing
from React (and this simplification just fixes the bug)
Also added a test to check that the bug is no longer reproduced
Add new 'How-To' documentation section for React with a terse
installation guide to provide bite-sized, task-oriented instructions.
This new section aims to provide extremely concise, step-by-step
instructions for common tasks, making it easier for users and AI to
quickly find and follow specific procedures. Existing guides that
previously contained detailed installation steps now reference this new,
focused how-to guide to avoid content duplication and improve
discoverability.
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Add documentation for prefix-based internationalization (i18n) using
Optional Path Parameters.
This PR adds a comprehensive guide on implementing i18n patterns,
covering:
- Prefix-based i18n routing (e.g., `/{-$locale}/about`)
- Complex i18n patterns with multiple optional parameters
- Language navigation using function-style `params` for `Link`
components
- Advanced i18n with route groups
- SEO best practices (canonical URLs, hreflang)
- Type safety for locale validation
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This PR addresses some flaky tests in the redirect e2e tests for
react-start and solid start.
Specifically, when testing external redirects use useServerFn it was
trying to reach out to http://example.com. This updates it to redirect
to the local dummy server.
This is a follow on from #4653
This PR resolves flaky E2E tests caused by port collisions when running
tests in parallel.
Instead of deriving ports from package names (which can collide), this
new approach assigns a random, available port to each test server
instance.
Key Changes:
- Random Port Allocation: Each test server (Playwright, dummy servers)
gets a unique, random port at startup.
- File-based Sync: The server writes its assigned port to a port.txt
file in its test project directory, this is kept unique through using
the package name or another input string for the file name.
- Test Runner Sync: The test runner reads the port from that file to
build the correct URL.
- Automatic Cleanup: All port files are deleted at the start of each
test:e2e run to ensure fresh ports.
Local parallel runs (up to 10) have shown this to be stable and free of
collisions.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com>
Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
Co-authored-by: Indrek Ardel <indrek@ardel.eu>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>