Loading workspace insights... Statistics interval
7 days30 daysLatest CI Pipeline Executions
05b77a8d fix(router-core): use encodeURIComponent for splat route params (#6520)
* fix(router-core): use encodeURIComponent for splat route params
Use encodeURIComponent instead of encodeURI for splat route parameters
to properly encode spaces, plus signs, and other special characters.
This fixes an SSR redirect loop that occurs when:
1. User navigates to a splat route with encoded characters (e.g., %20)
2. TanStack Router decodes params with decodeURIComponent
3. When rebuilding URL, encodeURI doesn't encode spaces/special chars
4. URL mismatch triggers redirect loop (307 redirects)
encodeURIComponent properly encodes these characters, preventing the
mismatch while still preserving forward slashes as path separators.
* update tests to use correct encoding for splat params
* use encodePathParam for splat/catch-all
* perf(router-core): add early return for URL-safe splat values
Add performance optimization that skips the split/map/join operation
when splat values only contain URL-safe characters (alphanumeric,
dash, period, underscore, tilde, exclamation, forward slash).
This avoids unnecessary processing in the hot path for common cases.
* fix(router-core): encode whitespace in encodeNonAscii
Update encodeNonAscii to also encode whitespace characters (spaces, tabs, etc.)
in addition to non-ASCII characters. This fixes SSR redirect loops where:
1. Request URL contains encoded spaces: /path/file%20name.pdf
2. parseLocation decodes pathname: /path/file name.pdf
3. buildLocation calls encodeNonAscii but spaces weren't encoded
4. URL mismatch triggers redirect loop
Now encodeNonAscii properly encodes:
- Whitespace characters (spaces become %20)
- Non-ASCII/unicode characters (including emojis)
Other ASCII special characters (parentheses, brackets, etc.) are preserved
as they are valid in URL paths.
* refactor(router-core): use regex in encodeNonAscii like original
* refactor(router-core): rename encodeNonAscii to encodePathLikeUrl
Rename the function to better reflect its expanded responsibility of
encoding paths the same way new URL() would, including:
- Whitespace characters (spaces → %20, tabs → %09)
- Non-ASCII/Unicode characters (emojis, accented characters)
The old name 'encodeNonAscii' was misleading since the function now
encodes more than just non-ASCII characters.
---------
Co-authored-by: Nico Lynzaad <nlynzaad@zylangroup.com>
Co-authored-by: Nico Lynzaad <44094871+nlynzaad@users.noreply.github.com>