-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: preserve shouldThrow in route-scoped hooks #8169
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
Merged
Sheraff
merged 5 commits into
TanStack:main
from
mizukendesu:fix/route-use-match-should-throw
Aug 27, 2026
+401
−182
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b706e07
fix(react-router): forward shouldThrow in Route.useMatch
mizukendesu e4cf081
ci: apply automated fixes
autofix-ci[bot] 50a4fa7
fix(react-router,solid-router,vue-router): preserve shouldThrow in ro…
mizukendesu 54cb3fe
test: simplify route-scoped shouldThrow coverage
Sheraff 9cdbe34
Merge pull request #1 from Sheraff/review/8169-route-scoped-tests
mizukendesu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@tanstack/react-router': patch | ||
| '@tanstack/solid-router': patch | ||
| '@tanstack/vue-router': patch | ||
| --- | ||
|
|
||
| Fix route-scoped `useMatch`, `useSearch`, and `useParams` APIs to forward the `shouldThrow` option and preserve optional return types when `shouldThrow: false`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/react-router/tests/routeScopedShouldThrow.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { afterEach, expect, test } from 'vitest' | ||
| import { cleanup, render, screen } from '@testing-library/react' | ||
| import { | ||
| Outlet, | ||
| RouterProvider, | ||
| createLazyRoute, | ||
| createMemoryHistory, | ||
| createRootRoute, | ||
| createRoute, | ||
| createRouter, | ||
| getRouteApi, | ||
| } from '../src' | ||
|
|
||
| afterEach(() => { | ||
| window.history.replaceState(null, 'root', '/') | ||
| cleanup() | ||
| }) | ||
|
|
||
| test('route-scoped hooks render undefined for an inactive route when shouldThrow is false', async () => { | ||
| const rootRoute = createRootRoute({ | ||
| component: Outlet, | ||
| }) | ||
| const postsRoute = createRoute({ | ||
| getParentRoute: () => rootRoute, | ||
| path: '/posts/$postId', | ||
| validateSearch: () => ({ page: 0 }), | ||
| }) | ||
| const postsRouteApi = getRouteApi('/posts/$postId') | ||
| const lazyPostsRoute = createLazyRoute('/posts/$postId')({}) | ||
|
|
||
| function IndexComponent() { | ||
| const routeMatch = postsRoute.useMatch({ shouldThrow: false }) | ||
| const routeSearch = postsRoute.useSearch({ shouldThrow: false }) | ||
| const routeParams = postsRoute.useParams({ shouldThrow: false }) | ||
| const routeApiMatch = postsRouteApi.useMatch({ shouldThrow: false }) | ||
| const routeApiSearch = postsRouteApi.useSearch({ shouldThrow: false }) | ||
| const routeApiParams = postsRouteApi.useParams({ shouldThrow: false }) | ||
| const lazyRouteMatch = lazyPostsRoute.useMatch({ shouldThrow: false }) | ||
| const lazyRouteSearch = lazyPostsRoute.useSearch({ shouldThrow: false }) | ||
| const lazyRouteParams = lazyPostsRoute.useParams({ shouldThrow: false }) | ||
|
|
||
| return ( | ||
| <> | ||
| <div data-testid="route-use-match">{String(routeMatch)}</div> | ||
| <div data-testid="route-use-search">{String(routeSearch)}</div> | ||
| <div data-testid="route-use-params">{String(routeParams)}</div> | ||
| <div data-testid="route-api-use-match">{String(routeApiMatch)}</div> | ||
| <div data-testid="route-api-use-search">{String(routeApiSearch)}</div> | ||
| <div data-testid="route-api-use-params">{String(routeApiParams)}</div> | ||
| <div data-testid="lazy-route-use-match">{String(lazyRouteMatch)}</div> | ||
| <div data-testid="lazy-route-use-search">{String(lazyRouteSearch)}</div> | ||
| <div data-testid="lazy-route-use-params">{String(lazyRouteParams)}</div> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| const indexRoute = createRoute({ | ||
| getParentRoute: () => rootRoute, | ||
| path: '/', | ||
| component: IndexComponent, | ||
| }) | ||
| const router = createRouter({ | ||
| routeTree: rootRoute.addChildren([indexRoute, postsRoute]), | ||
| history: createMemoryHistory({ initialEntries: ['/'] }), | ||
| }) | ||
|
|
||
| render(<RouterProvider router={router} />) | ||
|
|
||
| for (const scope of ['route', 'route-api', 'lazy-route']) { | ||
| for (const hook of ['use-match', 'use-search', 'use-params']) { | ||
| expect(await screen.findByTestId(`${scope}-${hook}`)).toHaveTextContent( | ||
| 'undefined', | ||
| ) | ||
| } | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: TanStack/router
Length of output: 50371
🌐 Web query:
site:github.com/TanStack/router/issues/8168 OR site:github.com/TanStack/router/pull/8168💡 Result:
There is no information available in the provided search results regarding a product called the Meta Quest 3S. The search results consist exclusively of a technical issue report for a software library called TanStack Router and do not contain any data related to Meta's VR hardware lineup or a product by that name.
Citations:
🏁 Script executed:
Repository: TanStack/router
Length of output: 5381
🏁 Script executed:
Repository: TanStack/router
Length of output: 4642
🏁 Script executed:
Repository: TanStack/router
Length of output: 50373
🏁 Script executed:
Repository: TanStack/router
Length of output: 715
Obtain maintainer sign-off before merging this public API change.
Issue
#8168was created after the first implementation commitb706e073b4714a8a3ec60b2bf754347fc3c352ff. No maintainer approval appears before implementation.🤖 Prompt for AI Agents
Source: Coding guidelines