@tanstack/router-core 0.0.1-beta.167 → 0.0.1-beta.169

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.167",
4
+ "version": "0.0.1-beta.169",
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.167"
46
+ "@tanstack/react-store": "0.0.1-beta.169"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rollup --config rollup.config.js",
package/src/fileRoute.ts CHANGED
@@ -2,7 +2,6 @@ import { ParsePathParams } from './link'
2
2
  import {
3
3
  AnyRoute,
4
4
  ResolveFullPath,
5
- AnySearchSchema,
6
5
  ResolveFullSearchSchema,
7
6
  MergeParamsFromParent,
8
7
  RouteContext,
package/src/link.ts CHANGED
@@ -124,6 +124,7 @@ export type NavigateOptions<
124
124
  > = ToOptions<TRouteTree, TFrom, TTo> & {
125
125
  // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
126
126
  replace?: boolean
127
+ resetScroll?: boolean
127
128
  }
128
129
 
129
130
  export type ToOptions<
package/src/route.ts CHANGED
@@ -11,11 +11,30 @@ export type AnySearchSchema = {}
11
11
  export type AnyContext = {}
12
12
  export interface RouteMeta {}
13
13
  export interface RouteContext {}
14
- export interface RegisterRouteComponent<TProps> {
14
+ export interface RegisterRouteComponent<
15
+ TLoader = unknown,
16
+ TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
17
+ TAllParams extends AnyPathParams = AnyPathParams,
18
+ TRouteContext extends AnyContext = AnyContext,
19
+ TAllContext extends AnyContext = AnyContext,
20
+ > {
15
21
  // RouteComponent: unknown // This is registered by the framework
16
22
  }
17
- export interface RegisterRouteErrorComponent<TProps> {
18
- // RouteErrorComponent: unknown // This is registered by the framework
23
+ export interface RegisterErrorRouteComponent<
24
+ TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
25
+ TAllParams extends AnyPathParams = AnyPathParams,
26
+ TRouteContext extends AnyContext = AnyContext,
27
+ TAllContext extends AnyContext = AnyContext,
28
+ > {
29
+ // ErrorRouteComponent: unknown // This is registered by the framework
30
+ }
31
+ export interface RegisterPendingRouteComponent<
32
+ TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
33
+ TAllParams extends AnyPathParams = AnyPathParams,
34
+ TRouteContext extends AnyContext = AnyContext,
35
+ TAllContext extends AnyContext = AnyContext,
36
+ > {
37
+ // PendingRouteComponent: unknown // This is registered by the framework
19
38
  }
20
39
  export interface RegisterRouteProps<
21
40
  TLoader = unknown,
@@ -44,19 +63,55 @@ export interface RegisterPendingRouteProps<
44
63
  // PendingRouteProps: unknown // This is registered by the framework
45
64
  }
46
65
 
47
- export type RegisteredRouteComponent<TProps> =
48
- RegisterRouteComponent<TProps> extends {
49
- RouteComponent: infer T
50
- }
51
- ? T
52
- : (props: TProps) => unknown
66
+ export type RegisteredRouteComponent<
67
+ TLoader = unknown,
68
+ TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
69
+ TAllParams extends AnyPathParams = AnyPathParams,
70
+ TRouteContext extends AnyContext = AnyContext,
71
+ TAllContext extends AnyContext = AnyContext,
72
+ > = RegisterRouteComponent<
73
+ TLoader,
74
+ TFullSearchSchema,
75
+ TAllParams,
76
+ TRouteContext,
77
+ TAllContext
78
+ > extends {
79
+ RouteComponent: infer T
80
+ }
81
+ ? T
82
+ : () => unknown
53
83
 
54
- export type RegisteredRouteErrorComponent<TProps> =
55
- RegisterRouteErrorComponent<TProps> extends {
56
- RouteErrorComponent: infer T
57
- }
58
- ? T
59
- : (props: TProps) => unknown
84
+ export type RegisteredErrorRouteComponent<
85
+ TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
86
+ TAllParams extends AnyPathParams = AnyPathParams,
87
+ TRouteContext extends AnyContext = AnyContext,
88
+ TAllContext extends AnyContext = AnyContext,
89
+ > = RegisterErrorRouteComponent<
90
+ TFullSearchSchema,
91
+ TAllParams,
92
+ TRouteContext,
93
+ TAllContext
94
+ > extends {
95
+ ErrorRouteComponent: infer T
96
+ }
97
+ ? T
98
+ : () => unknown
99
+
100
+ export type RegisteredPendingRouteComponent<
101
+ TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
102
+ TAllParams extends AnyPathParams = AnyPathParams,
103
+ TRouteContext extends AnyContext = AnyContext,
104
+ TAllContext extends AnyContext = AnyContext,
105
+ > = RegisterPendingRouteComponent<
106
+ TFullSearchSchema,
107
+ TAllParams,
108
+ TRouteContext,
109
+ TAllContext
110
+ > extends {
111
+ PendingRouteComponent: infer T
112
+ }
113
+ ? T
114
+ : () => unknown
60
115
 
61
116
  export type RegisteredRouteProps<
62
117
  TLoader = unknown,
@@ -74,7 +129,7 @@ export type RegisteredRouteProps<
74
129
  RouteProps: infer T
75
130
  }
76
131
  ? T
77
- : (props: {}) => unknown
132
+ : {}
78
133
 
79
134
  export type RegisteredErrorRouteProps<
80
135
  TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
@@ -90,7 +145,7 @@ export type RegisteredErrorRouteProps<
90
145
  ErrorRouteProps: infer T
91
146
  }
92
147
  ? T
93
- : (props: {}) => unknown
148
+ : {}
94
149
 
95
150
  export type RegisteredPendingRouteProps<
96
151
  TFullSearchSchema extends AnySearchSchema = AnySearchSchema,
@@ -106,7 +161,7 @@ export type RegisteredPendingRouteProps<
106
161
  PendingRouteProps: infer T
107
162
  }
108
163
  ? T
109
- : (props: {}) => unknown
164
+ : {}
110
165
 
111
166
  export type PreloadableObj = { preload?: () => Promise<void> }
112
167
 
@@ -325,31 +380,25 @@ export type UpdatableRouteOptions<
325
380
  wrapInSuspense?: boolean
326
381
  // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
327
382
  component?: RegisteredRouteComponent<
328
- RegisteredRouteProps<
329
- TLoader,
330
- TFullSearchSchema,
331
- TAllParams,
332
- TRouteContext,
333
- TAllContext
334
- >
383
+ TLoader,
384
+ TFullSearchSchema,
385
+ TAllParams,
386
+ TRouteContext,
387
+ TAllContext
335
388
  >
336
389
  // The content to be rendered when the route encounters an error
337
- errorComponent?: RegisteredRouteErrorComponent<
338
- RegisteredErrorRouteProps<
339
- TFullSearchSchema,
340
- TAllParams,
341
- TRouteContext,
342
- TAllContext
343
- >
390
+ errorComponent?: RegisteredErrorRouteComponent<
391
+ TFullSearchSchema,
392
+ TAllParams,
393
+ TRouteContext,
394
+ TAllContext
344
395
  > //
345
396
  // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
346
- pendingComponent?: RegisteredRouteComponent<
347
- RegisteredPendingRouteProps<
348
- TFullSearchSchema,
349
- TAllParams,
350
- TRouteContext,
351
- TAllContext
352
- >
397
+ pendingComponent?: RegisteredPendingRouteComponent<
398
+ TFullSearchSchema,
399
+ TAllParams,
400
+ TRouteContext,
401
+ TAllContext
353
402
  >
354
403
  // Filter functions that can manipulate search params *before* they are passed to links and navigate
355
404
  // calls that match this route.
package/src/router.ts CHANGED
@@ -27,9 +27,8 @@ import {
27
27
  AnyContext,
28
28
  AnyPathParams,
29
29
  RegisteredRouteComponent,
30
- RegisteredRouteErrorComponent,
31
- RegisteredRouteProps,
32
- RegisteredErrorRouteProps,
30
+ RegisteredErrorRouteComponent,
31
+ RegisteredPendingRouteComponent,
33
32
  } from './route'
34
33
  import {
35
34
  RoutesById,
@@ -157,30 +156,23 @@ export interface RouterOptions<
157
156
  defaultPreload?: false | 'intent'
158
157
  defaultPreloadDelay?: number
159
158
  defaultComponent?: RegisteredRouteComponent<
160
- RegisteredRouteProps<
161
- unknown,
162
- AnySearchSchema,
163
- AnyPathParams,
164
- AnyContext,
165
- AnyContext
166
- >
159
+ unknown,
160
+ AnySearchSchema,
161
+ AnyPathParams,
162
+ AnyContext,
163
+ AnyContext
167
164
  >
168
- defaultErrorComponent?: RegisteredRouteErrorComponent<
169
- RegisteredErrorRouteProps<
170
- AnySearchSchema,
171
- AnyPathParams,
172
- AnyContext,
173
- AnyContext
174
- >
165
+ defaultErrorComponent?: RegisteredErrorRouteComponent<
166
+ AnySearchSchema,
167
+ AnyPathParams,
168
+ AnyContext,
169
+ AnyContext
175
170
  >
176
- defaultPendingComponent?: RegisteredRouteComponent<
177
- RegisteredRouteProps<
178
- unknown,
179
- AnySearchSchema,
180
- AnyPathParams,
181
- AnyContext,
182
- AnyContext
183
- >
171
+ defaultPendingComponent?: RegisteredPendingRouteComponent<
172
+ AnySearchSchema,
173
+ AnyPathParams,
174
+ AnyContext,
175
+ AnyContext
184
176
  >
185
177
  defaultMaxAge?: number
186
178
  defaultGcMaxAge?: number
@@ -326,6 +318,7 @@ export class Router<
326
318
  __store: Store<RouterState<TRouteTree>>
327
319
  state: RouterState<TRouteTree>
328
320
  dehydratedData?: TDehydrated
321
+ resetNextScroll = false
329
322
 
330
323
  constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>) {
331
324
  this.options = {
@@ -803,8 +796,8 @@ export class Router<
803
796
  params: routeParams,
804
797
  pathname: joinPaths([this.basepath, interpolatedPath]),
805
798
  updatedAt: Date.now(),
806
- invalidAt: 9999999999999,
807
- preloadInvalidAt: 9999999999999,
799
+ invalidAt: Infinity,
800
+ preloadInvalidAt: Infinity,
808
801
  routeSearch: {},
809
802
  search: {} as any,
810
803
  status: hasLoaders ? 'pending' : 'success',
@@ -912,8 +905,6 @@ export class Router<
912
905
  maxAge?: number
913
906
  },
914
907
  ) => {
915
- this.cleanMatches()
916
-
917
908
  if (!opts?.preload) {
918
909
  resolvedMatches.forEach((match) => {
919
910
  // Update each match with its latest route data
@@ -927,10 +918,13 @@ export class Router<
927
918
  paramsError: match.paramsError,
928
919
  searchError: match.searchError,
929
920
  params: match.params,
921
+ preloadInvalidAt: 0,
930
922
  }))
931
923
  })
932
924
  }
933
925
 
926
+ this.cleanMatches()
927
+
934
928
  let firstBadMatchIndex: number | undefined
935
929
 
936
930
  // Check each match middleware to see if the route can be accessed
@@ -1105,6 +1099,8 @@ export class Router<
1105
1099
  })
1106
1100
 
1107
1101
  await Promise.all(matchPromises)
1102
+
1103
+ this.cleanMatches()
1108
1104
  }
1109
1105
 
1110
1106
  reload = () => {
@@ -1129,6 +1125,7 @@ export class Router<
1129
1125
  hash,
1130
1126
  replace,
1131
1127
  params,
1128
+ resetScroll,
1132
1129
  }: NavigateOptions<TRouteTree, TFrom, TTo>) => {
1133
1130
  // If this link simply reloads the current route,
1134
1131
  // make sure it has a new key so it will trigger a data refresh
@@ -1156,6 +1153,7 @@ export class Router<
1156
1153
  hash,
1157
1154
  replace,
1158
1155
  params,
1156
+ resetScroll,
1159
1157
  })
1160
1158
  }
1161
1159
 
@@ -1219,6 +1217,7 @@ export class Router<
1219
1217
  preloadDelay: userPreloadDelay,
1220
1218
  disabled,
1221
1219
  state,
1220
+ resetScroll,
1222
1221
  }: LinkOptions<TRouteTree, TFrom, TTo>): LinkInfo => {
1223
1222
  // If this link simply reloads the current route,
1224
1223
  // make sure it has a new key so it will trigger a data refresh
@@ -1242,6 +1241,7 @@ export class Router<
1242
1241
  hash,
1243
1242
  replace,
1244
1243
  state,
1244
+ resetScroll,
1245
1245
  }
1246
1246
 
1247
1247
  const next = this.buildNext(nextOpts)
@@ -1681,7 +1681,7 @@ export class Router<
1681
1681
  }
1682
1682
 
1683
1683
  #commitLocation = async (
1684
- location: BuildNextOptions & { replace?: boolean },
1684
+ location: BuildNextOptions & { replace?: boolean; resetScroll?: boolean },
1685
1685
  ) => {
1686
1686
  const next = this.buildNext(location)
1687
1687
  const id = '' + Date.now() + Math.random()
@@ -1709,6 +1709,9 @@ export class Router<
1709
1709
  ...next.state,
1710
1710
  })
1711
1711
 
1712
+ this.resetNextScroll = location.resetScroll ?? true
1713
+ console.log('resetScroll', this.resetNextScroll)
1714
+
1712
1715
  return this.latestLoadPromise
1713
1716
  }
1714
1717
 
@@ -1766,7 +1769,7 @@ export class Router<
1766
1769
  (opts?.maxAge ??
1767
1770
  route.options.maxAge ??
1768
1771
  this.options.defaultMaxAge ??
1769
- 9999999999999)
1772
+ Infinity)
1770
1773
 
1771
1774
  this.setRouteMatch(id, (s) => ({
1772
1775
  ...s,
@@ -1778,9 +1781,6 @@ export class Router<
1778
1781
  preloadInvalidAt,
1779
1782
  invalidAt,
1780
1783
  }))
1781
-
1782
- if (this.state.matches.find((d) => d.id === id)) {
1783
- }
1784
1784
  }
1785
1785
 
1786
1786
  invalidate = async (opts?: {
@@ -144,6 +144,10 @@ export function restoreScrollPositions(
144
144
  opts?: ScrollRestorationOptions,
145
145
  ) {
146
146
  if (pathDidChange) {
147
+ if (!router.resetNextScroll) {
148
+ return
149
+ }
150
+
147
151
  const getKey = opts?.getKey || defaultGetKey
148
152
 
149
153
  pathDidChange = false