@tanstack/react-router 0.0.1-beta.225 → 0.0.1-beta.226

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.225",
4
+ "version": "0.0.1-beta.226",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -42,7 +42,7 @@
42
42
  "@babel/runtime": "^7.16.7",
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
- "@tanstack/history": "0.0.1-beta.225"
45
+ "@tanstack/history": "0.0.1-beta.226"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "rollup --config rollup.config.js"
@@ -102,12 +102,6 @@ export type MatchRouteFn<TRouteTree extends AnyRoute> = <
102
102
  opts?: MatchRouteOptions,
103
103
  ) => false | RouteById<TRouteTree, TResolved>['types']['allParams']
104
104
 
105
- export type LoadFn = (opts?: {
106
- next?: ParsedLocation
107
- throwOnError?: boolean
108
- __dehydratedMatches?: DehydratedRouteMatch[]
109
- }) => Promise<void>
110
-
111
105
  export type BuildLocationFn<TRouteTree extends AnyRoute> = (
112
106
  opts: BuildNextOptions,
113
107
  ) => ParsedLocation
@@ -170,11 +164,15 @@ export function RouterProvider<
170
164
  router.updateOptions({
171
165
  ...router.options,
172
166
  ...rest,
167
+
173
168
  context: {
174
169
  ...router.options.context,
175
170
  ...rest?.context,
176
171
  },
177
- } as PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>)
172
+ } as PickAsRequired<
173
+ RouterOptions<TRouteTree, TDehydrated>,
174
+ 'stringifySearch' | 'parseSearch' | 'context'
175
+ >)
178
176
 
179
177
  const [preState, setState] = React.useState(() => router.state)
180
178
  const [isTransitioning, startReactTransition] = React.useTransition()
@@ -222,7 +220,7 @@ export function RouterProvider<
222
220
  return () => {
223
221
  unsub()
224
222
  }
225
- }, [history])
223
+ }, [router.history])
226
224
 
227
225
  React.useLayoutEffect(() => {
228
226
  if (!isTransitioning && state.resolvedLocation !== state.location) {
package/src/route.ts CHANGED
@@ -76,13 +76,11 @@ export type RouteOptions<
76
76
  TAllContext,
77
77
  TLoaderData
78
78
  > &
79
- NoInfer<
80
- UpdatableRouteOptions<
81
- TFullSearchSchema,
82
- TAllParams,
83
- TAllContext,
84
- TLoaderData
85
- >
79
+ UpdatableRouteOptions<
80
+ NoInfer<TFullSearchSchema>,
81
+ NoInfer<TAllParams>,
82
+ NoInfer<TAllContext>,
83
+ NoInfer<TLoaderData>
86
84
  >
87
85
 
88
86
  export type ParamsFallback<
@@ -389,7 +387,8 @@ export class Route<
389
387
  TPath
390
388
  >,
391
389
  TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
392
- TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
390
+ TFullSearchSchema extends
391
+ RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
393
392
  TParentRoute,
394
393
  TSearchSchema
395
394
  >,
@@ -714,14 +713,14 @@ type RoutePrefix<
714
713
  > = string extends TPath
715
714
  ? RootRouteId
716
715
  : TPath extends string
717
- ? TPrefix extends RootRouteId
718
- ? TPath extends '/'
719
- ? '/'
720
- : `/${TrimPath<TPath>}`
721
- : `${TPrefix}/${TPath}` extends '/'
722
- ? '/'
723
- : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
724
- : never
716
+ ? TPrefix extends RootRouteId
717
+ ? TPath extends '/'
718
+ ? '/'
719
+ : `/${TrimPath<TPath>}`
720
+ : `${TPrefix}/${TPath}` extends '/'
721
+ ? '/'
722
+ : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
723
+ : never
725
724
 
726
725
  export type TrimPath<T extends string> = '' extends T
727
726
  ? ''
@@ -731,13 +730,13 @@ export type TrimPathLeft<T extends string> =
731
730
  T extends `${RootRouteId}/${infer U}`
732
731
  ? TrimPathLeft<U>
733
732
  : T extends `/${infer U}`
734
- ? TrimPathLeft<U>
735
- : T
733
+ ? TrimPathLeft<U>
734
+ : T
736
735
  export type TrimPathRight<T extends string> = T extends '/'
737
736
  ? '/'
738
737
  : T extends `${infer U}/`
739
- ? TrimPathRight<U>
740
- : T
738
+ ? TrimPathRight<U>
739
+ : T
741
740
 
742
741
  export type RouteMask<TRouteTree extends AnyRoute> = {
743
742
  routeTree: TRouteTree
@@ -842,20 +841,20 @@ export type ComponentPropsFromRoute<TRoute> =
842
841
  TRoute extends (() => infer T extends AnyRoute)
843
842
  ? ComponentPropsFromRoute<T>
844
843
  : TRoute extends Route<
845
- infer TParentRoute,
846
- infer TPath,
847
- infer TFullPath,
848
- infer TCustomId,
849
- infer TId,
850
- infer TSearchSchema,
851
- infer TFullSearchSchema,
852
- infer TParams,
853
- infer TAllParams,
854
- infer TRouteContext,
855
- infer TAllContext,
856
- infer TRouterContext,
857
- infer TLoaderData,
858
- infer TChildren
859
- >
860
- ? RouteProps<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>
861
- : {}
844
+ infer TParentRoute,
845
+ infer TPath,
846
+ infer TFullPath,
847
+ infer TCustomId,
848
+ infer TId,
849
+ infer TSearchSchema,
850
+ infer TFullSearchSchema,
851
+ infer TParams,
852
+ infer TAllParams,
853
+ infer TRouteContext,
854
+ infer TAllContext,
855
+ infer TRouterContext,
856
+ infer TLoaderData,
857
+ infer TChildren
858
+ >
859
+ ? RouteProps<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>
860
+ : {}
package/src/router.ts CHANGED
@@ -43,7 +43,6 @@ import {
43
43
  BuildLocationFn,
44
44
  CommitLocationOptions,
45
45
  InjectedHtmlEntry,
46
- LoadFn,
47
46
  MatchRouteFn,
48
47
  NavigateFn,
49
48
  PathParamError,
@@ -679,8 +678,8 @@ export class Router<
679
678
  let pathname = this.resolvePathWithBase(fromPathname, `${dest.to ?? ''}`)
680
679
 
681
680
  const fromMatches = this.matchRoutes(fromPathname, from.search)
682
- const stayingMatches = matches?.filter((d) =>
683
- fromMatches?.find((e) => e.routeId === d.routeId),
681
+ const stayingMatches = matches?.filter(
682
+ (d) => fromMatches?.find((e) => e.routeId === d.routeId),
684
683
  )
685
684
 
686
685
  const prevParams = { ...last(fromMatches)?.params }
@@ -734,10 +733,10 @@ export class Router<
734
733
  dest.search === true
735
734
  ? preFilteredSearch // Preserve resolvedFrom true
736
735
  : dest.search
737
- ? functionalUpdate(dest.search, preFilteredSearch) ?? {} // Updater
738
- : preSearchFilters?.length
739
- ? preFilteredSearch // Preserve resolvedFrom filters
740
- : {}
736
+ ? functionalUpdate(dest.search, preFilteredSearch) ?? {} // Updater
737
+ : preSearchFilters?.length
738
+ ? preFilteredSearch // Preserve resolvedFrom filters
739
+ : {}
741
740
 
742
741
  // Then post filters
743
742
  const postFilteredSearch = postSearchFilters?.length
@@ -752,8 +751,8 @@ export class Router<
752
751
  dest.hash === true
753
752
  ? from.hash
754
753
  : dest.hash
755
- ? functionalUpdate(dest.hash!, from.hash)
756
- : from.hash
754
+ ? functionalUpdate(dest.hash!, from.hash)
755
+ : from.hash
757
756
 
758
757
  const hashStr = hash ? `#${hash}` : ''
759
758
 
@@ -761,8 +760,8 @@ export class Router<
761
760
  dest.state === true
762
761
  ? from.state
763
762
  : dest.state
764
- ? functionalUpdate(dest.state, from.state)
765
- : from.state
763
+ ? functionalUpdate(dest.state, from.state)
764
+ : from.state
766
765
 
767
766
  nextState = replaceEqualDeep(from.state, nextState)
768
767
 
@@ -945,10 +944,12 @@ export class Router<
945
944
  checkLatest,
946
945
  matches,
947
946
  preload,
947
+ invalidate,
948
948
  }: {
949
949
  checkLatest: () => Promise<void> | undefined
950
950
  matches: AnyRouteMatch[]
951
951
  preload?: boolean
952
+ invalidate?: boolean
952
953
  }): Promise<RouteMatch[]> => {
953
954
  let latestPromise
954
955
  let firstBadMatchIndex: number | undefined
@@ -1086,7 +1087,7 @@ export class Router<
1086
1087
  ? route.options.shouldReload?.(loaderContext)
1087
1088
  : !!(route.options.shouldReload ?? true)
1088
1089
 
1089
- if (match.cause === 'enter') {
1090
+ if (match.cause === 'enter' || invalidate) {
1090
1091
  match.shouldReloadDeps = shouldReloadDeps
1091
1092
  } else if (match.cause === 'stay') {
1092
1093
  if (typeof shouldReloadDeps === 'object') {
@@ -1192,7 +1193,12 @@ export class Router<
1192
1193
  return matches
1193
1194
  }
1194
1195
 
1195
- load: LoadFn = async () => {
1196
+ invalidate = () =>
1197
+ this.load({
1198
+ invalidate: true,
1199
+ })
1200
+
1201
+ load = async (opts?: { invalidate?: boolean }): Promise<void> => {
1196
1202
  const promise = new Promise<void>(async (resolve, reject) => {
1197
1203
  const next = this.latestLocation
1198
1204
  const prevLocation = this.state.resolvedLocation
@@ -1236,6 +1242,7 @@ export class Router<
1236
1242
  await this.loadMatches({
1237
1243
  matches,
1238
1244
  checkLatest: () => this.checkLatest(promise),
1245
+ invalidate: opts?.invalidate,
1239
1246
  })
1240
1247
  } catch (err) {
1241
1248
  // swallow this error, since we'll display the