Skip to content

Commit 0545239

Browse files
authored
refactor: signal based reactivity (#6704)
1 parent 7f38aac commit 0545239

106 files changed

Lines changed: 4369 additions & 2509 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/five-towns-wave.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@tanstack/router-ssr-query-core': minor
3+
'@tanstack/router-devtools-core': minor
4+
'@tanstack/start-client-core': minor
5+
'@tanstack/start-server-core': minor
6+
'@tanstack/router-plugin': minor
7+
'@tanstack/react-router': minor
8+
'@tanstack/solid-router': minor
9+
'@tanstack/react-start': minor
10+
'@tanstack/router-core': minor
11+
'@tanstack/solid-start': minor
12+
'@tanstack/vue-router': minor
13+
'@tanstack/vue-start': minor
14+
---
15+
16+
remove pendingMatches, cachedMatches
17+
move to signal-based reactivity
18+
solid uses its own native signals

‎docs/router/api/router/RouterStateType.md‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type RouterState = {
1111
isLoading: boolean
1212
isTransitioning: boolean
1313
matches: Array<RouteMatch>
14-
pendingMatches: Array<RouteMatch>
1514
location: ParsedLocation
1615
resolvedLocation: ParsedLocation
1716
}
@@ -41,11 +40,6 @@ The `RouterState` type contains all of the properties that are available on the
4140
- Type: [`Array<RouteMatch>`](./RouteMatchType.md)
4241
- An array of all of the route matches that have been resolved and are currently active.
4342
44-
### `pendingMatches` property
45-
46-
- Type: [`Array<RouteMatch>`](./RouteMatchType.md)
47-
- An array of all of the route matches that are currently pending.
48-
4943
### `location` property
5044
5145
- Type: [`ParsedLocation`](./ParsedLocationType.md)

‎docs/router/api/router/useChildMatchesHook.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: useChildMatches hook
66
The `useChildMatches` hook returns all of the child [`RouteMatch`](./RouteMatchType.md) objects from the closest match down to the leaf-most match. **It does not include the current match, which can be obtained using the `useMatch` hook.**
77

88
> [!IMPORTANT]
9-
> If the router has pending matches and they are showing their pending component fallbacks, `router.state.pendingMatches` will used instead of `router.state.matches`.
9+
> If the router has pending matches and they are showing their pending component fallbacks, pending matches are used instead of active matches.
1010
1111
## useChildMatches options
1212

‎docs/router/api/router/useParentMatchesHook.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: useParentMatches hook
66
The `useParentMatches` hook returns all of the parent [`RouteMatch`](./RouteMatchType.md) objects from the root down to the immediate parent of the current match in context. **It does not include the current match, which can be obtained using the `useMatch` hook.**
77

88
> [!IMPORTANT]
9-
> If the router has pending matches and they are showing their pending component fallbacks, `router.state.pendingMatches` will used instead of `router.state.matches`.
9+
> If the router has pending matches and they are showing their pending component fallbacks, pending matches are used instead of active matches.
1010
1111
## useParentMatches options
1212

‎docs/router/api/router/useRouterStateHook.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: useRouterState hook
66
The `useRouterState` method is a hook that returns the current internal state of the router. This hook is useful for accessing the current state of the router in a component.
77

88
> [!TIP]
9-
> If you want to access the current location or the current matches, you should try out the [`useLocation`](./useLocationHook.md) and [`useMatches`](./useMatchesHook.md) hooks first. These hooks are designed to be more ergonomic and easier to use than accessing the router state directly.
9+
> If you want to access the current location or the current matches, you should try out the [`useLocation`](./useLocationHook.md) and [`useMatches`](./useMatchesHook.md) hooks first. These hooks are designed to be more performant, more ergonomic and easier to use than accessing the router state directly.
1010
1111
## useRouterState options
1212

‎e2e/react-router/basic-file-based/tests/app.spec.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ async function structuralSharingTest(page: Page, enabled: boolean) {
268268

269269
test('structural sharing disabled', async ({ page }) => {
270270
await structuralSharingTest(page, false)
271+
expect(await getRenderCount(page)).toBe(2)
272+
await page.getByTestId('link').click()
271273
expect(await getRenderCount(page)).toBeGreaterThan(2)
272274
})
273275

‎e2e/solid-start/basic/tests/transition.spec.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { expect, test } from '@playwright/test'
33
test('transitions/count/create-resource should keep old values visible during navigation', async ({
44
page,
55
}) => {
6+
const burstClicks = async (count: number) => {
7+
await page
8+
.getByTestId('increase-button')
9+
.evaluate((element, clickCount) => {
10+
for (let index = 0; index < clickCount; index++) {
11+
;(element as HTMLAnchorElement).click()
12+
}
13+
}, count)
14+
}
15+
616
await page.goto('/transition/count/create-resource')
717

818
await expect(page.getByTestId('n-value')).toContainText('n: 1')
@@ -20,7 +30,7 @@ test('transitions/count/create-resource should keep old values visible during na
2030

2131
// 1 click
2232

23-
page.getByTestId('increase-button').click()
33+
await burstClicks(1)
2434

2535
await expect(page.getByTestId('n-value')).toContainText('n: 1', {
2636
timeout: 2_000,
@@ -40,8 +50,7 @@ test('transitions/count/create-resource should keep old values visible during na
4050

4151
// 2 clicks
4252

43-
page.getByTestId('increase-button').click()
44-
page.getByTestId('increase-button').click()
53+
await burstClicks(2)
4554

4655
await expect(page.getByTestId('n-value')).toContainText('n: 2', {
4756
timeout: 2000,
@@ -61,9 +70,7 @@ test('transitions/count/create-resource should keep old values visible during na
6170

6271
// 3 clicks
6372

64-
page.getByTestId('increase-button').click()
65-
page.getByTestId('increase-button').click()
66-
page.getByTestId('increase-button').click()
73+
await burstClicks(3)
6774

6875
await expect(page.getByTestId('n-value')).toContainText('n: 4', {
6976
timeout: 2000,

‎packages/react-router/skills/react-router/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ function InvalidateButton() {
165165

166166
### `useRouterState()`
167167

168-
Subscribe to router state changes:
168+
Subscribe to router state changes. Exposes the entire state and thus incurs
169+
a performance cost. For matches or location favor `useMatches` and `useLocation`.
169170

170171
```tsx
171172
import { useRouterState } from '@tanstack/react-router'

0 commit comments

Comments
 (0)