@tanstack/router-core 0.0.1-beta.160 → 0.0.1-beta.162

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/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.160",
4
+ "version": "0.0.1-beta.162",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -43,7 +43,7 @@
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
45
  "@gisatcz/cross-package-react-context": "^0.2.0",
46
- "@tanstack/react-store": "0.0.1-beta.160"
46
+ "@tanstack/react-store": "0.0.1-beta.162"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rollup --config rollup.config.js",
package/src/fileRoute.ts CHANGED
@@ -59,7 +59,7 @@ export type ResolveFilePath<
59
59
  ? TrimPathLeft<TFilePath>
60
60
  : Replace<
61
61
  TrimPathLeft<TFilePath>,
62
- TrimPathLeft<TParentRoute['__types']['customId']>,
62
+ TrimPathLeft<TParentRoute['types']['customId']>,
63
63
  ''
64
64
  >
65
65
 
@@ -96,14 +96,14 @@ export class FileRoute<
96
96
  ? AnyPathParams
97
97
  : Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,
98
98
  TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<
99
- TParentRoute['__types']['allParams'],
99
+ TParentRoute['types']['allParams'],
100
100
  TParams
101
101
  >,
102
- TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],
103
- TAllParentContext extends RouteConstraints['TId'] = TParentRoute['__types']['context'],
102
+ TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'],
103
+ TAllParentContext extends RouteConstraints['TId'] = TParentRoute['types']['context'],
104
104
  TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
105
105
  TContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<
106
- TParentRoute['__types']['context'],
106
+ TParentRoute['types']['context'],
107
107
  TRouteContext
108
108
  >,
109
109
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
package/src/link.ts CHANGED
@@ -152,17 +152,17 @@ export type SearchParamOptions<
152
152
  TFromSchema = UnionToIntersection<
153
153
  FullSearchSchema<TRouteTree> & RouteByPath<TRouteTree, TFrom> extends never
154
154
  ? {}
155
- : RouteByPath<TRouteTree, TFrom>['__types']['fullSearchSchema']
155
+ : RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']
156
156
  >,
157
157
  // Find the schema for the new path, and make optional any keys
158
158
  // that are already defined in the current schema
159
159
  TToSchema = Partial<
160
- RouteByPath<TRouteTree, TFrom>['__types']['fullSearchSchema']
160
+ RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']
161
161
  > &
162
162
  Omit<
163
- RouteByPath<TRouteTree, TTo>['__types']['fullSearchSchema'],
163
+ RouteByPath<TRouteTree, TTo>['types']['fullSearchSchema'],
164
164
  keyof PickRequired<
165
- RouteByPath<TRouteTree, TFrom>['__types']['fullSearchSchema']
165
+ RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']
166
166
  >
167
167
  >,
168
168
  TFromFullSchema = UnionToIntersection<
@@ -188,14 +188,14 @@ export type PathParamOptions<
188
188
  TFromSchema = UnionToIntersection<
189
189
  RouteByPath<TRouteTree, TFrom> extends never
190
190
  ? {}
191
- : RouteByPath<TRouteTree, TFrom>['__types']['allParams']
191
+ : RouteByPath<TRouteTree, TFrom>['types']['allParams']
192
192
  >,
193
193
  // Find the schema for the new path, and make optional any keys
194
194
  // that are already defined in the current schema
195
- TToSchema = Partial<RouteByPath<TRouteTree, TFrom>['__types']['allParams']> &
195
+ TToSchema = Partial<RouteByPath<TRouteTree, TFrom>['types']['allParams']> &
196
196
  Omit<
197
- RouteByPath<TRouteTree, TTo>['__types']['allParams'],
198
- keyof PickRequired<RouteByPath<TRouteTree, TFrom>['__types']['allParams']>
197
+ RouteByPath<TRouteTree, TTo>['types']['allParams'],
198
+ keyof PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>
199
199
  >,
200
200
  TFromFullParams = UnionToIntersection<AllParams<TRouteTree> & TFromSchema>,
201
201
  TToFullParams = UnionToIntersection<AllParams<TRouteTree> & TToSchema>,
package/src/route.ts CHANGED
@@ -81,12 +81,12 @@ export type ComponentFromRoute<TRoute> = RegisteredRouteComponent<
81
81
  >
82
82
 
83
83
  export type RouteLoaderFromRoute<TRoute extends AnyRoute> = LoaderFn<
84
- TRoute['__types']['loader'],
85
- TRoute['__types']['searchSchema'],
86
- TRoute['__types']['fullSearchSchema'],
87
- TRoute['__types']['allParams'],
88
- TRoute['__types']['routeContext'],
89
- TRoute['__types']['context']
84
+ TRoute['types']['loader'],
85
+ TRoute['types']['searchSchema'],
86
+ TRoute['types']['fullSearchSchema'],
87
+ TRoute['types']['allParams'],
88
+ TRoute['types']['routeContext'],
89
+ TRoute['types']['context']
90
90
  >
91
91
 
92
92
  export type RouteProps<
@@ -443,13 +443,13 @@ export type ResolveId<
443
443
 
444
444
  export type InferFullSearchSchema<TRoute> = TRoute extends {
445
445
  isRoot: true
446
- __types: {
446
+ types: {
447
447
  searchSchema: infer TSearchSchema
448
448
  }
449
449
  }
450
450
  ? TSearchSchema
451
451
  : TRoute extends {
452
- __types: {
452
+ types: {
453
453
  fullSearchSchema: infer TFullSearchSchema
454
454
  }
455
455
  }
@@ -542,21 +542,21 @@ export class Route<
542
542
  string
543
543
  >,
544
544
  TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<
545
- TParentRoute['__types']['allParams'],
545
+ TParentRoute['types']['allParams'],
546
546
  TParams
547
547
  >,
548
- TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],
549
- TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'],
548
+ TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'],
549
+ TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'],
550
550
  TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
551
551
  TAllContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<
552
- TParentRoute['__types']['context'],
552
+ TParentRoute['types']['context'],
553
553
  TRouteContext
554
554
  >,
555
555
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
556
556
  TChildren extends RouteConstraints['TChildren'] = unknown,
557
557
  TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
558
558
  > {
559
- __types!: {
559
+ types!: {
560
560
  parentRoute: TParentRoute
561
561
  path: TPath
562
562
  to: TrimPathRight<TFullPath>
package/src/routeInfo.ts CHANGED
@@ -63,9 +63,9 @@ export type RoutePaths<TRouteTree extends AnyRoute> =
63
63
  | '/'
64
64
 
65
65
  export type FullSearchSchema<TRouteTree extends AnyRoute> = MergeUnion<
66
- ParseRoute<TRouteTree>['__types']['fullSearchSchema']
66
+ ParseRoute<TRouteTree>['types']['fullSearchSchema']
67
67
  > & {}
68
68
 
69
69
  export type AllParams<TRouteTree extends AnyRoute> = MergeUnion<
70
- ParseRoute<TRouteTree>['__types']['allParams']
70
+ ParseRoute<TRouteTree>['types']['allParams']
71
71
  >
package/src/router.ts CHANGED
@@ -114,7 +114,7 @@ export interface RouteMatch<
114
114
  key?: string
115
115
  routeId: string
116
116
  pathname: string
117
- params: TRoute['__types']['allParams']
117
+ params: TRoute['types']['allParams']
118
118
  status: 'pending' | 'success' | 'error'
119
119
  isFetching: boolean
120
120
  invalid: boolean
@@ -124,13 +124,13 @@ export interface RouteMatch<
124
124
  updatedAt: number
125
125
  invalidAt: number
126
126
  preloadInvalidAt: number
127
- loaderData: TRoute['__types']['loader']
127
+ loaderData: TRoute['types']['loader']
128
128
  loadPromise?: Promise<void>
129
129
  __resolveLoadPromise?: () => void
130
- routeContext: TRoute['__types']['routeContext']
131
- context: TRoute['__types']['context']
132
- routeSearch: TRoute['__types']['searchSchema']
133
- search: FullSearchSchema<TRouteTree> & TRoute['__types']['fullSearchSchema']
130
+ routeContext: TRoute['types']['routeContext']
131
+ context: TRoute['types']['context']
132
+ routeSearch: TRoute['types']['searchSchema']
133
+ search: FullSearchSchema<TRouteTree> & TRoute['types']['fullSearchSchema']
134
134
  fetchedAt: number
135
135
  abortController: AbortController
136
136
  }
@@ -138,12 +138,12 @@ export interface RouteMatch<
138
138
  export type AnyRouteMatch = RouteMatch<AnyRoute, AnyRoute>
139
139
 
140
140
  export type RouterContextOptions<TRouteTree extends AnyRoute> =
141
- AnyContext extends TRouteTree['__types']['routerContext']
141
+ AnyContext extends TRouteTree['types']['routerContext']
142
142
  ? {
143
- context?: TRouteTree['__types']['routerContext']
143
+ context?: TRouteTree['types']['routerContext']
144
144
  }
145
145
  : {
146
- context: TRouteTree['__types']['routerContext']
146
+ context: TRouteTree['types']['routerContext']
147
147
  }
148
148
 
149
149
  export interface RouterOptions<
@@ -172,7 +172,7 @@ export interface RouterOptions<
172
172
  basepath?: string
173
173
  createRoute?: (opts: { route: AnyRoute; router: AnyRouter }) => void
174
174
  onRouteChange?: () => void
175
- context?: TRouteTree['__types']['routerContext']
175
+ context?: TRouteTree['types']['routerContext']
176
176
  Wrap?: React.ComponentType<{
177
177
  children: React.ReactNode
178
178
  dehydratedState?: TDehydrated
@@ -292,10 +292,6 @@ export class Router<
292
292
 
293
293
  const next = this.__store.state
294
294
 
295
- console.log(
296
- Object.values(next.matchesById).find((d) => d.status === 'error'),
297
- )
298
-
299
295
  const matchesByIdChanged = prev.matchesById !== next.matchesById
300
296
  let matchesChanged
301
297
  let pendingMatchesChanged
@@ -869,7 +865,6 @@ export class Router<
869
865
  }
870
866
  }
871
867
 
872
- console.log('set error')
873
868
  this.setRouteMatch(match.id, (s) => ({
874
869
  ...s,
875
870
  error: err,
@@ -936,19 +931,18 @@ export class Router<
936
931
  : undefined
937
932
  }
938
933
 
939
- const load = async () => {
940
- let latestPromise
941
-
942
- const handleError = (err: any) => {
943
- if (isRedirect(err)) {
944
- if (!opts?.preload) {
945
- this.navigate(err as any)
946
- }
947
- return true
934
+ const handleIfRedirect = (err: any) => {
935
+ if (isRedirect(err)) {
936
+ if (!opts?.preload) {
937
+ this.navigate(err as any)
948
938
  }
949
-
950
- return false
939
+ return true
951
940
  }
941
+ return false
942
+ }
943
+
944
+ const load = async () => {
945
+ let latestPromise
952
946
 
953
947
  try {
954
948
  const componentsPromise = Promise.all(
@@ -975,44 +969,58 @@ export class Router<
975
969
 
976
970
  this.setRouteMatchData(match.id, () => loader, opts)
977
971
  } catch (loaderError) {
972
+ let latestError = loaderError
978
973
  if ((latestPromise = checkLatest())) return await latestPromise
979
- handleError(loaderError)
980
-
981
- let error = loaderError
974
+ if (handleIfRedirect(loaderError)) return
975
+
976
+ if (route.options.onLoadError) {
977
+ try {
978
+ route.options.onLoadError(loaderError)
979
+ } catch (onLoadError) {
980
+ latestError = onLoadError
981
+ if (handleIfRedirect(onLoadError)) return
982
+ }
983
+ }
982
984
 
983
- try {
984
- if (route.options.onLoadError) {
985
- route.options.onLoadError?.(loaderError)
986
- } else {
987
- route.options.onError?.(loaderError)
985
+ if (
986
+ (!route.options.onLoadError || latestError !== loaderError) &&
987
+ route.options.onError
988
+ ) {
989
+ try {
990
+ route.options.onError(latestError)
991
+ } catch (onErrorError) {
992
+ if (handleIfRedirect(onErrorError)) return
988
993
  }
989
- } catch (errorHandlerErr) {
990
- error = errorHandlerErr
991
- handleError(error)
992
994
  }
993
995
 
994
- console.log('set error')
995
996
  this.setRouteMatch(match.id, (s) => ({
996
997
  ...s,
997
- error: error,
998
+ error: loaderError,
998
999
  status: 'error',
999
1000
  isFetching: false,
1000
1001
  updatedAt: Date.now(),
1001
1002
  }))
1002
- console.log(this.getRouteMatch(match.id)?.status)
1003
1003
  }
1004
1004
  }
1005
1005
 
1006
- const loadPromise = load()
1006
+ let loadPromise: Promise<void> | undefined
1007
1007
 
1008
- this.setRouteMatch(match.id, (s) => ({
1009
- ...s,
1010
- status: s.status !== 'success' ? 'pending' : s.status,
1011
- isFetching: true,
1012
- loadPromise,
1013
- fetchedAt,
1014
- invalid: false,
1015
- }))
1008
+ this.__store.batch(() => {
1009
+ this.setRouteMatch(match.id, (s) => ({
1010
+ ...s,
1011
+ // status: s.status !== 'success' ? 'pending' : s.status,
1012
+ isFetching: true,
1013
+ fetchedAt,
1014
+ invalid: false,
1015
+ }))
1016
+
1017
+ loadPromise = load()
1018
+
1019
+ this.setRouteMatch(match.id, (s) => ({
1020
+ ...s,
1021
+ loadPromise,
1022
+ }))
1023
+ })
1016
1024
 
1017
1025
  await loadPromise
1018
1026
  })(),
@@ -1081,7 +1089,7 @@ export class Router<
1081
1089
  >(
1082
1090
  location: ToOptions<TRouteTree, TFrom, TTo>,
1083
1091
  opts?: MatchRouteOptions,
1084
- ): false | RouteById<TRouteTree, TResolved>['__types']['allParams'] => {
1092
+ ): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {
1085
1093
  location = {
1086
1094
  ...location,
1087
1095
  to: location.to
@@ -1655,7 +1663,6 @@ export class Router<
1655
1663
  this.options.defaultMaxAge ??
1656
1664
  Infinity)
1657
1665
 
1658
- console.log('set success')
1659
1666
  this.setRouteMatch(id, (s) => ({
1660
1667
  ...s,
1661
1668
  error: undefined,