@tanstack/react-router 1.111.6 → 1.111.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
2
2
  import { AnyRouter, RegisteredRouter } from './router.js';
3
- import { MakeRouteMatch, MakeRouteMatchUnion } from './Matches.js';
4
- import { StrictOrFrom, ThrowOrOptional } from '@tanstack/router-core';
3
+ import { MakeRouteMatch, MakeRouteMatchUnion, StrictOrFrom, ThrowOrOptional } from '@tanstack/router-core';
5
4
  export interface UseMatchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing extends boolean> {
6
5
  select?: (match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
7
6
  shouldThrow?: TThrow;
@@ -1 +1 @@
1
- {"version":3,"file":"useMatch.js","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { MakeRouteMatch, MakeRouteMatchUnion } from './Matches'\nimport type { StrictOrFrom, ThrowOrOptional } from '@tanstack/router-core'\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport function useMatch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const matchSelection = useRouterState({\n select: (state: any) => {\n const match = state.matches.find((d: any) =>\n opts.from ? opts.from === d.routeId : d.id === nearestMatchId,\n )\n invariant(\n !((opts.shouldThrow ?? true) && !match),\n `Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n\n if (match === undefined) {\n return undefined\n }\n\n return opts.select ? opts.select(match) : match\n },\n structuralSharing: opts.structuralSharing,\n } as any)\n\n return matchSelection as any\n}\n"],"names":[],"mappings":";;;;AA4EO,SAAS,SAQd,MAQ6E;AAC7E,QAAM,iBAAiB,MAAM;AAAA,IAC3B,KAAK,OAAO,oBAAoB;AAAA,EAClC;AAEA,QAAM,iBAAiB,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAe;AAChB,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MACjD;AACA;AAAA,QACE,GAAG,KAAK,eAAe,SAAS,CAAC;AAAA,QACjC,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAC1F;AAEA,UAAI,UAAU,QAAW;AAChB,eAAA;AAAA,MAAA;AAGT,aAAO,KAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AAAA,IAC5C;AAAA,IACA,mBAAmB,KAAK;AAAA,EAAA,CAClB;AAED,SAAA;AACT;"}
1
+ {"version":3,"file":"useMatch.js","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type {\n MakeRouteMatch,\n MakeRouteMatchUnion,\n StrictOrFrom,\n ThrowOrOptional,\n} from '@tanstack/router-core'\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport function useMatch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const matchSelection = useRouterState({\n select: (state: any) => {\n const match = state.matches.find((d: any) =>\n opts.from ? opts.from === d.routeId : d.id === nearestMatchId,\n )\n invariant(\n !((opts.shouldThrow ?? true) && !match),\n `Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n\n if (match === undefined) {\n return undefined\n }\n\n return opts.select ? opts.select(match) : match\n },\n structuralSharing: opts.structuralSharing,\n } as any)\n\n return matchSelection as any\n}\n"],"names":[],"mappings":";;;;AAgFO,SAAS,SAQd,MAQ6E;AAC7E,QAAM,iBAAiB,MAAM;AAAA,IAC3B,KAAK,OAAO,oBAAoB;AAAA,EAClC;AAEA,QAAM,iBAAiB,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAe;AAChB,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MACjD;AACA;AAAA,QACE,GAAG,KAAK,eAAe,SAAS,CAAC;AAAA,QACjC,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAC1F;AAEA,UAAI,UAAU,QAAW;AAChB,eAAA;AAAA,MAAA;AAGT,aAAO,KAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AAAA,IAC5C;AAAA,IACA,mBAAmB,KAAK;AAAA,EAAA,CAClB;AAED,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.111.6",
3
+ "version": "1.111.7",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "tiny-invariant": "^1.3.3",
55
55
  "tiny-warning": "^1.0.3",
56
56
  "@tanstack/history": "1.99.13",
57
- "@tanstack/router-core": "^1.111.6"
57
+ "@tanstack/router-core": "^1.111.7"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@testing-library/jest-dom": "^6.6.3",
package/src/Matches.tsx CHANGED
@@ -11,111 +11,30 @@ import type {
11
11
  StructuralSharingOption,
12
12
  ValidateSelected,
13
13
  } from './structuralSharing'
14
- import type { AnyRoute, ReactNode } from './route'
14
+ import type { ReactNode } from './route'
15
15
  import type {
16
- AllContext,
17
- AllLoaderData,
18
- AllParams,
19
- ControlledPromise,
20
16
  DeepPartial,
21
- FullSearchSchema,
22
17
  MakeOptionalPathParams,
23
18
  MakeOptionalSearchParams,
19
+ MakeRouteMatchUnion,
24
20
  MaskOptions,
25
21
  NoInfer,
26
- ParseRoute,
27
22
  ResolveRelativePath,
28
23
  ResolveRoute,
29
- RouteById,
30
24
  RouteByPath,
31
- RouteIds,
32
- StaticDataRouteOption,
33
25
  ToSubOptionsProps,
34
26
  } from '@tanstack/router-core'
35
27
  import type { AnyRouter, RegisteredRouter, RouterState } from './router'
36
28
 
37
- export type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<
38
- TRoute['types']['id'],
39
- TRoute['types']['fullPath'],
40
- TRoute['types']['allParams'],
41
- TRoute['types']['fullSearchSchema'],
42
- TRoute['types']['loaderData'],
43
- TRoute['types']['allContext'],
44
- TRoute['types']['loaderDeps']
45
- >
46
-
47
- export interface RouteMatch<
48
- out TRouteId,
49
- out TFullPath,
50
- out TAllParams,
51
- out TFullSearchSchema,
52
- out TLoaderData,
53
- out TAllContext,
54
- out TLoaderDeps,
55
- > {
56
- id: string
57
- routeId: TRouteId
58
- fullPath: TFullPath
59
- index: number
60
- pathname: string
61
- params: TAllParams
62
- _strictParams: TAllParams
63
- status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'
64
- isFetching: false | 'beforeLoad' | 'loader'
65
- error: unknown
66
- paramsError: unknown
67
- searchError: unknown
68
- updatedAt: number
69
- loadPromise?: ControlledPromise<void>
70
- beforeLoadPromise?: ControlledPromise<void>
71
- loaderPromise?: ControlledPromise<void>
72
- loaderData?: TLoaderData
73
- __routeContext: Record<string, unknown>
74
- __beforeLoadContext: Record<string, unknown>
75
- context: TAllContext
76
- search: TFullSearchSchema
77
- _strictSearch: TFullSearchSchema
78
- fetchCount: number
79
- abortController: AbortController
80
- cause: 'preload' | 'enter' | 'stay'
81
- loaderDeps: TLoaderDeps
82
- preload: boolean
83
- invalid: boolean
84
- meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>
85
- links?: Array<React.JSX.IntrinsicElements['link'] | undefined>
86
- scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>
87
- headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>
88
- headers?: Record<string, string>
89
- globalNotFound?: boolean
90
- staticData: StaticDataRouteOption
91
- minPendingPromise?: ControlledPromise<void>
92
- pendingTimeout?: ReturnType<typeof setTimeout>
29
+ declare module '@tanstack/router-core' {
30
+ export interface RouteMatchExtensions {
31
+ meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>
32
+ links?: Array<React.JSX.IntrinsicElements['link'] | undefined>
33
+ scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>
34
+ headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>
35
+ }
93
36
  }
94
37
 
95
- export type MakeRouteMatch<
96
- TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
97
- TRouteId = RouteIds<TRouteTree>,
98
- TStrict extends boolean = true,
99
- > = RouteMatch<
100
- TRouteId,
101
- RouteById<TRouteTree, TRouteId>['types']['fullPath'],
102
- TStrict extends false
103
- ? AllParams<TRouteTree>
104
- : RouteById<TRouteTree, TRouteId>['types']['allParams'],
105
- TStrict extends false
106
- ? FullSearchSchema<TRouteTree>
107
- : RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],
108
- TStrict extends false
109
- ? AllLoaderData<TRouteTree>
110
- : RouteById<TRouteTree, TRouteId>['types']['loaderData'],
111
- TStrict extends false
112
- ? AllContext<TRouteTree>
113
- : RouteById<TRouteTree, TRouteId>['types']['allContext'],
114
- RouteById<TRouteTree, TRouteId>['types']['loaderDeps']
115
- >
116
-
117
- export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>
118
-
119
38
  export function Matches() {
120
39
  const router = useRouter()
121
40
 
@@ -257,21 +176,6 @@ export function MatchRoute<
257
176
  return params ? props.children : null
258
177
  }
259
178
 
260
- export type MakeRouteMatchUnion<
261
- TRouter extends AnyRouter = RegisteredRouter,
262
- TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,
263
- > = TRoute extends any
264
- ? RouteMatch<
265
- TRoute['id'],
266
- TRoute['fullPath'],
267
- TRoute['types']['allParams'],
268
- TRoute['types']['fullSearchSchema'],
269
- TRoute['types']['loaderData'],
270
- TRoute['types']['allContext'],
271
- TRoute['types']['loaderDeps']
272
- >
273
- : never
274
-
275
179
  export interface UseMatchesBaseOptions<
276
180
  TRouter extends AnyRouter,
277
181
  TSelected,
package/src/fileRoute.ts CHANGED
@@ -11,14 +11,7 @@ import type { UseParamsRoute } from './useParams'
11
11
  import type { UseMatchRoute } from './useMatch'
12
12
  import type { UseSearchRoute } from './useSearch'
13
13
 
14
- import type {
15
- AnyRoute,
16
- FileBaseRouteOptions,
17
- Route,
18
- RouteConstraints,
19
- RouteLoaderFn,
20
- UpdatableRouteOptions,
21
- } from './route'
14
+ import type { AnyRoute, Route, RouteConstraints } from './route'
22
15
  import type { RegisteredRouter } from './router'
23
16
  import type {
24
17
  AnyContext,
@@ -28,10 +21,13 @@ import type {
28
21
  AnyValidator,
29
22
  Constrain,
30
23
  ConstrainLiteral,
24
+ FileBaseRouteOptions,
31
25
  FileRoutesByPath,
32
26
  ResolveParams,
33
27
  RouteById,
34
28
  RouteIds,
29
+ RouteLoaderFn,
30
+ UpdatableRouteOptions,
35
31
  } from '@tanstack/router-core'
36
32
  import type { UseLoaderDepsRoute } from './useLoaderDeps'
37
33
  import type { UseLoaderDataRoute } from './useLoaderData'
package/src/index.tsx CHANGED
@@ -123,6 +123,7 @@ export type {
123
123
  ValidatorObj,
124
124
  FileRoutesByPath,
125
125
  RouteById,
126
+ RootRouteOptions,
126
127
  } from '@tanstack/router-core'
127
128
 
128
129
  export {
@@ -199,6 +200,21 @@ export type {
199
200
  AnyRedirect,
200
201
  Redirect,
201
202
  ResolvedRedirect,
203
+ MakeRouteMatch,
204
+ MakeRouteMatchUnion,
205
+ RouteMatch,
206
+ AnyRouteMatch,
207
+ RouteContextFn,
208
+ RouteContextOptions,
209
+ BeforeLoadFn,
210
+ BeforeLoadContextOptions,
211
+ ContextOptions,
212
+ RouteOptions,
213
+ FileBaseRouteOptions,
214
+ BaseRouteOptions,
215
+ UpdatableRouteOptions,
216
+ RouteLoaderFn,
217
+ LoaderFnContext,
202
218
  } from '@tanstack/router-core'
203
219
  export type {
204
220
  UseLinkPropsOptions,
@@ -219,13 +235,9 @@ export {
219
235
  } from './Matches'
220
236
 
221
237
  export type {
222
- RouteMatch,
223
- AnyRouteMatch,
224
238
  MatchRouteOptions,
225
239
  UseMatchRouteOptions,
226
240
  MakeMatchRouteOptions,
227
- MakeRouteMatch,
228
- MakeRouteMatchUnion,
229
241
  } from './Matches'
230
242
 
231
243
  export { matchContext } from './matchContext'
@@ -250,12 +262,6 @@ export {
250
262
  NotFoundRoute,
251
263
  } from './route'
252
264
  export type {
253
- RouteOptions,
254
- FileBaseRouteOptions,
255
- BaseRouteOptions,
256
- UpdatableRouteOptions,
257
- RouteLoaderFn,
258
- LoaderFnContext,
259
265
  AnyRoute,
260
266
  RouteConstraints,
261
267
  AnyRootRoute,
@@ -266,12 +272,6 @@ export type {
266
272
  RouteComponent,
267
273
  ErrorRouteComponent,
268
274
  NotFoundRouteComponent,
269
- RootRouteOptions,
270
- RouteContextFn,
271
- RouteContextOptions,
272
- BeforeLoadFn,
273
- BeforeLoadContextOptions,
274
- ContextOptions,
275
275
  } from './route'
276
276
 
277
277
  export {