0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/packages/solid-router/tests
Jason Xie 4814d4ef90
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>
History 2026-01-26 23:53:20 +02:00
..
lazy refactor(router-core): begin migrating types from react-router and solid-router to router-core (#3538) 2025-02-23 23:18:16 +01:00
server tests(solid-router): enable ClientOnly SSR test (#4666) 2025-07-16 19:58:35 +02:00
blocker.test.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
ClientOnly.test.tsx tests(solid-router): enable ClientOnly SSR test (#4666) 2025-07-16 19:58:35 +02:00
createLazyRoute.test.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
disableGlobalCatchBoundary.test.tsx feat(react-router): add disableGlobalCatchBoundary option (#4765) 2025-07-26 22:45:20 +02:00
errorComponent.test.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
fileRoute.test-d.tsx refactor(router-core): begin migrating types from react-router and solid-router to router-core (#3538) 2025-02-23 23:18:16 +01:00
fileRoute.test.ts feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
index.test.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
link.bench.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
link.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
link.test.tsx fix(router-core): use encodeURIComponent for splat route params (#6520) 2026-01-26 23:53:20 +02:00
loaders.test.tsx fix(router-core): handle AbortError in router execution flow (#4570) 2026-01-07 22:55:00 +01:00
Matches.test-d.tsx refactor(router-core): migrate matches and route options to core (#3552) 2025-02-24 23:17:58 +01:00
Matches.test.tsx refactor(router-core): Process routeTree into segment tree instead of flatRoutes [WIP] (#5722) 2025-11-15 13:45:02 +01:00
navigate.test.tsx fix(router-core): use encodeURIComponent for splat route params (#6520) 2026-01-26 23:53:20 +02:00
not-found.test.tsx fix: update error handling in MatchInner to access error data directly (#4746) 2025-11-19 19:46:29 +01:00
optional-path-params.test-d.tsx test(solid-router): sync unit tests from react-router (#5614) 2025-10-25 19:21:19 +02:00
optional-path-params.test.tsx refactor(router-core): interpolatePath skips optional segments w/ nullish param value (#5934) 2025-11-21 23:55:16 +01:00
redirect.test.tsx refactor(router-core): skip URL constructor in buildLocation (#6447) 2026-01-24 11:42:55 +01:00
redirects.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
route.test-d.tsx feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
route.test.tsx fix(solid-router): make useLoaderDeps return Accessor for reactivity (#5348) 2025-10-07 01:42:53 +02:00
routeApi.test-d.tsx fix(solid-router): make useLoaderDeps return Accessor for reactivity (#5348) 2025-10-07 01:42:53 +02:00
routeContext.test.tsx fix: commit route context (#6053) 2025-12-09 21:17:36 +01:00
router.test-d.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
router.test.tsx refactor(router-core): skip URL constructor in buildLocation (#6447) 2026-01-24 11:42:55 +01:00
RouterProvider.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
RouterProvider.test.tsx fix(solid-router): RouteProvider Wrap and Match InnerWrap support propagating context to their children (#5033) 2025-08-29 21:24:38 +02:00
Scripts.test.tsx fix(react-router, solid-router): make head function scripts load properly (#4323) 2025-06-18 22:03:06 +02:00
searchMiddleware.test.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
setupTests.tsx chore: silence error in test (#4794) 2025-07-26 23:05:17 +02:00
store-updates-during-navigation.test.tsx fix: Commit context together with status to avoid race condition (#6407) 2026-01-18 01:01:03 +01:00
Transitioner.test.tsx refactor(router-core): flatten loadMatches (#4961) 2025-08-15 23:19:56 +02:00
useBlocker.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useBlocker.test.tsx fix(router-core): useBlocker navigation issues for 404 pages and external URLs (#4917) 2025-11-23 01:29:13 +01:00
useCanGoBack.test.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useLoaderData.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useLocation.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useMatch.test-d.tsx refactor(router-core): migrate matches and route options to core (#3552) 2025-02-24 23:17:58 +01:00
useMatch.test.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useNavigate.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useNavigate.test.tsx fix(router-core): use encodeURIComponent for splat route params (#6520) 2026-01-26 23:53:20 +02:00
useParams.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useParams.test.tsx refactor(router-core): skip full matchRoutesInternal for Link's buildLocation, use simple getMatchedRoutes (#6445) 2026-01-22 23:24:56 +01:00
useRouteContext.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useRouterState.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useSearch.test-d.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
utils.ts feat: Start RC (#5189) 2025-09-23 11:34:54 -06:00