@tanstack/solid-router 1.132.0-alpha.1 → 1.132.0-alpha.13

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.
Files changed (80) hide show
  1. package/dist/cjs/HeadContent.cjs +9 -6
  2. package/dist/cjs/HeadContent.cjs.map +1 -1
  3. package/dist/cjs/Match.cjs +30 -27
  4. package/dist/cjs/Match.cjs.map +1 -1
  5. package/dist/cjs/ScriptOnce.cjs +2 -2
  6. package/dist/cjs/ScriptOnce.cjs.map +1 -1
  7. package/dist/cjs/fileRoute.cjs.map +1 -1
  8. package/dist/cjs/fileRoute.d.cts +2 -2
  9. package/dist/cjs/index.cjs +2 -10
  10. package/dist/cjs/index.cjs.map +1 -1
  11. package/dist/cjs/index.d.cts +2 -2
  12. package/dist/cjs/link.cjs +7 -9
  13. package/dist/cjs/link.cjs.map +1 -1
  14. package/dist/cjs/route.cjs.map +1 -1
  15. package/dist/cjs/route.d.cts +12 -12
  16. package/dist/cjs/router.cjs +1 -1
  17. package/dist/cjs/router.cjs.map +1 -1
  18. package/dist/cjs/scroll-restoration.cjs +11 -3
  19. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  20. package/dist/cjs/useBlocker.cjs +1 -1
  21. package/dist/cjs/useBlocker.cjs.map +1 -1
  22. package/dist/cjs/useNavigate.cjs +3 -11
  23. package/dist/cjs/useNavigate.cjs.map +1 -1
  24. package/dist/esm/HeadContent.js +9 -6
  25. package/dist/esm/HeadContent.js.map +1 -1
  26. package/dist/esm/Match.js +31 -28
  27. package/dist/esm/Match.js.map +1 -1
  28. package/dist/esm/ScriptOnce.js +2 -2
  29. package/dist/esm/ScriptOnce.js.map +1 -1
  30. package/dist/esm/fileRoute.d.ts +2 -2
  31. package/dist/esm/fileRoute.js.map +1 -1
  32. package/dist/esm/index.d.ts +2 -2
  33. package/dist/esm/index.js +2 -4
  34. package/dist/esm/link.js +7 -9
  35. package/dist/esm/link.js.map +1 -1
  36. package/dist/esm/route.d.ts +12 -12
  37. package/dist/esm/route.js.map +1 -1
  38. package/dist/esm/router.js +1 -1
  39. package/dist/esm/router.js.map +1 -1
  40. package/dist/esm/scroll-restoration.js +11 -3
  41. package/dist/esm/scroll-restoration.js.map +1 -1
  42. package/dist/esm/useBlocker.js +1 -1
  43. package/dist/esm/useBlocker.js.map +1 -1
  44. package/dist/esm/useNavigate.js +3 -11
  45. package/dist/esm/useNavigate.js.map +1 -1
  46. package/dist/source/HeadContent.jsx +9 -7
  47. package/dist/source/HeadContent.jsx.map +1 -1
  48. package/dist/source/Match.jsx +33 -34
  49. package/dist/source/Match.jsx.map +1 -1
  50. package/dist/source/ScriptOnce.jsx +1 -1
  51. package/dist/source/ScriptOnce.jsx.map +1 -1
  52. package/dist/source/fileRoute.d.ts +2 -2
  53. package/dist/source/fileRoute.js.map +1 -1
  54. package/dist/source/index.d.ts +2 -2
  55. package/dist/source/index.jsx +1 -1
  56. package/dist/source/index.jsx.map +1 -1
  57. package/dist/source/link.jsx +7 -11
  58. package/dist/source/link.jsx.map +1 -1
  59. package/dist/source/route.d.ts +12 -12
  60. package/dist/source/route.jsx.map +1 -1
  61. package/dist/source/router.js +1 -1
  62. package/dist/source/router.js.map +1 -1
  63. package/dist/source/scroll-restoration.jsx +11 -3
  64. package/dist/source/scroll-restoration.jsx.map +1 -1
  65. package/dist/source/useBlocker.jsx +1 -1
  66. package/dist/source/useBlocker.jsx.map +1 -1
  67. package/dist/source/useNavigate.jsx +3 -10
  68. package/dist/source/useNavigate.jsx.map +1 -1
  69. package/package.json +2 -2
  70. package/src/HeadContent.tsx +9 -6
  71. package/src/Match.tsx +35 -37
  72. package/src/ScriptOnce.tsx +2 -2
  73. package/src/fileRoute.ts +10 -2
  74. package/src/index.tsx +3 -3
  75. package/src/link.tsx +7 -11
  76. package/src/route.tsx +76 -18
  77. package/src/router.ts +1 -1
  78. package/src/scroll-restoration.tsx +11 -4
  79. package/src/useBlocker.tsx +1 -1
  80. package/src/useNavigate.tsx +3 -12
@@ -1 +1 @@
1
- {"version":3,"file":"useNavigate.jsx","sourceRoot":"","sources":["../../src/useNavigate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AASrC,MAAM,UAAU,WAAW,CAGzB,YAED;IACC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,CAAA;IAEvC,MAAM,UAAU,GAAG,QAAQ,CAAC;QAC1B,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK;KAC/B,CAAC,CAAA;IAEF,OAAO,CAAC,CAAC,OAAwB,EAAE,EAAE;QACnC,OAAO,QAAQ,CAAC;YACd,GAAG,OAAO;YACV,IAAI,EACF,OAAO,CAAC,IAAI;gBACZ,YAAY,EAAE,IAAI;gBAClB,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAE,CAAC,QAAQ;SACxC,CAAC,CAAA;IACJ,CAAC,CAAoC,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,QAAQ,CAMtB,KAA+D;IAC/D,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAA;IAEhC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC;YACP,GAAG,KAAK;SACT,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACb,CAAC"}
1
+ {"version":3,"file":"useNavigate.jsx","sourceRoot":"","sources":["../../src/useNavigate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AASvC,MAAM,UAAU,WAAW,CAGzB,YAED;IACC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAE1B,OAAO,CAAC,CAAC,OAAwB,EAAE,EAAE;QACnC,OAAO,MAAM,CAAC,QAAQ,CAAC;YACrB,GAAG,OAAO;YACV,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,YAAY,EAAE,IAAI;SACzC,CAAC,CAAA;IACJ,CAAC,CAAoC,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,QAAQ,CAMtB,KAA+D;IAC/D,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAA;IAEhC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC;YACP,GAAG,KAAK;SACT,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-router",
3
- "version": "1.132.0-alpha.1",
3
+ "version": "1.132.0-alpha.13",
4
4
  "description": "Modern and scalable routing for Solid applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -89,7 +89,7 @@
89
89
  "tiny-invariant": "^1.3.3",
90
90
  "tiny-warning": "^1.0.3",
91
91
  "@tanstack/history": "1.132.0-alpha.1",
92
- "@tanstack/router-core": "1.132.0-alpha.1"
92
+ "@tanstack/router-core": "1.132.0-alpha.12"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@solidjs/testing-library": "^0.8.10",
@@ -18,9 +18,12 @@ export const useTags = () => {
18
18
  const resultMeta: Array<RouterManagedTag> = []
19
19
  const metaByAttribute: Record<string, true> = {}
20
20
  let title: RouterManagedTag | undefined
21
- ;[...routeMeta()].reverse().forEach((metas) => {
22
- ;[...metas].reverse().forEach((m) => {
23
- if (!m) return
21
+ const routeMetasArray = routeMeta()
22
+ for (let i = routeMetasArray.length - 1; i >= 0; i--) {
23
+ const metas = routeMetasArray[i]!
24
+ for (let j = metas.length - 1; j >= 0; j--) {
25
+ const m = metas[j]
26
+ if (!m) continue
24
27
 
25
28
  if (m.title) {
26
29
  if (!title) {
@@ -33,7 +36,7 @@ export const useTags = () => {
33
36
  const attribute = m.name ?? m.property
34
37
  if (attribute) {
35
38
  if (metaByAttribute[attribute]) {
36
- return
39
+ continue
37
40
  } else {
38
41
  metaByAttribute[attribute] = true
39
42
  }
@@ -46,8 +49,8 @@ export const useTags = () => {
46
49
  },
47
50
  })
48
51
  }
49
- })
50
- })
52
+ }
53
+ }
51
54
 
52
55
  if (title) {
53
56
  resultMeta.push(title)
package/src/Match.tsx CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  getLocationChangeInfo,
7
7
  isNotFound,
8
8
  isRedirect,
9
- pick,
10
9
  rootRouteId,
11
10
  } from '@tanstack/router-core'
12
11
  import { Dynamic } from 'solid-js/web'
@@ -30,7 +29,11 @@ export const Match = (props: { matchId: string }) => {
30
29
  match,
31
30
  `Could not find match for matchId "${props.matchId}". Please file an issue!`,
32
31
  )
33
- return pick(match, ['routeId', 'ssr', '_displayPending'])
32
+ return {
33
+ routeId: match.routeId,
34
+ ssr: match.ssr,
35
+ _displayPending: match._displayPending,
36
+ }
34
37
  },
35
38
  })
36
39
 
@@ -182,8 +185,7 @@ export const MatchInner = (props: { matchId: string }): any => {
182
185
 
183
186
  const matchState = useRouterState({
184
187
  select: (s) => {
185
- const matchIndex = s.matches.findIndex((d) => d.id === props.matchId)
186
- const match = s.matches[matchIndex]!
188
+ const match = s.matches.find((d) => d.id === props.matchId)!
187
189
  const routeId = match.routeId as string
188
190
 
189
191
  const remountFn =
@@ -200,13 +202,13 @@ export const MatchInner = (props: { matchId: string }): any => {
200
202
  return {
201
203
  key,
202
204
  routeId,
203
- match: pick(match, [
204
- 'id',
205
- 'status',
206
- 'error',
207
- '_forcePending',
208
- '_displayPending',
209
- ]),
205
+ match: {
206
+ id: match.id,
207
+ status: match.status,
208
+ error: match.error,
209
+ _forcePending: match._forcePending,
210
+ _displayPending: match._displayPending,
211
+ },
210
212
  }
211
213
  },
212
214
  })
@@ -218,8 +220,9 @@ export const MatchInner = (props: { matchId: string }): any => {
218
220
  const out = () => {
219
221
  const Comp = route().options.component ?? router.options.defaultComponent
220
222
  if (Comp) {
223
+ const key = matchState().key ?? matchState().match.id
221
224
  return (
222
- <Solid.Show when={matchState().match.id} keyed>
225
+ <Solid.Show when={key} keyed>
223
226
  <Comp />
224
227
  </Solid.Show>
225
228
  )
@@ -232,7 +235,8 @@ export const MatchInner = (props: { matchId: string }): any => {
232
235
  <Solid.Match when={match()._displayPending}>
233
236
  {(_) => {
234
237
  const [displayPendingResult] = Solid.createResource(
235
- () => router.getMatch(match().id)?.displayPendingPromise,
238
+ () =>
239
+ router.getMatch(match().id)?._nonReactive.displayPendingPromise,
236
240
  )
237
241
 
238
242
  return <>{displayPendingResult()}</>
@@ -241,7 +245,7 @@ export const MatchInner = (props: { matchId: string }): any => {
241
245
  <Solid.Match when={match()._forcePending}>
242
246
  {(_) => {
243
247
  const [minPendingResult] = Solid.createResource(
244
- () => router.getMatch(match().id)?.minPendingPromise,
248
+ () => router.getMatch(match().id)?._nonReactive.minPendingPromise,
245
249
  )
246
250
 
247
251
  return <>{minPendingResult()}</>
@@ -252,33 +256,27 @@ export const MatchInner = (props: { matchId: string }): any => {
252
256
  const pendingMinMs =
253
257
  route().options.pendingMinMs ?? router.options.defaultPendingMinMs
254
258
 
255
- if (pendingMinMs && !router.getMatch(match().id)?.minPendingPromise) {
256
- // Create a promise that will resolve after the minPendingMs
257
- if (!router.isServer) {
258
- const minPendingPromise = createControlledPromise<void>()
259
-
260
- Promise.resolve().then(() => {
261
- router.updateMatch(match().id, (prev) => ({
262
- ...prev,
263
- minPendingPromise,
264
- }))
265
- })
266
-
267
- setTimeout(() => {
268
- minPendingPromise.resolve()
269
-
270
- // We've handled the minPendingPromise, so we can delete it
271
- router.updateMatch(match().id, (prev) => ({
272
- ...prev,
273
- minPendingPromise: undefined,
274
- }))
275
- }, pendingMinMs)
259
+ if (pendingMinMs) {
260
+ const routerMatch = router.getMatch(match().id)
261
+ if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {
262
+ // Create a promise that will resolve after the minPendingMs
263
+ if (!router.isServer) {
264
+ const minPendingPromise = createControlledPromise<void>()
265
+
266
+ routerMatch._nonReactive.minPendingPromise = minPendingPromise
267
+
268
+ setTimeout(() => {
269
+ minPendingPromise.resolve()
270
+ // We've handled the minPendingPromise, so we can delete it
271
+ routerMatch._nonReactive.minPendingPromise = undefined
272
+ }, pendingMinMs)
273
+ }
276
274
  }
277
275
  }
278
276
 
279
277
  const [loaderResult] = Solid.createResource(async () => {
280
278
  await new Promise((r) => setTimeout(r, 0))
281
- return router.getMatch(match().id)?.loadPromise
279
+ return router.getMatch(match().id)?._nonReactive.loadPromise
282
280
  })
283
281
 
284
282
  return <>{loaderResult()}</>
@@ -297,7 +295,7 @@ export const MatchInner = (props: { matchId: string }): any => {
297
295
 
298
296
  const [loaderResult] = Solid.createResource(async () => {
299
297
  await new Promise((r) => setTimeout(r, 0))
300
- return router.getMatch(match().id)?.loadPromise
298
+ return router.getMatch(match().id)?._nonReactive.loadPromise
301
299
  })
302
300
 
303
301
  return <>{loaderResult()}</>
@@ -11,8 +11,8 @@ export function ScriptOnce({
11
11
 
12
12
  return (
13
13
  <script
14
- class="tsr-once"
15
- innerHTML={[children].filter(Boolean).join('\n')}
14
+ class="$tsr"
15
+ innerHTML={[children].filter(Boolean).join('\n') + ';$_TSR.c()'}
16
16
  />
17
17
  )
18
18
  }
package/src/fileRoute.ts CHANGED
@@ -20,6 +20,7 @@ import type {
20
20
  FileBaseRouteOptions,
21
21
  FileRoutesByPath,
22
22
  LazyRouteOptions,
23
+ Register,
23
24
  RegisteredRouter,
24
25
  ResolveParams,
25
26
  Route,
@@ -76,6 +77,7 @@ export class FileRoute<
76
77
  }
77
78
 
78
79
  createRoute = <
80
+ TRegister extends Register = Register,
79
81
  TSearchValidator = undefined,
80
82
  TParams = ResolveParams<TPath>,
81
83
  TRouteContextFn = AnyContext,
@@ -83,8 +85,10 @@ export class FileRoute<
83
85
  TLoaderDeps extends Record<string, any> = {},
84
86
  TLoaderFn = undefined,
85
87
  TChildren = unknown,
88
+ TSSR = unknown,
86
89
  >(
87
90
  options?: FileBaseRouteOptions<
91
+ TRegister,
88
92
  TParentRoute,
89
93
  TId,
90
94
  TPath,
@@ -94,7 +98,9 @@ export class FileRoute<
94
98
  TLoaderFn,
95
99
  AnyContext,
96
100
  TRouteContextFn,
97
- TBeforeLoadFn
101
+ TBeforeLoadFn,
102
+ AnyContext,
103
+ TSSR
98
104
  > &
99
105
  UpdatableRouteOptions<
100
106
  TParentRoute,
@@ -109,6 +115,7 @@ export class FileRoute<
109
115
  TBeforeLoadFn
110
116
  >,
111
117
  ): Route<
118
+ TRegister,
112
119
  TParentRoute,
113
120
  TPath,
114
121
  TFullPath,
@@ -122,7 +129,8 @@ export class FileRoute<
122
129
  TLoaderDeps,
123
130
  TLoaderFn,
124
131
  TChildren,
125
- unknown
132
+ unknown,
133
+ TSSR
126
134
  > => {
127
135
  warning(
128
136
  this.silent,
package/src/index.tsx CHANGED
@@ -13,15 +13,12 @@ export {
13
13
  matchPathname,
14
14
  removeBasepath,
15
15
  matchByPath,
16
- encode,
17
- decode,
18
16
  rootRouteId,
19
17
  defaultSerializeError,
20
18
  defaultParseSearch,
21
19
  defaultStringifySearch,
22
20
  parseSearchWith,
23
21
  stringifySearchWith,
24
- pick,
25
22
  functionalUpdate,
26
23
  replaceEqualDeep,
27
24
  isPlainObject,
@@ -30,6 +27,7 @@ export {
30
27
  createControlledPromise,
31
28
  retainSearchParams,
32
29
  stripSearchParams,
30
+ createSerializationAdapter,
33
31
  } from '@tanstack/router-core'
34
32
 
35
33
  export type {
@@ -192,6 +190,8 @@ export type {
192
190
  InjectedHtmlEntry,
193
191
  CreateFileRoute,
194
192
  CreateLazyFileRoute,
193
+ AnySerializationAdapter,
194
+ SerializationAdapter,
195
195
  } from '@tanstack/router-core'
196
196
 
197
197
  export {
package/src/link.tsx CHANGED
@@ -15,7 +15,6 @@ import { useRouter } from './useRouter'
15
15
 
16
16
  import { useIntersectionObserver } from './utils'
17
17
 
18
- import { useMatch } from './useMatch'
19
18
  import type {
20
19
  AnyRouter,
21
20
  Constrain,
@@ -133,17 +132,14 @@ export function useLinkProps<
133
132
  select: (s) => s.location.searchStr,
134
133
  })
135
134
 
136
- // when `from` is not supplied, use the route of the current match as the `from` location
137
- // so relative routing works as expected
138
- const from = useMatch({
139
- strict: false,
140
- select: (match) => options.from ?? match.fullPath,
141
- })
135
+ const from = options.from
142
136
 
143
- const _options = () => ({
144
- ...options,
145
- from: from(),
146
- })
137
+ const _options = () => {
138
+ return {
139
+ ...options,
140
+ from,
141
+ }
142
+ }
147
143
 
148
144
  const next = Solid.createMemo(() => {
149
145
  currentSearch()
package/src/route.tsx CHANGED
@@ -20,6 +20,7 @@ import type {
20
20
  ErrorComponentProps,
21
21
  NotFoundError,
22
22
  NotFoundRouteProps,
23
+ Register,
23
24
  RegisteredRouter,
24
25
  ResolveFullPath,
25
26
  ResolveId,
@@ -49,7 +50,7 @@ import type { LinkComponentRoute } from './link'
49
50
  declare module '@tanstack/router-core' {
50
51
  export interface UpdatableRouteOptionsExtensions {
51
52
  component?: RouteComponent
52
- errorComponent?: false | null | ErrorRouteComponent
53
+ errorComponent?: false | null | undefined | ErrorRouteComponent
53
54
  notFoundComponent?: NotFoundRouteComponent
54
55
  pendingComponent?: RouteComponent
55
56
  }
@@ -152,6 +153,7 @@ export class RouteApi<
152
153
  }
153
154
 
154
155
  export class Route<
156
+ in out TRegister extends Register = Register,
155
157
  in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
156
158
  in out TPath extends RouteConstraints['TPath'] = '/',
157
159
  in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
@@ -173,8 +175,10 @@ export class Route<
173
175
  in out TLoaderFn = undefined,
174
176
  in out TChildren = unknown,
175
177
  in out TFileRouteTypes = unknown,
178
+ in out TSSR = unknown,
176
179
  >
177
180
  extends BaseRoute<
181
+ TRegister,
178
182
  TParentRoute,
179
183
  TPath,
180
184
  TFullPath,
@@ -188,10 +192,12 @@ export class Route<
188
192
  TLoaderDeps,
189
193
  TLoaderFn,
190
194
  TChildren,
191
- TFileRouteTypes
195
+ TFileRouteTypes,
196
+ TSSR
192
197
  >
193
198
  implements
194
199
  RouteCore<
200
+ TRegister,
195
201
  TParentRoute,
196
202
  TPath,
197
203
  TFullPath,
@@ -205,7 +211,8 @@ export class Route<
205
211
  TLoaderDeps,
206
212
  TLoaderFn,
207
213
  TChildren,
208
- TFileRouteTypes
214
+ TFileRouteTypes,
215
+ TSSR
209
216
  >
210
217
  {
211
218
  /**
@@ -213,6 +220,7 @@ export class Route<
213
220
  */
214
221
  constructor(
215
222
  options?: RouteOptions<
223
+ TRegister,
216
224
  TParentRoute,
217
225
  TId,
218
226
  TCustomId,
@@ -224,7 +232,8 @@ export class Route<
224
232
  TLoaderFn,
225
233
  TRouterContext,
226
234
  TRouteContextFn,
227
- TBeforeLoadFn
235
+ TBeforeLoadFn,
236
+ TSSR
228
237
  >,
229
238
  ) {
230
239
  super(options)
@@ -277,6 +286,7 @@ export class Route<
277
286
  }
278
287
 
279
288
  export function createRoute<
289
+ TRegister extends Register = Register,
280
290
  TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
281
291
  TPath extends RouteConstraints['TPath'] = '/',
282
292
  TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
@@ -296,8 +306,10 @@ export function createRoute<
296
306
  TLoaderDeps extends Record<string, any> = {},
297
307
  TLoaderFn = undefined,
298
308
  TChildren = unknown,
309
+ TSSR = unknown,
299
310
  >(
300
311
  options: RouteOptions<
312
+ TRegister,
301
313
  TParentRoute,
302
314
  TId,
303
315
  TCustomId,
@@ -309,9 +321,11 @@ export function createRoute<
309
321
  TLoaderFn,
310
322
  AnyContext,
311
323
  TRouteContextFn,
312
- TBeforeLoadFn
324
+ TBeforeLoadFn,
325
+ TSSR
313
326
  >,
314
327
  ): Route<
328
+ TRegister,
315
329
  TParentRoute,
316
330
  TPath,
317
331
  TFullPath,
@@ -325,9 +339,11 @@ export function createRoute<
325
339
  TLoaderDeps,
326
340
  TLoaderFn,
327
341
  TChildren,
328
- unknown
342
+ unknown,
343
+ TSSR
329
344
  > {
330
345
  return new Route<
346
+ TRegister,
331
347
  TParentRoute,
332
348
  TPath,
333
349
  TFullPath,
@@ -341,36 +357,54 @@ export function createRoute<
341
357
  TLoaderDeps,
342
358
  TLoaderFn,
343
359
  TChildren,
344
- unknown
360
+ unknown,
361
+ TSSR
345
362
  >(options)
346
363
  }
347
364
 
348
- export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
365
+ export type AnyRootRoute = RootRoute<
366
+ any,
367
+ any,
368
+ any,
369
+ any,
370
+ any,
371
+ any,
372
+ any,
373
+ any,
374
+ any,
375
+ any
376
+ >
349
377
 
350
378
  export function createRootRouteWithContext<TRouterContext extends {}>() {
351
379
  return <
380
+ TRegister extends Register = Register,
352
381
  TRouteContextFn = AnyContext,
353
382
  TBeforeLoadFn = AnyContext,
354
383
  TSearchValidator = undefined,
355
384
  TLoaderDeps extends Record<string, any> = {},
356
385
  TLoaderFn = undefined,
386
+ TSSR = unknown,
357
387
  >(
358
388
  options?: RootRouteOptions<
389
+ TRegister,
359
390
  TSearchValidator,
360
391
  TRouterContext,
361
392
  TRouteContextFn,
362
393
  TBeforeLoadFn,
363
394
  TLoaderDeps,
364
- TLoaderFn
395
+ TLoaderFn,
396
+ TSSR
365
397
  >,
366
398
  ) => {
367
399
  return createRootRoute<
400
+ TRegister,
368
401
  TSearchValidator,
369
402
  TRouterContext,
370
403
  TRouteContextFn,
371
404
  TBeforeLoadFn,
372
405
  TLoaderDeps,
373
- TLoaderFn
406
+ TLoaderFn,
407
+ TSSR
374
408
  >(options as any)
375
409
  }
376
410
  }
@@ -381,6 +415,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
381
415
  export const rootRouteWithContext = createRootRouteWithContext
382
416
 
383
417
  export class RootRoute<
418
+ in out TRegister extends Register = Register,
384
419
  in out TSearchValidator = undefined,
385
420
  in out TRouterContext = {},
386
421
  in out TRouteContextFn = AnyContext,
@@ -389,8 +424,10 @@ export class RootRoute<
389
424
  in out TLoaderFn = undefined,
390
425
  in out TChildren = unknown,
391
426
  in out TFileRouteTypes = unknown,
427
+ in out TSSR = unknown,
392
428
  >
393
429
  extends BaseRootRoute<
430
+ TRegister,
394
431
  TSearchValidator,
395
432
  TRouterContext,
396
433
  TRouteContextFn,
@@ -398,10 +435,12 @@ export class RootRoute<
398
435
  TLoaderDeps,
399
436
  TLoaderFn,
400
437
  TChildren,
401
- TFileRouteTypes
438
+ TFileRouteTypes,
439
+ TSSR
402
440
  >
403
441
  implements
404
442
  RootRouteCore<
443
+ TRegister,
405
444
  TSearchValidator,
406
445
  TRouterContext,
407
446
  TRouteContextFn,
@@ -409,7 +448,8 @@ export class RootRoute<
409
448
  TLoaderDeps,
410
449
  TLoaderFn,
411
450
  TChildren,
412
- TFileRouteTypes
451
+ TFileRouteTypes,
452
+ TSSR
413
453
  >
414
454
  {
415
455
  /**
@@ -417,12 +457,14 @@ export class RootRoute<
417
457
  */
418
458
  constructor(
419
459
  options?: RootRouteOptions<
460
+ TRegister,
420
461
  TSearchValidator,
421
462
  TRouterContext,
422
463
  TRouteContextFn,
423
464
  TBeforeLoadFn,
424
465
  TLoaderDeps,
425
- TLoaderFn
466
+ TLoaderFn,
467
+ TSSR
426
468
  >,
427
469
  ) {
428
470
  super(options)
@@ -504,6 +546,7 @@ export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>
504
546
  export type NotFoundRouteComponent = RouteTypes<NotFoundRouteProps>['component']
505
547
 
506
548
  export class NotFoundRoute<
549
+ TRegister extends Register,
507
550
  TParentRoute extends AnyRootRoute,
508
551
  TRouterContext = AnyContext,
509
552
  TRouteContextFn = AnyContext,
@@ -512,7 +555,9 @@ export class NotFoundRoute<
512
555
  TLoaderDeps extends Record<string, any> = {},
513
556
  TLoaderFn = undefined,
514
557
  TChildren = unknown,
558
+ TSSR = unknown,
515
559
  > extends Route<
560
+ TRegister,
516
561
  TParentRoute,
517
562
  '/404',
518
563
  '/404',
@@ -525,11 +570,13 @@ export class NotFoundRoute<
525
570
  TBeforeLoadFn,
526
571
  TLoaderDeps,
527
572
  TLoaderFn,
528
- TChildren
573
+ TChildren,
574
+ TSSR
529
575
  > {
530
576
  constructor(
531
577
  options: Omit<
532
578
  RouteOptions<
579
+ TRegister,
533
580
  TParentRoute,
534
581
  string,
535
582
  string,
@@ -541,7 +588,8 @@ export class NotFoundRoute<
541
588
  TLoaderFn,
542
589
  TRouterContext,
543
590
  TRouteContextFn,
544
- TBeforeLoadFn
591
+ TBeforeLoadFn,
592
+ TSSR
545
593
  >,
546
594
  | 'caseSensitive'
547
595
  | 'parseParams'
@@ -559,22 +607,27 @@ export class NotFoundRoute<
559
607
  }
560
608
 
561
609
  export function createRootRoute<
610
+ TRegister extends Register = Register,
562
611
  TSearchValidator = undefined,
563
612
  TRouterContext = {},
564
613
  TRouteContextFn = AnyContext,
565
614
  TBeforeLoadFn = AnyContext,
566
615
  TLoaderDeps extends Record<string, any> = {},
567
616
  TLoaderFn = undefined,
617
+ TSSR = unknown,
568
618
  >(
569
619
  options?: RootRouteOptions<
620
+ TRegister,
570
621
  TSearchValidator,
571
622
  TRouterContext,
572
623
  TRouteContextFn,
573
624
  TBeforeLoadFn,
574
625
  TLoaderDeps,
575
- TLoaderFn
626
+ TLoaderFn,
627
+ TSSR
576
628
  >,
577
629
  ): RootRoute<
630
+ TRegister,
578
631
  TSearchValidator,
579
632
  TRouterContext,
580
633
  TRouteContextFn,
@@ -582,14 +635,19 @@ export function createRootRoute<
582
635
  TLoaderDeps,
583
636
  TLoaderFn,
584
637
  unknown,
585
- unknown
638
+ unknown,
639
+ TSSR
586
640
  > {
587
641
  return new RootRoute<
642
+ TRegister,
588
643
  TSearchValidator,
589
644
  TRouterContext,
590
645
  TRouteContextFn,
591
646
  TBeforeLoadFn,
592
647
  TLoaderDeps,
593
- TLoaderFn
648
+ TLoaderFn,
649
+ unknown,
650
+ unknown,
651
+ TSSR
594
652
  >(options)
595
653
  }
package/src/router.ts CHANGED
@@ -108,5 +108,5 @@ if (typeof globalThis !== 'undefined') {
108
108
  ;(globalThis as any).createLazyFileRoute = createLazyFileRoute
109
109
  } else if (typeof window !== 'undefined') {
110
110
  ;(window as any).createFileRoute = createFileRoute
111
- ;(window as any).createFileRoute = createLazyFileRoute
111
+ ;(window as any).createLazyFileRoute = createLazyFileRoute
112
112
  }
@@ -8,6 +8,17 @@ import { ScriptOnce } from './ScriptOnce'
8
8
 
9
9
  export function ScrollRestoration() {
10
10
  const router = useRouter()
11
+ if (!router.isScrollRestoring || !router.isServer) {
12
+ return null
13
+ }
14
+ if (typeof router.options.scrollRestoration === 'function') {
15
+ const shouldRestore = router.options.scrollRestoration({
16
+ location: router.latestLocation,
17
+ })
18
+ if (!shouldRestore) {
19
+ return null
20
+ }
21
+ }
11
22
  const getKey =
12
23
  router.options.getScrollRestorationKey || defaultGetScrollRestorationKey
13
24
  const userKey = getKey(router.latestLocation)
@@ -16,10 +27,6 @@ export function ScrollRestoration() {
16
27
  ? userKey
17
28
  : undefined
18
29
 
19
- if (!router.isScrollRestoring || !router.isServer) {
20
- return null
21
- }
22
-
23
30
  const restoreScrollOptions: Parameters<typeof restoreScroll>[0] = {
24
31
  storageKey,
25
32
  shouldScrollRestoration: true,