Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(router-core): validate params while matching#5936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d9e403b77aade62fd3009102ef3cc9f0f62b9c416a9b083175e0ea27fca20cec577ce90353059c67704ec221f3e1a3df20152a6bf725b7647f821bfc96fdc78b787306b9d31bc35ac00cac7a3beed4b0b40b9428086f19650227f61a51a43d826289File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1188,9 +1188,46 @@ export interface UpdatableRouteOptions< | ||
| in out TBeforeLoadFn, | ||
| > extends UpdatableStaticRouteOption, | ||
| UpdatableRouteOptionsExtensions { | ||
| // If true, this route will be matched as case-sensitive | ||
| /** | ||
| * Options to control route matching behavior with runtime code. | ||
| * | ||
| * @experimental 🚧 this feature is subject to change | ||
| * | ||
| * @link https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType | ||
| */ | ||
| skipRouteOnParseError?: { | ||
| /** | ||
| * If `true`, skip this route during matching if `params.parse` fails. | ||
| * | ||
| * Without this option, a `/$param` route could match *any* value for `param`, | ||
| * and only later during the route lifecycle would `params.parse` run and potentially | ||
| * show the `errorComponent` if validation failed. | ||
| * | ||
| * With this option enabled, the route will only match if `params.parse` succeeds. | ||
| * If it fails, the router will continue trying to match other routes, potentially | ||
| * finding a different route that works, or ultimately showing the `notFoundComponent`. | ||
| * | ||
| * @default false | ||
| */ | ||
| params?: boolean | ||
| /** | ||
| * In cases where multiple routes would need to run `params.parse` during matching | ||
| * to determine which route to pick, this priority number can be used as a tie-breaker | ||
| * for which route to try first. Higher number = higher priority. | ||
| * | ||
| * @default 0 | ||
| */ | ||
| priority?: number | ||
| } | ||
Comment on lines
+1191
to
+1221
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, check the RouteLike interface definition and its options field
rg -n "interface RouteLike" --type=ts packages/router-core/src/
# Then view the specific lines in route.ts to see the RouteLike definition
sed -n '2003,2014p' packages/router-core/src/route.tsRepository: TanStack/router Length of output: 342 🏁 Script executed: # Search for skipRouteOnParseError usage throughout the codebase
rg -n "skipRouteOnParseError" --type=ts packages/router-core/src/
# Check where RouteLike is used in matching logic
rg -n "RouteLike" --type=ts -A3 packages/router-core/src/ | head -100Repository: TanStack/router Length of output: 7940 🏁 Script executed: # Look for test files related to skipRouteOnParseError
find packages -name "*.test.ts" -o -name "*.spec.ts"| xargs rg -l "skipRouteOnParseError"2>/dev/null ||echo"No test files found with skipRouteOnParseError"# Check for any @experimental tags in the route.ts file
grep -n "@experimental\|@alpha\|experimental" packages/router-core/src/route.ts | head -20Repository: TanStack/router Length of output: 216 🏁 Script executed: # Check the route.ts file to see if there are other interfaces besides RouteLike# and understand the complete type hierarchy
grep -n "interface.*Route\|type.*Route" packages/router-core/src/route.ts | head -30
# Look at the UpdatableRouteOptions interface mentioned in the review
rg -n "UpdatableRouteOptions" --type=ts packages/router-core/src/route.ts -A20Repository: TanStack/router Length of output: 4834 🏁 Script executed: # Check the test file to verify if tests exist
head -50 packages/router-core/tests/skip-route-on-parse-error.test.ts
# Check how parseSegments is called and what route object is passed
rg -n "parseSegments" --type=ts packages/router-core/src/ -B2 -A2Repository: TanStack/router Length of output: 3893 🏁 Script executed: # Check if there's a type declaration or wider options interface used elsewhere
rg -n "route\.options\?" --type=ts packages/router-core/src/new-process-route-tree.ts -B2 -A2 | head -50Repository: TanStack/router Length of output: 650 🏁 Script executed: # Check if Route extends RouteLike or what the relationship is
rg -n "class Route\|extends.*Route\|implements.*RouteLike" --type=ts packages/router-core/src/route.ts -A3 -B1 | head -40
# Check the full test file to see test coverage quality
wc -l packages/router-core/tests/skip-route-on-parse-error.test.ts
# Check how RouteLike is used - is it for serialization/export?
rg -n "RouteLike" --type=ts packages/router-core/src/ -B2 -A2 | grep -E "export|JSON|serialize|toJSON"| head -20Repository: TanStack/router Length of output: 778 🏁 Script executed: # Check the processRouteTree function to see what it accepts and returns
rg -n "function processRouteTree\|export.*processRouteTree" --type=ts packages/router-core/src/ -A10Repository: TanStack/router Length of output: 41 🏁 Script executed: # Get the processRouteTree function signature and implementation
sed -n '755,790p' packages/router-core/src/new-process-route-tree.tsRepository: TanStack/router Length of output: 1590 🏁 Script executed: # Check what the test file passes as tree parameter to processRouteTree
grep -n "processRouteTree" packages/router-core/tests/skip-route-on-parse-error.test.ts -A5 | head -30Repository: TanStack/router Length of output: 1422 🏁 Script executed: # Check Route class definition to understand relationship to RouteLike
sed -n '586,650p' packages/router-core/src/route.tsRepository: TanStack/router Length of output: 1417 🏁 Script executed: # Search for @experimental or @alpha markers in the entire file
grep -n "@experimental\|@alpha\|experimental\|alpha" packages/router-core/src/route.tsRepository: TanStack/router Length of output: 41 🏁 Script executed: # Check if @experimental/@alpha tags are used elsewhere in the codebase
rg -n "@experimental|@alpha" --type=ts packages/router-core/src/ | head -20Repository: TanStack/router Length of output: 114 🏁 Script executed: # Check Route vs RouteLike - see if they're related or separate concerns# Look at RouteOptions to see if it extends UpdatableRouteOptions
rg -n "type RouteOptions\|interface RouteOptions" --type=ts packages/router-core/src/route.ts -A20 | head -40Repository: TanStack/router Length of output: 41 🏁 Script executed: # Check the test more thoroughly - see if it's testing real routes or just mock objects
tail -100 packages/router-core/tests/skip-route-on-parse-error.test.tsRepository: TanStack/router Length of output: 2824 Update RouteLike interface and add @experimental tag for type safety and consistency. The type structure and documentation for
Comprehensive tests for this feature already exist in packages/router-core/tests/skip-route-on-parse-error.test.ts, covering successful parsing, error skipping with fallbacks, priority ordering, and edge cases. 🤖 Prompt for AI Agents | ||
| /** | ||
| * If true, this route will be matched as case-sensitive | ||
| * | ||
| * @default false | ||
| */ | ||
| caseSensitive?: boolean | ||
| // If true, this route will be forcefully wrapped in a suspense boundary | ||
| /** | ||
| * If true, this route will be forcefully wrapped in a suspense boundary | ||
| */ | ||
| wrapInSuspense?: boolean | ||
| // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />` | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a JSDoc annotation for
@experimentalmentioned this can change. Maybe even a link to the docs RouteOptionsType reference page.If you search the codebase we should have something similar to copy off of marked with
@link.