Skip to content

Commit 0873c1f

Browse files
feat(react-router): add support for structural sharing for finegrained selectors (#2647)
Co-authored-by: chorobin <[email protected]>
1 parent 581ebe3 commit 0873c1f

Some content is hidden

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

50 files changed

+2028
-784
lines changed

docs/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@
175175
{
176176
"label": "SSR",
177177
"to": "framework/react/guide/ssr"
178+
},
179+
{
180+
"label": "Render Optimizations",
181+
"to": "framework/react/guide/render-optimizations"
178182
}
179183
]
180184
}

docs/framework/react/api/router/RouteApiType.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ The `RouteApi` has the following properties and methods:
2323
- Optional
2424
- `(match: RouteMatch) => TSelected`
2525
- If supplied, this function will be called with the route match and the return value will be returned from `useMatch`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
26+
- `opts.structuralSharing`
27+
- Optional
28+
- `boolean`
29+
- Configures whether structural sharing is enabled for the value returned by `select`.
30+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
2631
- Returns
2732
- If a `select` function is provided, the return value of the `select` function.
2833
- If no `select` function is provided, the `RouteMatch` object or a loosened version of the `RouteMatch` object if `opts.strict` is `false`.
@@ -59,6 +64,11 @@ The `RouteApi` has the following properties and methods:
5964
- Optional
6065
- `(match: TFullSearchSchema) => TSelected`
6166
- If supplied, this function will be called with the route match and the return value will be returned from `useSearch`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
67+
- `opts.structuralSharing`
68+
- Optional
69+
- `boolean`
70+
- Configures whether structural sharing is enabled for the value returned by `select`.
71+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
6272
- Returns
6373
- If a `select` function is provided, the return value of the `select` function.
6474
- If no `select` function is provided, the `TFullSearchSchema` object or a loosened version of the `TFullSearchSchema` object if `opts.strict` is `false`.
@@ -77,6 +87,11 @@ The `RouteApi` has the following properties and methods:
7787
- Optional
7888
- `(match: TAllParams) => TSelected`
7989
- If supplied, this function will be called with the route match and the return value will be returned from `useParams`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
90+
- `opts.structuralSharing`
91+
- Optional
92+
- `boolean`
93+
- Configures whether structural sharing is enabled for the value returned by `select`.
94+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
8095
- Returns
8196
- If a `select` function is provided, the return value of the `select` function.
8297
- If no `select` function is provided, the `TAllParams` object or a loosened version of the `TAllParams` object if `opts.strict` is `false`.
@@ -95,6 +110,11 @@ The `RouteApi` has the following properties and methods:
95110
- Optional
96111
- `(match: TLoaderData) => TSelected`
97112
- If supplied, this function will be called with the route match and the return value will be returned from `useLoaderData`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
113+
- `opts.structuralSharing`
114+
- Optional
115+
- `boolean`
116+
- Configures whether structural sharing is enabled for the value returned by `select`.
117+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
98118
- Returns
99119
- If a `select` function is provided, the return value of the `select` function.
100120
- If no `select` function is provided, the `TLoaderData` object or a loosened version of the `TLoaderData` object if `opts.strict` is `false`.
@@ -113,6 +133,11 @@ The `RouteApi` has the following properties and methods:
113133
- Optional
114134
- `(match: TLoaderDeps) => TSelected`
115135
- If supplied, this function will be called with the route match and the return value will be returned from `useLoaderDeps`.
136+
- `opts.structuralSharing`
137+
- Optional
138+
- `boolean`
139+
- Configures whether structural sharing is enabled for the value returned by `select`.
140+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
116141
- Returns
117142
- If a `select` function is provided, the return value of the `select` function.
118143
- If no `select` function is provided, the `TLoaderDeps` object.

docs/framework/react/api/router/RouterOptionsType.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,11 @@ const router = createRouter({
292292
- Type: `Array<';' | ':' | '@' | '&' | '=' | '+' | '$' | ','>`
293293
- Optional
294294
- Configures which URI characters are allowed in path params that would ordinarily be escaped by encodeURIComponent.
295+
296+
### `defaultStructuralSharing` property
297+
298+
- Type: `boolean`
299+
- Optional
300+
- Defaults to `false`
301+
- Configures whether structural sharing is enabled by default for fine-grained selectors.
302+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.

docs/framework/react/api/router/useChildMatchesHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ The `useChildMatches` hook accepts a single _optional_ argument, an `options` ob
1818
- `(matches: RouteMatch[]) => TSelected`
1919
- If supplied, this function will be called with the route matches and the return value will be returned from `useChildMatches`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
2020

21+
### `opts.structuralSharing` option
22+
23+
- Type: `boolean`
24+
- Optional
25+
- Configures whether structural sharing is enabled for the value returned by `select`.
26+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
27+
2128
## useChildMatches returns
2229

2330
- If a `select` function is provided, the return value of the `select` function.

docs/framework/react/api/router/useLoaderDataHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ The `useLoaderData` hook accepts an `options` object.
2929
- `(loaderData: TLoaderData) => TSelected`
3030
- If supplied, this function will be called with the loader data and the return value will be returned from `useLoaderData`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3131

32+
### `opts.structuralSharing` option
33+
34+
- Type: `boolean`
35+
- Optional
36+
- Configures whether structural sharing is enabled for the value returned by `select`.
37+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
38+
3239
## useLoaderData returns
3340

3441
- If a `select` function is provided, the return value of the `select` function.

docs/framework/react/api/router/useLoaderDepsHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ The `useLoaderDepsHook` hook accepts an `options` object.
2121
- Optional
2222
- If supplied, this function will be called with the loader dependencies object and the return value will be returned from `useLoaderDeps`.
2323

24+
### `opts.structuralSharing` option
25+
26+
- Type: `boolean`
27+
- Optional
28+
- Configures whether structural sharing is enabled for the value returned by `select`.
29+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
30+
2431
## useLoaderDeps returns
2532

2633
- An object of the loader dependencies or `TSelected` if a `select` function is provided.

docs/framework/react/api/router/useMatchHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ The `useMatch` hook accepts a single argument, an `options` object.
3030
- `(match: RouteMatch) => TSelected`
3131
- If supplied, this function will be called with the route match and the return value will be returned from `useMatch`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3232

33+
### `opts.structuralSharing` option
34+
35+
- Type: `boolean`
36+
- Optional
37+
- Configures whether structural sharing is enabled for the value returned by `select`.
38+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
39+
3340
### `opts.shouldThrow` option
3441

3542
- Type: `boolean`

docs/framework/react/api/router/useMatchesHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ The `useMatches` hook accepts a single _optional_ argument, an `options` object.
1818
- `(matches: RouteMatch[]) => TSelected`
1919
- If supplied, this function will be called with the route matches and the return value will be returned from `useMatches`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
2020

21+
### `opts.structuralSharing` option
22+
23+
- Type: `boolean`
24+
- Optional
25+
- Configures whether structural sharing is enabled for the value returned by `select`.
26+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
27+
2128
## useMatches returns
2229

2330
- If a `select` function is provided, the return value of the `select` function.

docs/framework/react/api/router/useParamsHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ The `useParams` hook accepts an optional `options` object.
2121
- `(params: AllParams) => TSelected`
2222
- If supplied, this function will be called with the params object and the return value will be returned from `useParams`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
2323

24+
### `opts.structuralSharing` option
25+
26+
- Type: `boolean`
27+
- Optional
28+
- Configures whether structural sharing is enabled for the value returned by `select`.
29+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
30+
2431
## useParams returns
2532

2633
- An object of of the match's and parent match path params or `TSelected` if a `select` function is provided.

docs/framework/react/api/router/useParentMatchesHook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ The `useParentMatches` hook accepts an optional `options` object.
1818
- `(matches: RouteMatch[]) => TSelected`
1919
- If supplied, this function will be called with the route matches and the return value will be returned from `useParentMatches`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
2020

21+
### `opts.structuralSharing` option
22+
23+
- Type: `boolean`
24+
- Optional
25+
- Configures whether structural sharing is enabled for the value returned by `select`.
26+
- See the [Render Optimizations guide](../../guide/render-optimizations.md) for more information.
27+
2128
## useParentMatches returns
2229

2330
- If a `select` function is provided, the return value of the `select` function.

0 commit comments

Comments
 (0)