fix(router-core): add support for handling any kind of empty _splat consistently #5510
main fromrefs/pull/5510/head·merged by nlynzaad(GitHub profile, opens in a new tab) When expanding a splat, undefined should be handled exactly like if the _splat param didn't exist at all. This allows consistent handling of _splat routes to ensure that trailing slashes are kept or dropped according to the spec.
Fixes #5385
Summary by CodeRabbit#
Bug Fixes
- Consistent handling of empty, undefined, or omitted "splat" segments so routes, links, and navigation resolve predictably across trailing-slash settings.
New Features
- Trailing-slash behavior is now exposed and configurable, making URL trailing-slash handling explicit.
Tests
- Added end-to-end tests covering splat-route link generation and navigation for empty, undefined, and missing splat values across trailing-slash modes.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
paul-sachs(GitHub profile, opens in a new tab) changed the title
for which scenarios is this relevant? navigating an setting
_splatto e.g.undefined? we should add tests for those scenarios as wellthanks for the unit tests on path and Link, as Manuel mentioned please add tests for navigate as well, both useNavigate and navigate, just to ensure consistency.
Apart from that it's a go from me.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/react-router/tests/navigate.test.tsx (3)
1250-1250: KeepcreateRootRouteusage consistent.Elsewhere in this file you call
createRootRoute({}). Mirror that here to avoid accidental reliance on defaulted options.Apply:
- const rootRoute = createRootRoute() + const rootRoute = createRootRoute({})
1270-1287: Add a case that clears an existing non-empty splat.Also verify that navigating from "/splat/foo" (or deeper) to an empty/omitted
_splatlands on "/splat" (or "/splat/") pertrailingSlash. This guards interpolation when removing segments, not just building from root.Append inside this
describe('splat routes with empty splat', ...):+ it.each([{ trailingSlash: true }, { trailingSlash: false }])( + 'clears a non-empty _splat with trailingSlash: $trailingSlash', + async ({ trailingSlash }) => { + const tail = trailingSlash ? '/' : '' + const history = createMemoryHistory({ initialEntries: ['/splat/foo/bar'] }) + const rootRoute = createRootRoute({}) + const indexRoute = createRoute({ getParentRoute: () => rootRoute, path: '/' }) + const splatRoute = createRoute({ getParentRoute: () => rootRoute, path: 'splat/$' }) + const router = createRouter({ + routeTree: rootRoute.addChildren([indexRoute, splatRoute]), + history, + trailingSlash: trailingSlash ? 'always' : 'never', + }) + await router.load() + // Clear via '', undefined, and omission + for (const params of [{ _splat: '' }, { _splat: undefined }, {}]) { + await router.navigate({ to: '/splat/$', params }) + await router.invalidate() + expect(router.state.location.pathname).toBe(`/splat${tail}`) + } + }, + )
1242-1290: Add auseNavigateparity test.Reviewers asked for both programmatic
navigateand hook-based navigation. Please add a React-level test that callsuseNavigate()with{ to: '/splat/$', params: { _splat: undefined } }and asserts the same pathname outcomes for 'always'/'never'. I can help wire a minimal render harness if you don’t have one handy.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c35c88c48fa0e3b28c137433106cf6b3758bd3a2 and 3e11ca166e38e3dde806481fd4e79000f909c6b0.
📒 Files selected for processing (1)
packages/react-router/tests/navigate.test.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/react-router/tests/navigate.test.tsx
packages/{react-router,solid-router}/**
📄 CodeRabbit inference engine (AGENTS.md)
Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/
Files:
packages/react-router/tests/navigate.test.tsx
🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad PR: TanStack/router#5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/react-router/tests/navigate.test.tsx
🧬 Code graph analysis (1)
packages/react-router/tests/navigate.test.tsx (2)
packages/history/src/index.ts (1)
createMemoryHistory(568-614)
packages/react-router/src/router.ts (1)
createRouter(80-82)
🔇 Additional comments (1)
packages/react-router/tests/navigate.test.tsx (1)
1242-1290: Good coverage for empty/undefined/omitted _splat across trailingSlash policies.Scenario matrix and back-to-index reset make the assertions robust. This directly guards against "/undefined" regressions and enforces 'always' vs 'never'.
@@ -1240,0 +1245,21 @@1245+ async ({ trailingSlash }) => {1246+ const tail = trailingSlash ? '/' : ''1247+1248+ const history = createMemoryHistory({ initialEntries: ['/'] })1249+1250+ const rootRoute = createRootRoute()1251+ const indexRoute = createRoute({1252+ getParentRoute: () => rootRoute,1253+ path: '/',1254+ })1255+1256+ const splatRoute = createRoute({1257+ getParentRoute: () => rootRoute,1258+ path: 'splat/$',1259+ })1260+1261+ const router = createRouter({1262+ routeTree: rootRoute.addChildren([indexRoute, splatRoute]),1263+ history,1264+ trailingSlash: trailingSlash ? 'always' : 'never',1265+ })⚠️ Potential issue | 🔴 Critical
🧩 Analysis chain
Consider covering all supported
trailingSlashmodes.If the router also supports values besides 'always' | 'never' (e.g., 'ignore'/'preserve'), add them to the matrix to lock behavior.
Run to confirm allowed options and update tests accordingly:
🏁 Script executed:
#!/bin/bash # Discover trailingSlash option type/union in repo rg -nP --type=ts -C2 'trailingSlash\??:\s*["\']|type\s+TrailingSlash|export\s+type\s+.*trailingSlash'Length of output: 68
I'll fix the shell syntax error and search for the trailingSlash type definition with corrected escaping.
--- 🏁 Script executed: ```shell #!/bin/bash # Search for TrailingSlash type definition rg -nP --type=ts "type\s+TrailingSlash" -A 3Length of output: 686
🏁 Script executed:
#!/bin/bash # Search for trailingSlash property in config/types rg -nP --type=ts "trailingSlash.*:" -B 2 -A 2 | head -50Length of output: 4048
🏁 Script executed:
#!/bin/bash # Look for router config interface/type rg -nP --type=ts "(interface|type)\s+\w*(Config|Options|Router)" -A 5 | grep -A 5 -B 1 "trailingSlash"Length of output: 2370
Now let me verify the exact test context in the React Router file to understand the test structure:
--- 🏁 Script executed: ```shell #!/bin/bash # Check context around lines 1264-1265 in the react-router navigate test sed -n '1250,1280p' packages/react-router/tests/navigate.test.tsxLength of output: 778
Let me verify the test.each() structure:
--- 🏁 Script executed: ```shell #!/bin/bash # Find the test.each line before line 1264 sed -n '1235,1265p' packages/react-router/tests/navigate.test.tsx | grep -B 20 "trailingSlash:"Length of output: 904
Add 'preserve' mode to test matrix for complete
trailingSlashcoverage.The router supports three
trailingSlashmodes:'always' | 'never' | 'preserve'(defined in packages/router-core/src/router.ts:800). The current test at line 1243 usesit.each([{ trailingSlash: true }, { trailingSlash: false }]), which covers only'always'and'never'via the ternary at line 1264. Update the test matrix to include'preserve'mode to fully exercise all supported behaviors.🤖 Prompt for AI Agents
In packages/react-router/tests/navigate.test.tsx around lines 1264 to 1265, the test matrix only supplies booleans and maps them via a ternary to 'always' or 'never', missing the 'preserve' mode; update the it.each matrix to include a third case for 'preserve' (e.g. it.each([{ trailingSlash: true }, { trailingSlash: false }, { trailingSlash: 'preserve' }]) ) and change the code that builds the router option so it uses the value directly when it's a string (or simply set trailingSlash: trailingSlash as the test input) instead of only using the ternary, ensuring the test runs for 'always', 'never', and 'preserve'.✅ Addressed in commit 3ec9c9d
@schiller-manuel Added additional test coverage. I followed the suggestions of CodeRabbit as well, to better cover
trailingSlashpotential options even though I knowpreservedoesn't really make that much of a difference but it was easy enough to modify so might as well test it.Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/react-router/tests/navigate.test.tsx (1)
1242-1290: Great coverage for empty/undefined/omitted_splatacross all trailingSlash modes.Behavior matches the spec and prevents
/undefinedregressions. Optional: factor the matrix into a typed constant to drop the casts and reuse across files:const trailingSlashCases = (['preserve','always','never'] as const).map((t) => ({ trailingSlash: t }))packages/react-router/tests/useNavigate.test.tsx (1)
2559-2680: Solid navigate-path coverage for empty_splatvia useNavigate.Asserts match expectations for 'preserve'/'always'/'never' and properly reset between runs. Consider extracting a shared typed matrix to remove repeated casts, mirroring the navigate and link tests.
packages/react-router/tests/link.test.tsx (1)
5552-5643: Href + active-state assertions for splat links are on point.This closes the loop on Link behavior for empty/undefined/omitted
_splat. If you want to DRY the three files, consider a small helper to supply the trailingSlash cases and expected tail.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 7cc7d00ad43a0047e8dba5e18f7e8f4947f52ab2 and 3ec9c9d882f1ccc4f5547d0d37b693ba9044f15e.
📒 Files selected for processing (3)
packages/react-router/tests/link.test.tsx(2 hunks)packages/react-router/tests/navigate.test.tsx(2 hunks)packages/react-router/tests/useNavigate.test.tsx(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/react-router/tests/useNavigate.test.tsxpackages/react-router/tests/navigate.test.tsxpackages/react-router/tests/link.test.tsx
packages/{react-router,solid-router}/**
📄 CodeRabbit inference engine (AGENTS.md)
Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/
Files:
packages/react-router/tests/useNavigate.test.tsxpackages/react-router/tests/navigate.test.tsxpackages/react-router/tests/link.test.tsx
🧠 Learnings (2)
📚 Learning: 2025-09-28T21:41:45.233Z
Learnt from: nlynzaad PR: TanStack/router#5284 File: e2e/react-start/basic/server.js:50-0 Timestamp: 2025-09-28T21:41:45.233Z Learning: In Express v5, catch-all routes must use named wildcards. Use `/*splat` to match everything except root path, or `/{*splat}` (with braces) to match including root path. The old `*` syntax is not allowed and will cause "Missing parameter name" errors. This breaking change requires explicit naming of wildcard parameters.Applied to files:
packages/react-router/tests/useNavigate.test.tsxpackages/react-router/tests/navigate.test.tsx
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad PR: TanStack/router#5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/react-router/tests/navigate.test.tsxpackages/react-router/tests/link.test.tsx
🧬 Code graph analysis (3)
packages/react-router/tests/useNavigate.test.tsx (1)
packages/router-core/src/router.ts (1)
TrailingSlashOption(800-800)
packages/react-router/tests/navigate.test.tsx (3)
packages/router-core/src/router.ts (1)
TrailingSlashOption(800-800)
packages/react-router/src/index.tsx (5)
TrailingSlashOption(80-80)createMemoryHistory(118-118)createRootRoute(258-258)createRoute(255-255)createRouter(273-273)
packages/history/src/index.ts (1)
createMemoryHistory(568-614)
packages/react-router/tests/link.test.tsx (2)
packages/router-core/src/router.ts (1)
TrailingSlashOption(800-800)
packages/react-router/src/router.ts (1)
createRouter(80-82)
🔇 Additional comments (3)
packages/react-router/tests/navigate.test.tsx (1)
9-9: Type import looks good.Importing TrailingSlashOption from the public surface is correct and keeps tests strongly typed.
packages/react-router/tests/useNavigate.test.tsx (1)
26-26: Type import is appropriate.Using TrailingSlashOption here keeps the parameterized tests precise.
packages/react-router/tests/link.test.tsx (1)
44-44: Type import is fine.Keeps tests aligned with the public API surface.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/react-router/tests/link.test.tsx (1)
5553-5644: LGTM: Thorough Link component test for empty splat handling.This test validates that the Link component generates consistent hrefs for empty,
undefined, and omitted_splatparameters across alltrailingSlashconfigurations. The activation check (lines 5637-5639) confirms the router correctly recognizes all three link variants as pointing to the same route.Potential duplication concern: The AI summary indicates this test suite may be duplicated in the file. If so, please remove the duplicate to avoid redundant test execution and maintenance overhead.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 3ec9c9d882f1ccc4f5547d0d37b693ba9044f15e and 1b5b17cc102084a44712e81f7ea09f4dfea91327.
📒 Files selected for processing (4)
packages/react-router/tests/link.test.tsx(2 hunks)packages/react-router/tests/navigate.test.tsx(2 hunks)packages/react-router/tests/useNavigate.test.tsx(3 hunks)packages/react-router/tests/utils.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/react-router/tests/useNavigate.test.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/react-router/tests/utils.tspackages/react-router/tests/navigate.test.tsxpackages/react-router/tests/link.test.tsx
packages/{react-router,solid-router}/**
📄 CodeRabbit inference engine (AGENTS.md)
Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/
Files:
packages/react-router/tests/utils.tspackages/react-router/tests/navigate.test.tsxpackages/react-router/tests/link.test.tsx
🧠 Learnings (1)
📓 Common learnings
Learnt from: nlynzaad PR: TanStack/router#5284 File: e2e/react-start/basic/server.js:50-0 Timestamp: 2025-09-28T21:41:45.233Z Learning: In Express v5, catch-all routes must use named wildcards. Use `/*splat` to match everything except root path, or `/{*splat}` (with braces) to match including root path. The old `*` syntax is not allowed and will cause "Missing parameter name" errors. This breaking change requires explicit naming of wildcard parameters.🧬 Code graph analysis (2)
packages/react-router/tests/navigate.test.tsx (2)
packages/react-router/tests/utils.ts (1)
trailingSlashCases(58-58)
packages/history/src/index.ts (1)
createMemoryHistory(568-614)
packages/react-router/tests/link.test.tsx (1)
packages/react-router/tests/utils.ts (1)
trailingSlashCases(58-58)
🔇 Additional comments (2)
packages/react-router/tests/utils.ts (1)
57-58: LGTM: Clean test utility for trailing slash parameterization.This provides a single source of truth for testing all three trailing slash modes across the test suites. The const assertion ensures proper type inference.
packages/react-router/tests/navigate.test.tsx (1)
1243-1291: LGTM: Comprehensive test coverage for empty splat navigation.This test validates that empty string,
undefined, and omitted_splatparameters all produce consistent navigation behavior across alltrailingSlashconfigurations. The iteration through param sets with cleanup (navigating back to index) ensures test isolation.Note on
preservemode (line 1247): The test treats'preserve'the same as'never'(no trailing slash). This is likely correct for programmatic navigation where there's no "user-typed" URL to preserve, but worth confirming this aligns with the router's intended behavior for thepreservemode.github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router
@paul-sachs thanks a lot for this.
I made some minor updates:
- exported the constant from router-core so it can be reused more globally
- replicated the tests for solid js
nlynzaad(GitHub profile, opens in a new tab) approved these changes
View your CI Pipeline Execution ↗ for commit d55f44ccf281654253a7198ce06ed227dcd7b8cf
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 1m 44s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 35s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-20 23:12:49UTCActionable comments posted: 1
🧹 Nitpick comments (3)
packages/solid-router/tests/useNavigate.test.tsx (1)
2528-2647: Stabilize event timing; add defensive assertion- Don’t wrap fireEvent.click/history.push inside waitFor. Click/push first, then waitFor on resulting state to reduce flakes.
- Also assert pathname never contains "undefined" to lock the regression.
Apply this representative diff to the three interactions:
- await waitFor(() => { - fireEvent.click(splatBtnWithEmptySplat) - }) + fireEvent.click(splatBtnWithEmptySplat) + await waitFor(() => expect(window.location.pathname).toBe(`/splat${tail}`)) + expect(window.location.pathname).not.toContain('undefined') - await waitFor(() => { - history.push('/') - }) + history.push('/') + await waitFor(() => expect(window.location.pathname).toBe('/'))packages/solid-router/tests/navigate.test.tsx (1)
572-624: Harden expectations for the splat permutationsCurrent checks are solid. Consider adding:
- A negative assertion against “undefined” in the path.
- Optional: type paramSets to make intent explicit.
Example tweak:
- const paramSets = [ + const paramSets: Array<Partial<{ _splat: string }>> = [ { _splat: '' }, { _splat: undefined }, {}, ] ... expect(router.state.location.pathname).toBe(`/splat${tail}`) +expect(router.state.location.pathname).not.toContain('undefined')packages/react-router/tests/link.test.tsx (1)
5553-5641: Strengthen assertions; minor readability- Add a negative assertion to ensure no “undefined” leaks into href/path.
- Optional: factor expectedHref =
/splat${tail}to avoid repetition.
Example additions:
expect(splatLinkWithEmptySplat.getAttribute('href')).toBe(`/splat${tail}`) +expect(splatLinkWithEmptySplat.getAttribute('href')).not.toMatch(/undefined/) ... expect(window.location.pathname).toBe(`/splat${tail}`) +expect(window.location.pathname).not.toMatch(/undefined/)📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 1b5b17cc102084a44712e81f7ea09f4dfea91327 and 92a1269e1d496f729c77c576729951136f7f02d2.
📒 Files selected for processing (8)
packages/react-router/tests/link.test.tsx(2 hunks)packages/react-router/tests/navigate.test.tsx(2 hunks)packages/react-router/tests/useNavigate.test.tsx(2 hunks)packages/router-core/src/index.ts(1 hunks)packages/router-core/src/router.ts(1 hunks)packages/solid-router/tests/link.test.tsx(2 hunks)packages/solid-router/tests/navigate.test.tsx(2 hunks)packages/solid-router/tests/useNavigate.test.tsx(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-core/src/index.tspackages/solid-router/tests/useNavigate.test.tsxpackages/react-router/tests/navigate.test.tsxpackages/router-core/src/router.tspackages/solid-router/tests/navigate.test.tsxpackages/react-router/tests/useNavigate.test.tsxpackages/solid-router/tests/link.test.tsxpackages/react-router/tests/link.test.tsx
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/src/index.tspackages/router-core/src/router.ts
packages/{react-router,solid-router}/**
📄 CodeRabbit inference engine (AGENTS.md)
Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/
Files:
packages/solid-router/tests/useNavigate.test.tsxpackages/react-router/tests/navigate.test.tsxpackages/solid-router/tests/navigate.test.tsxpackages/react-router/tests/useNavigate.test.tsxpackages/solid-router/tests/link.test.tsxpackages/react-router/tests/link.test.tsx
🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad PR: TanStack/router#5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/solid-router/tests/useNavigate.test.tsxpackages/react-router/tests/navigate.test.tsxpackages/solid-router/tests/navigate.test.tsxpackages/solid-router/tests/link.test.tsx
🧬 Code graph analysis (7)
packages/solid-router/tests/useNavigate.test.tsx (2)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/solid-router/src/useNavigate.tsx (1)
useNavigate(11-25)
packages/react-router/tests/navigate.test.tsx (3)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/history/src/index.ts (1)
createMemoryHistory(568-614)
packages/react-router/src/router.ts (1)
createRouter(91-93)
packages/router-core/src/router.ts (3)
packages/router-core/src/index.ts (2)
trailingSlashOptions(207-207)TrailingSlashOption(212-212)
packages/react-router/src/index.tsx (1)
TrailingSlashOption(80-80)
packages/solid-router/src/index.tsx (1)
TrailingSlashOption(79-79)
packages/solid-router/tests/navigate.test.tsx (1)
packages/solid-router/src/router.ts (1)
createRouter(76-78)
packages/react-router/tests/useNavigate.test.tsx (1)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/solid-router/tests/link.test.tsx (1)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/react-router/tests/link.test.tsx (2)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/react-router/src/router.ts (1)
createRouter(91-93)
🔇 Additional comments (9)
packages/router-core/src/index.ts (1)
199-209: Expose trailingSlashOptions in public API — good additionMatches router.ts const and unblocks cross-package tests/imports. No issues.
packages/solid-router/tests/useNavigate.test.tsx (1)
13-13: Import source for trailingSlashOptions — OKPublic export is available; import looks correct.
packages/solid-router/tests/navigate.test.tsx (1)
3-3: Import of trailingSlashOptions — OKConsistent with router-core export.
packages/react-router/tests/link.test.tsx (1)
15-15: Import of trailingSlashOptions — OKMatches new public export.
packages/react-router/tests/navigate.test.tsx (1)
1243-1294: Great coverage for splat edge casesExercising empty/undefined/missing
_splatacross everytrailingSlashmode (viaObject.values(trailingSlashOptions)) is a nice way to lock the regression fix and guard future modes automatically.packages/solid-router/tests/link.test.tsx (1)
5089-5177: Solid link parity looks solidThanks for mirroring the React coverage here—asserting both the generated hrefs and active-state behaviour across the three
_splatpermutations gives us end-to-end confidence that the Solid bindings respect the core fix.packages/router-core/src/router.ts (1)
800-808: Nice single source for trailingSlash valuesDeriving
TrailingSlashOptionfrom thetrailingSlashOptionsconst keeps the runtime export and type union in lockstep, which makes the downstreamObject.values(...)usage in tests both ergonomic and type-safe.packages/react-router/tests/useNavigate.test.tsx (2)
13-14: LGTM!The import of
trailingSlashOptionsis correct and enables parameterized testing across all trailing slash configurations.
2565-2679: LGTM!The test implementation comprehensively covers the empty splat scenarios. The logic correctly handles all three edge cases (empty string, undefined, and missing
_splat), verifies the pathname respects thetrailingSlashoption, and properly resets state between test cases for isolation.Resolvedby nlynzaad(GitHub profile, opens in a new tab)@@ -2555,3 +2557,8 @@25552557 })25562558 },25572559 )2560+2561+describe('splat routes with empty splat', () => {2562+ test.each(Object.values(trailingSlashOptions))(2563+ 'should handle empty _splat parameter with trailingSlash: $trailingSlash',2564+ async (trailingSlash) => {⚠️ Potential issue | 🟡 Minor
Fix test name interpolation.
The test name uses
$trailingSlash, buttest.eachis called with an array of primitives. Use%sfor string interpolation instead.Apply this diff:
- 'should handle empty _splat parameter with trailingSlash: $trailingSlash', + 'should handle empty _splat parameter with trailingSlash: %s',📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
test.each(Object.values(trailingSlashOptions))( 'should handle empty _splat parameter with trailingSlash: %s', async (trailingSlash) => {🤖 Prompt for AI Agents
In packages/react-router/tests/useNavigate.test.tsx around lines 2562 to 2564, the test title uses `$trailingSlash` which only works for object interpolation but the table is an array of primitives; change the placeholder to `%s` so test.each properly interpolates the primitive value into the test name (i.e., replace `$trailingSlash` with `%s` in the test description).More templates
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5510@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5510@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5510@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5510@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5510@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5510@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5510@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5510@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5510@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5510@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5510@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5510@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5510@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5510@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5510@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5510@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5510@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5510@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5510@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5510@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5510@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5510@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5510@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5510@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5510@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5510@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5510@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5510@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5510@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5510@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5510@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5510@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5510@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5510@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5510commit:
d55f44cActionable comments posted: 1
🧹 Nitpick comments (2)
packages/solid-router/tests/useNavigate.test.tsx (1)
2528-2643: Good end‑to‑end coverage; consider simplifying waitFor usage.Current pattern awaits
findByTextinside an asyncwaitForcallback. Prefer either:- waitFor pathname, then a standalone
findByText, or - use synchronous
getByTextinsidewaitFor.
Example:
await waitFor(() => expect(window.location.pathname).toBe(`/splat${tail}`)) expect(await screen.findByText('Splat Route')).toBeInTheDocument()packages/solid-router/tests/link.test.tsx (1)
5089-5181: Thorough Link-level validation for empty/undefined/missing_splat.Href generation and active state checks look correct across all trailingSlash modes; route render assertion completes the flow.
Minor: the inline comment “When _splat has a value...” could say “When navigating with empty/undefined/missing _splat...” for precision.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 25fa6865f137861b0b70b2de8b261c686b26ec47 and b26e9b7da7a52a3f38556f45c262b6db19dcbc80.
📒 Files selected for processing (3)
packages/solid-router/tests/link.test.tsx(2 hunks)packages/solid-router/tests/navigate.test.tsx(2 hunks)packages/solid-router/tests/useNavigate.test.tsx(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/solid-router/tests/link.test.tsxpackages/solid-router/tests/useNavigate.test.tsxpackages/solid-router/tests/navigate.test.tsx
packages/{react-router,solid-router}/**
📄 CodeRabbit inference engine (AGENTS.md)
Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/
Files:
packages/solid-router/tests/link.test.tsxpackages/solid-router/tests/useNavigate.test.tsxpackages/solid-router/tests/navigate.test.tsx
🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad PR: TanStack/router#5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/solid-router/tests/link.test.tsxpackages/solid-router/tests/useNavigate.test.tsxpackages/solid-router/tests/navigate.test.tsx
🧬 Code graph analysis (3)
packages/solid-router/tests/link.test.tsx (1)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/solid-router/tests/useNavigate.test.tsx (2)
packages/router-core/src/router.ts (1)
trailingSlashOptions(800-804)
packages/solid-router/src/useNavigate.tsx (1)
useNavigate(11-25)
packages/solid-router/tests/navigate.test.tsx (1)
packages/solid-router/src/router.ts (1)
createRouter(76-78)
🪛 ESLint
packages/solid-router/tests/navigate.test.tsx
[error] 11-11:
@solidjs/testing-libraryimport should occur before import of../src(import/order)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (3)
packages/solid-router/tests/navigate.test.tsx (1)
573-628: Solid coverage for empty/undefined/missing_splatacross trailingSlash modes.Exercises navigate() + history reset and asserts path normalization. Matches the intended behavior.
packages/solid-router/tests/useNavigate.test.tsx (1)
13-13: LGTM import.Public
trailingSlashOptionsusage is appropriate here.packages/solid-router/tests/link.test.tsx (1)
13-13: LGTM import.Using the exported
trailingSlashOptionskeeps tests in sync with core.@@ -1,9 +1,11 @@11 import { afterEach, describe, expect, it, vi } from 'vitest'223+import { trailingSlashOptions } from '@tanstack/router-core'34 import {45 createMemoryHistory,56 createRootRoute,67 createRoute,78 createRouter,89 } from '../src'910 import type { RouterHistory } from '../src'11+import { waitFor } from '@solidjs/testing-library'⚠️ Potential issue | 🟡 Minor
Fix import order (import/order).
Place external imports before local (“../src”). Move
@solidjs/testing-libraryabove the internal imports.Apply this diff:
import { trailingSlashOptions } from '@tanstack/router-core' +import { waitFor } from '@solidjs/testing-library' import { createMemoryHistory, createRootRoute, createRoute, createRouter, } from '../src' import type { RouterHistory } from '../src' -import { waitFor } from '@solidjs/testing-library'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { trailingSlashOptions } from '@tanstack/router-core' import { waitFor } from '@solidjs/testing-library' import { createMemoryHistory, createRootRoute, createRoute, createRouter, } from '../src' import type { RouterHistory } from '../src'🧰 Tools
🪛 ESLint
[error] 11-11:
@solidjs/testing-libraryimport should occur before import of../src(import/order)
🤖 Prompt for AI Agents
In packages/solid-router/tests/navigate.test.tsx around lines 3 to 11, the import order is incorrect: external imports should precede local imports. Move the import of '@solidjs/testing-library' (waitFor) so it appears above any '../src' imports and ensure all third-party package imports (e.g., '@tanstack/router-core', '@solidjs/testing-library') are grouped before internal relative imports; adjust spacing to match project linting rules.✅ Addressed in commit d55f44c
- waitFor pathname, then a standalone
nlynzaad(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Warning
Rate limit exceeded#
@nlynzaad has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 7 seconds before requesting another review.
⌛ How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
🚦 How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.
📥 Commits
Reviewing files that changed from the base of the PR and between b26e9b7da7a52a3f38556f45c262b6db19dcbc80 and d55f44ccf281654253a7198ce06ed227dcd7b8cf.
📒 Files selected for processing (1)
packages/solid-router/tests/navigate.test.tsx(2 hunks)Walkthrough#
Treats empty or falsy
_splatas missing during path interpolation, adds atrailingSlashOptionsconst and derivedTrailingSlashOptiontype (exported), re-exports it, and adds parameterized tests across router-core, react-router, and solid-router validating behavior for empty/undefined/missing splat with trailingSlash options.Changes#
packages/router-core/src/path.ts,packages/router-core/src/router.ts,packages/router-core/src/index.ts_splatvalues as missing (changes wildcard insertion logic); addedtrailingSlashOptionsconst and derivedTrailingSlashOptiontype; re-exportedtrailingSlashOptionsfrom package index.packages/router-core/tests/path.test.ts_splatis""orundefined.packages/react-router/tests/link.test.tsx,packages/react-router/tests/navigate.test.tsx,packages/react-router/tests/useNavigate.test.tsxtrailingSlashOptionsthat check href/pathname generation, navigation, and active-route behavior for_splatvalues"",undefined, and omitted across trailing-slash options. (Duplicate suites appear in diff.)packages/solid-router/tests/link.test.tsx,packages/solid-router/tests/navigate.test.tsx,packages/solid-router/tests/useNavigate.test.tsxtrailingSlashOptionsvalidating href/pathname generation and navigation for_splatvalues"",undefined, and omitted across trailing-slash options. (Duplicate suites appear in diff.)Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs#
_splatinterpolation logic changed here.Suggested reviewers#
Poem#
Pre-merge checks and finishing touches#
✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share