@tanstack/router-core 0.0.1-beta.14 → 0.0.1-beta.15

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.14",
4
+ "version": "0.0.1-beta.15",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -50,20 +50,27 @@ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
50
50
  }
51
51
 
52
52
  export type LoaderFn<
53
- TRouteLoaderData extends AnyLoaderData,
53
+ TParentRouteLoaderData extends AnyLoaderData = {},
54
+ TRouteLoaderData extends AnyLoaderData = {},
54
55
  TFullSearchSchema extends AnySearchSchema = {},
55
56
  TAllParams extends AnyPathParams = {},
56
57
  > = (
57
- loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,
58
+ loaderContext: LoaderContext<
59
+ TParentRouteLoaderData,
60
+ TFullSearchSchema,
61
+ TAllParams
62
+ >,
58
63
  ) => Promise<TRouteLoaderData>
59
64
 
60
65
  export interface LoaderContext<
66
+ TParentRouteLoaderData extends AnyLoaderData = {},
61
67
  TFullSearchSchema extends AnySearchSchema = {},
62
68
  TAllParams extends AnyPathParams = {},
63
69
  > {
64
70
  params: TAllParams
65
71
  search: TFullSearchSchema
66
72
  signal?: AbortSignal
73
+ parentLoaderPromise?: Promise<TParentRouteLoaderData>
67
74
  }
68
75
 
69
76
  export type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (
@@ -77,6 +84,7 @@ export type UnloaderFn<TPath extends string> = (
77
84
  export type RouteOptions<
78
85
  TRouteId extends string = string,
79
86
  TPath extends string = string,
87
+ TParentRouteLoaderData extends AnyLoaderData = {},
80
88
  TRouteLoaderData extends AnyLoaderData = {},
81
89
  TLoaderData extends AnyLoaderData = {},
82
90
  TActionPayload = unknown,
@@ -109,13 +117,18 @@ export type RouteOptions<
109
117
  // calls that match this route.
110
118
  postSearchFilters?: SearchFilter<TFullSearchSchema>[]
111
119
  // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
112
- component?: GetFrameworkGeneric<'Component'> // , NoInfer<TLoaderData>>
120
+ component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
113
121
  // The content to be rendered when the route encounters an error
114
- errorComponent?: GetFrameworkGeneric<'Component'> // , NoInfer<TLoaderData>>
122
+ errorComponent?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
115
123
  // If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
116
- pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TLoaderData>>
124
+ pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>
117
125
  // An asynchronous function responsible for preparing or fetching data for the route before it is rendered
118
- loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>
126
+ loader?: LoaderFn<
127
+ TParentRouteLoaderData,
128
+ TRouteLoaderData,
129
+ TFullSearchSchema,
130
+ TAllParams
131
+ >
119
132
  // The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch
120
133
  // Defaults to 0. Only stale loader data is refetched.
121
134
  loaderMaxAge?: number
@@ -171,6 +184,7 @@ export interface RouteConfig<
171
184
  TRouteId extends string = string,
172
185
  TPath extends string = string,
173
186
  TFullPath extends string = string,
187
+ TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
174
188
  TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
175
189
  TLoaderData extends AnyLoaderData = AnyLoaderData,
176
190
  TActionPayload = unknown,
@@ -193,6 +207,7 @@ export interface RouteConfig<
193
207
  options: RouteOptions<
194
208
  TRouteId,
195
209
  TPath,
210
+ TParentRouteLoaderData,
196
211
  TRouteLoaderData,
197
212
  TLoaderData,
198
213
  TActionPayload,
@@ -217,6 +232,7 @@ export interface RouteConfig<
217
232
  TRouteId,
218
233
  TPath,
219
234
  TFullPath,
235
+ TParentRouteLoaderData,
220
236
  TRouteLoaderData,
221
237
  TLoaderData,
222
238
  TActionPayload,
@@ -239,6 +255,7 @@ export interface RouteConfig<
239
255
  false,
240
256
  TId,
241
257
  TFullPath,
258
+ TRouteLoaderData,
242
259
  TLoaderData,
243
260
  TFullSearchSchema,
244
261
  TAllParams
@@ -251,6 +268,7 @@ export interface RouteConfig<
251
268
  TRouteId,
252
269
  TPath,
253
270
  TFullPath,
271
+ TParentRouteLoaderData,
254
272
  TRouteLoaderData,
255
273
  TLoaderData,
256
274
  TActionPayload,
@@ -268,6 +286,7 @@ export interface RouteConfig<
268
286
  false,
269
287
  TId,
270
288
  TFullPath,
289
+ TRouteLoaderData,
271
290
  TLoaderData,
272
291
  TFullSearchSchema,
273
292
  TAllParams
@@ -278,7 +297,8 @@ type CreateRouteConfigFn<
278
297
  TIsRoot extends boolean = false,
279
298
  TParentId extends string = string,
280
299
  TParentPath extends string = string,
281
- TParentAllLoaderData extends AnyLoaderData = {},
300
+ TParentRouteLoaderData extends AnyLoaderData = {},
301
+ TParentLoaderData extends AnyLoaderData = {},
282
302
  TParentSearchSchema extends AnySearchSchema = {},
283
303
  TParentParams extends AnyPathParams = {},
284
304
  > = <
@@ -309,8 +329,9 @@ type CreateRouteConfigFn<
309
329
  RouteOptions<
310
330
  TRouteId,
311
331
  TPath,
332
+ TParentRouteLoaderData,
312
333
  TRouteLoaderData,
313
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
334
+ Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
314
335
  TActionPayload,
315
336
  TActionResponse,
316
337
  TParentSearchSchema,
@@ -325,8 +346,9 @@ type CreateRouteConfigFn<
325
346
  : RouteOptions<
326
347
  TRouteId,
327
348
  TPath,
349
+ TParentRouteLoaderData,
328
350
  TRouteLoaderData,
329
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
351
+ Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
330
352
  TActionPayload,
331
353
  TActionResponse,
332
354
  TParentSearchSchema,
@@ -345,8 +367,9 @@ type CreateRouteConfigFn<
345
367
  TResolvedId,
346
368
  TPath,
347
369
  string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
370
+ TParentRouteLoaderData,
348
371
  TRouteLoaderData,
349
- Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
372
+ Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
350
373
  TActionPayload,
351
374
  TActionResponse,
352
375
  TParentSearchSchema,
@@ -389,6 +412,7 @@ export interface AnyRouteConfig
389
412
  any,
390
413
  any,
391
414
  any,
415
+ any,
392
416
  any
393
417
  > {}
394
418
 
@@ -408,6 +432,7 @@ export interface AnyRouteConfigWithChildren<TChildren>
408
432
  any,
409
433
  any,
410
434
  any,
435
+ any,
411
436
  TChildren
412
437
  > {}
413
438
 
package/src/routeInfo.ts CHANGED
@@ -63,6 +63,7 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
63
63
  infer TRouteId,
64
64
  infer TPath,
65
65
  infer TFullPath,
66
+ infer TParentLoaderData,
66
67
  infer TRouteLoaderData,
67
68
  infer TLoaderData,
68
69
  infer TActionPayload,
@@ -82,6 +83,7 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
82
83
  TRouteId,
83
84
  TPath,
84
85
  TFullPath,
86
+ TParentLoaderData,
85
87
  TRouteLoaderData,
86
88
  TLoaderData,
87
89
  TActionPayload,
@@ -111,6 +113,7 @@ export interface RoutesInfoInner<
111
113
  any,
112
114
  any,
113
115
  any,
116
+ any,
114
117
  any
115
118
  > = RouteInfo,
116
119
  TRouteInfoById = {
@@ -147,6 +150,7 @@ export interface AnyRouteInfo
147
150
  any,
148
151
  any,
149
152
  any,
153
+ any,
150
154
  any
151
155
  > {}
152
156
 
@@ -155,6 +159,7 @@ export interface RouteInfo<
155
159
  TRouteId extends string = string,
156
160
  TPath extends string = string,
157
161
  TFullPath extends string = string,
162
+ TParentRouteLoaderData extends AnyLoaderData = {},
158
163
  TRouteLoaderData extends AnyLoaderData = {},
159
164
  TLoaderData extends AnyLoaderData = {},
160
165
  TActionPayload = unknown,
@@ -173,6 +178,7 @@ export interface RouteInfo<
173
178
  routeId: TRouteId
174
179
  path: TPath
175
180
  fullPath: TFullPath
181
+ parentRouteLoaderData: TParentRouteLoaderData
176
182
  routeLoaderData: TRouteLoaderData
177
183
  loaderData: TLoaderData
178
184
  actionPayload: TActionPayload
@@ -185,6 +191,7 @@ export interface RouteInfo<
185
191
  options: RouteOptions<
186
192
  TRouteId,
187
193
  TPath,
194
+ TParentRouteLoaderData,
188
195
  TRouteLoaderData,
189
196
  TLoaderData,
190
197
  TActionPayload,
package/src/routeMatch.ts CHANGED
@@ -35,7 +35,7 @@ export interface RouteMatch<
35
35
  pendingComponent?: GetFrameworkGeneric<'Component'> // , TRouteInfo['loaderData']>
36
36
  loadPromise?: Promise<void>
37
37
  componentsPromise?: Promise<void>
38
- dataPromise?: Promise<void>
38
+ dataPromise?: Promise<TRouteInfo['routeLoaderData']>
39
39
  onExit?:
40
40
  | void
41
41
  | ((matchContext: {
@@ -74,6 +74,7 @@ export function createRouteMatch<
74
74
  router: Router<any, any>,
75
75
  route: Route<TAllRouteInfo, TRouteInfo>,
76
76
  opts: {
77
+ parentMatch?: RouteMatch<any, any>
77
78
  matchId: string
78
79
  params: TRouteInfo['allParams']
79
80
  pathname: string
@@ -240,6 +241,7 @@ export function createRouteMatch<
240
241
  try {
241
242
  if (routeMatch.options.loader) {
242
243
  const data = await routeMatch.options.loader({
244
+ parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
243
245
  params: routeMatch.params,
244
246
  search: routeMatch.routeSearch,
245
247
  signal: routeMatch.__.abortController.signal,
@@ -263,6 +265,8 @@ export function createRouteMatch<
263
265
  routeMatch.options.loaderMaxAge ??
264
266
  router.options.defaultLoaderMaxAge ??
265
267
  0)
268
+
269
+ return routeMatch.routeLoaderData
266
270
  } catch (err) {
267
271
  if (id !== routeMatch.__.latestId) {
268
272
  return routeMatch.__.loadPromise
@@ -271,16 +275,19 @@ export function createRouteMatch<
271
275
  if (process.env.NODE_ENV !== 'production') {
272
276
  console.error(err)
273
277
  }
278
+
274
279
  routeMatch.error = err
275
280
  routeMatch.status = 'error'
276
281
  routeMatch.updatedAt = Date.now()
282
+
283
+ throw err
277
284
  }
278
285
  })
279
286
 
280
287
  try {
281
288
  await Promise.all([
282
289
  routeMatch.__.componentsPromise,
283
- routeMatch.__.dataPromise,
290
+ routeMatch.__.dataPromise.catch(() => {}),
284
291
  ])
285
292
  if (id !== routeMatch.__.latestId) {
286
293
  return routeMatch.__.loadPromise
package/src/router.ts CHANGED
@@ -811,6 +811,7 @@ export function createRouter<
811
811
  existingMatches.find((d) => d.matchId === matchId) ||
812
812
  router.matchCache[matchId]?.match ||
813
813
  createRouteMatch(router, foundRoute, {
814
+ parentMatch,
814
815
  matchId,
815
816
  params,
816
817
  pathname: joinPaths([pathname, interpolatedPath]),