@tanstack/react-router 0.0.1-beta.273 → 0.0.1-beta.275

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.273",
4
+ "version": "0.0.1-beta.275",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.273"
47
+ "@tanstack/history": "0.0.1-beta.275"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/Matches.tsx CHANGED
@@ -39,13 +39,14 @@ export interface RouteMatch<
39
39
  context: RouteById<TRouteTree, TRouteId>['types']['allContext']
40
40
  search: FullSearchSchema<TRouteTree> &
41
41
  RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
42
- fetchedAt: number
42
+ fetchCount: number
43
43
  shouldReloadDeps: any
44
44
  abortController: AbortController
45
- cause: 'enter' | 'stay'
45
+ cause: 'preload' | 'enter' | 'stay'
46
+ loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']
46
47
  }
47
48
 
48
- export type AnyRouteMatch = RouteMatch<any>
49
+ export type AnyRouteMatch = RouteMatch<any, any>
49
50
 
50
51
  export function Matches() {
51
52
  const router = useRouter()
@@ -54,10 +54,14 @@ export type BuildLocationFn<TRouteTree extends AnyRoute> = (
54
54
 
55
55
  export type InjectedHtmlEntry = string | (() => Promise<string> | string)
56
56
 
57
- export const routerContext = React.createContext<Router<any>>(null!)
57
+ export let routerContext = React.createContext<Router<any>>(null!)
58
58
 
59
59
  if (typeof document !== 'undefined') {
60
- window.__TSR_ROUTER_CONTEXT__ = routerContext as any
60
+ if (window.__TSR_ROUTER_CONTEXT__) {
61
+ routerContext = window.__TSR_ROUTER_CONTEXT__
62
+ } else {
63
+ window.__TSR_ROUTER_CONTEXT__ = routerContext as any
64
+ }
61
65
  }
62
66
 
63
67
  export function RouterProvider<
@@ -212,9 +216,11 @@ export function getRouteMatch<TRouteTree extends AnyRoute>(
212
216
  state: RouterState<TRouteTree>,
213
217
  id: string,
214
218
  ): undefined | RouteMatch<TRouteTree> {
215
- return [...(state.pendingMatches ?? []), ...state.matches].find(
216
- (d) => d.id === id,
217
- )
219
+ return [
220
+ ...state.preloadMatches,
221
+ ...(state.pendingMatches ?? []),
222
+ ...state.matches,
223
+ ].find((d) => d.id === id)
218
224
  }
219
225
 
220
226
  export function useRouterState<
package/src/fileRoute.ts CHANGED
@@ -105,6 +105,7 @@ export class FileRoute<
105
105
  Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
106
106
  >,
107
107
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
108
+ TLoaderDeps extends Record<string, any> = {},
108
109
  TLoaderData extends any = unknown,
109
110
  TChildren extends RouteConstraints['TChildren'] = unknown,
110
111
  TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
@@ -120,6 +121,7 @@ export class FileRoute<
120
121
  TAllParams,
121
122
  TRouteContext,
122
123
  TContext,
124
+ TLoaderDeps,
123
125
  TLoaderData
124
126
  >,
125
127
  'getParentRoute' | 'path' | 'id'
@@ -138,6 +140,7 @@ export class FileRoute<
138
140
  TRouteContext,
139
141
  TContext,
140
142
  TRouterContext,
143
+ TLoaderDeps,
141
144
  TLoaderData,
142
145
  TChildren,
143
146
  TRouteTree
package/src/redirects.ts CHANGED
@@ -5,7 +5,7 @@ import { RegisteredRouter } from './router'
5
5
 
6
6
  // Detect if we're in the DOM
7
7
 
8
- export type AnyRedirect = Redirect<any, any, any>
8
+ export type AnyRedirect = Redirect<any, any, any, any, any>
9
9
 
10
10
  export type Redirect<
11
11
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
package/src/route.ts CHANGED
@@ -62,6 +62,7 @@ export type RouteOptions<
62
62
  TAllParams extends AnyPathParams = TParams,
63
63
  TRouteContext extends RouteContext = RouteContext,
64
64
  TAllContext extends Record<string, any> = AnyContext,
65
+ TLoaderDeps extends Record<string, any> = {},
65
66
  TLoaderData extends any = unknown,
66
67
  > = BaseRouteOptions<
67
68
  TParentRoute,
@@ -73,6 +74,7 @@ export type RouteOptions<
73
74
  TAllParams,
74
75
  TRouteContext,
75
76
  TAllContext,
77
+ TLoaderDeps,
76
78
  TLoaderData
77
79
  > &
78
80
  UpdatableRouteOptions<NoInfer<TFullSearchSchema>>
@@ -82,10 +84,6 @@ export type ParamsFallback<
82
84
  TParams,
83
85
  > = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams
84
86
 
85
- type Prefix<T extends string, U extends string> = U extends `${T}${infer _}`
86
- ? U
87
- : never
88
-
89
87
  export type BaseRouteOptions<
90
88
  TParentRoute extends AnyRoute = AnyRoute,
91
89
  TCustomId extends string = string,
@@ -96,6 +94,7 @@ export type BaseRouteOptions<
96
94
  TAllParams = ParamsFallback<TPath, TParams>,
97
95
  TRouteContext extends RouteContext = RouteContext,
98
96
  TAllContext extends Record<string, any> = AnyContext,
97
+ TLoaderDeps extends Record<string, any> = {},
99
98
  TLoaderData extends any = unknown,
100
99
  > = RoutePathOptions<TCustomId, TPath> & {
101
100
  getParentRoute: () => TParentRoute
@@ -131,10 +130,10 @@ export type BaseRouteOptions<
131
130
  TRouteContext
132
131
  >
133
132
  }) & {
134
- key?: (opts: { search: TFullSearchSchema; location: ParsedLocation }) => any
133
+ loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps
135
134
  loader?: RouteLoaderFn<
136
135
  TAllParams,
137
- TFullSearchSchema,
136
+ NoInfer<TLoaderDeps>,
138
137
  NoInfer<TAllContext>,
139
138
  NoInfer<TRouteContext>,
140
139
  TLoaderData
@@ -171,7 +170,7 @@ type BeforeLoadFn<
171
170
  location: ParsedLocation
172
171
  navigate: NavigateFn<AnyRoute>
173
172
  buildLocation: BuildLocationFn<AnyRoute>
174
- cause: 'enter' | 'stay'
173
+ cause: 'preload' | 'enter' | 'stay'
175
174
  }) => Promise<TRouteContext> | TRouteContext | void
176
175
 
177
176
  export type UpdatableRouteOptions<
@@ -241,34 +240,29 @@ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
241
240
 
242
241
  export type RouteLoaderFn<
243
242
  TAllParams = {},
244
- TFullSearchSchema extends Record<string, any> = {},
243
+ TLoaderDeps extends Record<string, any> = {},
245
244
  TAllContext extends Record<string, any> = AnyContext,
246
245
  TRouteContext extends Record<string, any> = AnyContext,
247
246
  TLoaderData extends any = unknown,
248
247
  > = (
249
- match: LoaderFnContext<
250
- TAllParams,
251
- TFullSearchSchema,
252
- TAllContext,
253
- TRouteContext
254
- >,
248
+ match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,
255
249
  ) => Promise<TLoaderData> | TLoaderData
256
250
 
257
251
  export interface LoaderFnContext<
258
252
  TAllParams = {},
259
- TFullSearchSchema extends Record<string, any> = {},
253
+ TLoaderDeps extends Record<string, any> = {},
260
254
  TAllContext extends Record<string, any> = AnyContext,
261
255
  TRouteContext extends Record<string, any> = AnyContext,
262
256
  > {
263
257
  abortController: AbortController
264
258
  preload: boolean
265
259
  params: TAllParams
266
- search: TFullSearchSchema
260
+ deps: TLoaderDeps
267
261
  context: Expand<Assign<TAllContext, TRouteContext>>
268
- location: ParsedLocation<TFullSearchSchema>
262
+ location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps
269
263
  navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>
270
264
  parentMatchPromise?: Promise<void>
271
- cause: 'enter' | 'stay'
265
+ cause: 'preload' | 'enter' | 'stay'
272
266
  }
273
267
 
274
268
  export type SearchFilter<T, U = T> = (prev: T) => U
@@ -308,6 +302,8 @@ export interface AnyRoute
308
302
  any,
309
303
  any,
310
304
  any,
305
+ any,
306
+ any,
311
307
  any
312
308
  > {}
313
309
 
@@ -425,6 +421,7 @@ export class Route<
425
421
  Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
426
422
  >,
427
423
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
424
+ TLoaderDeps extends Record<string, any> = {},
428
425
  TLoaderData extends any = unknown,
429
426
  TChildren extends RouteConstraints['TChildren'] = unknown,
430
427
  TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
@@ -440,6 +437,7 @@ export class Route<
440
437
  TAllParams,
441
438
  TRouteContext,
442
439
  TAllContext,
440
+ TLoaderDeps,
443
441
  TLoaderData
444
442
  >
445
443
 
@@ -472,6 +470,7 @@ export class Route<
472
470
  TAllParams,
473
471
  TRouteContext,
474
472
  TAllContext,
473
+ TLoaderDeps,
475
474
  TLoaderData
476
475
  >,
477
476
  ) {
@@ -501,6 +500,7 @@ export class Route<
501
500
  routeTree: TRouteTree
502
501
  routerContext: TRouterContext
503
502
  loaderData: TLoaderData
503
+ loaderDeps: TLoaderDeps
504
504
  }
505
505
 
506
506
  init = (opts: { originalIndex: number }) => {
@@ -516,6 +516,7 @@ export class Route<
516
516
  TAllParams,
517
517
  TRouteContext,
518
518
  TAllContext,
519
+ TLoaderDeps,
519
520
  TLoaderData
520
521
  > &
521
522
  RoutePathOptionsIntersection<TCustomId, TPath>
@@ -585,6 +586,8 @@ export class Route<
585
586
  TRouteContext,
586
587
  TAllContext,
587
588
  TRouterContext,
589
+ TLoaderDeps,
590
+ TLoaderData,
588
591
  TNewChildren,
589
592
  TRouteTree
590
593
  > => {
@@ -632,12 +635,13 @@ export class Route<
632
635
  }
633
636
  }
634
637
 
635
- export type AnyRootRoute = RootRoute<any, any, any>
638
+ export type AnyRootRoute = RootRoute<any, any, any, any>
636
639
 
637
640
  export function rootRouteWithContext<TRouterContext extends {}>() {
638
641
  return <
639
642
  TSearchSchema extends Record<string, any> = {},
640
643
  TRouteContext extends RouteContext = RouteContext,
644
+ TLoaderDeps extends Record<string, any> = {},
641
645
  TLoaderData extends any = unknown,
642
646
  >(
643
647
  options?: Omit<
@@ -651,7 +655,8 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
651
655
  {}, // TAllParams
652
656
  TRouteContext, // TRouteContext
653
657
  Assign<TRouterContext, TRouteContext>, // TAllContext
654
- TLoaderData // TLoaderData
658
+ TLoaderDeps,
659
+ TLoaderData // TLoaderData,
655
660
  >,
656
661
  | 'path'
657
662
  | 'id'
@@ -669,6 +674,7 @@ export class RootRoute<
669
674
  TSearchSchema extends Record<string, any> = {},
670
675
  TRouteContext extends RouteContext = RouteContext,
671
676
  TRouterContext extends {} = {},
677
+ TLoaderDeps extends Record<string, any> = {},
672
678
  TLoaderData extends any = unknown,
673
679
  > extends Route<
674
680
  any, // TParentRoute
@@ -683,6 +689,7 @@ export class RootRoute<
683
689
  TRouteContext, // TRouteContext
684
690
  Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
685
691
  TRouterContext, // TRouterContext
692
+ TLoaderDeps,
686
693
  TLoaderData,
687
694
  any, // TChildren
688
695
  any // TRouteTree
@@ -699,6 +706,7 @@ export class RootRoute<
699
706
  {}, // TAllParams
700
707
  TRouteContext, // TRouteContext
701
708
  Assign<TRouterContext, TRouteContext>, // TAllContext
709
+ TLoaderDeps,
702
710
  TLoaderData
703
711
  >,
704
712
  | 'path'
@@ -809,6 +817,7 @@ export class NotFoundRoute<
809
817
  Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
810
818
  >,
811
819
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
820
+ TLoaderDeps extends Record<string, any> = {},
812
821
  TLoaderData extends any = unknown,
813
822
  TChildren extends RouteConstraints['TChildren'] = unknown,
814
823
  TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
@@ -825,6 +834,7 @@ export class NotFoundRoute<
825
834
  TRouteContext,
826
835
  TAllContext,
827
836
  TRouterContext,
837
+ TLoaderDeps,
828
838
  TLoaderData,
829
839
  TChildren,
830
840
  TRouteTree
@@ -841,6 +851,7 @@ export class NotFoundRoute<
841
851
  {},
842
852
  TRouteContext,
843
853
  TAllContext,
854
+ TLoaderDeps,
844
855
  TLoaderData
845
856
  >,
846
857
  'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'
package/src/routeInfo.ts CHANGED
@@ -19,6 +19,8 @@ export type ParseRouteChildren<TRouteTree extends AnyRoute> =
19
19
  any,
20
20
  any,
21
21
  any,
22
+ any,
23
+ any,
22
24
  infer TChildren,
23
25
  any
24
26
  >