@tanstack/react-router 0.0.1-beta.276 → 0.0.1-beta.278

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.276",
4
+ "version": "0.0.1-beta.278",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.276"
47
+ "@tanstack/history": "0.0.1-beta.278"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/Matches.tsx CHANGED
@@ -95,6 +95,8 @@ export function Match({ matchId }: { matchId: string }) {
95
95
  const PendingComponent = (route.options.pendingComponent ??
96
96
  router.options.defaultPendingComponent) as any
97
97
 
98
+ const pendingElement = PendingComponent ? <PendingComponent /> : null
99
+
98
100
  const routeErrorComponent =
99
101
  route.options.errorComponent ??
100
102
  router.options.defaultErrorComponent ??
@@ -115,7 +117,7 @@ export function Match({ matchId }: { matchId: string }) {
115
117
 
116
118
  return (
117
119
  <matchContext.Provider value={matchId}>
118
- <ResolvedSuspenseBoundary fallback={PendingComponent}>
120
+ <ResolvedSuspenseBoundary fallback={pendingElement}>
119
121
  <ResolvedCatchBoundary
120
122
  getResetKey={() => router.state.resolvedLocation.state?.key}
121
123
  errorComponent={routeErrorComponent}
@@ -123,7 +125,7 @@ export function Match({ matchId }: { matchId: string }) {
123
125
  warning(false, `Error in route match: ${matchId}`)
124
126
  }}
125
127
  >
126
- <MatchInner matchId={matchId!} pendingElement={PendingComponent} />
128
+ <MatchInner matchId={matchId!} pendingElement={pendingElement} />
127
129
  </ResolvedCatchBoundary>
128
130
  </ResolvedSuspenseBoundary>
129
131
  </matchContext.Provider>
@@ -161,7 +163,7 @@ function MatchInner({
161
163
 
162
164
  if (match.status === 'pending') {
163
165
  if (match.showPending) {
164
- return pendingElement || null
166
+ return pendingElement
165
167
  }
166
168
  throw match.loadPromise
167
169
  }
@@ -218,6 +220,7 @@ export type UseMatchRouteOptions<
218
220
  export function useMatchRoute<
219
221
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
220
222
  >() {
223
+ useRouterState({ select: (s) => [s.location, s.resolvedLocation] })
221
224
  const { matchRoute } = useRouter()
222
225
 
223
226
  return React.useCallback(
@@ -370,6 +373,30 @@ export function useParentMatches<T = RouteMatch[]>(opts?: {
370
373
  })
371
374
  }
372
375
 
376
+ export function useLoaderDeps<
377
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
378
+ TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
379
+ TStrict extends boolean = true,
380
+ TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<
381
+ TRouteTree,
382
+ TFrom
383
+ >,
384
+ TSelected = Required<TRouteMatch>['loaderDeps'],
385
+ >(
386
+ opts: StrictOrFrom<TFrom> & {
387
+ select?: (match: TRouteMatch) => TSelected
388
+ },
389
+ ): TStrict extends true ? TSelected : TSelected | undefined {
390
+ return useMatch({
391
+ ...opts,
392
+ select: (s) => {
393
+ return typeof opts.select === 'function'
394
+ ? opts.select(s?.loaderDeps)
395
+ : s?.loaderDeps
396
+ },
397
+ })!
398
+ }
399
+
373
400
  export function useLoaderData<
374
401
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
375
402
  TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
package/src/route.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import invariant from 'tiny-invariant'
3
- import { useLoaderData, useMatch } from './Matches'
3
+ import { useLoaderData, useLoaderDeps, useMatch } from './Matches'
4
4
  import { AnyRouteMatch } from './Matches'
5
5
  import { NavigateOptions, ParsePathParams, ToSubOptions } from './link'
6
6
  import { ParsedLocation } from './location'
@@ -345,6 +345,7 @@ export class RouteApi<
345
345
  > = TRoute['types']['fullSearchSchema'],
346
346
  TAllParams extends AnyPathParams = TRoute['types']['allParams'],
347
347
  TAllContext extends Record<string, any> = TRoute['types']['allContext'],
348
+ TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
348
349
  TLoaderData extends any = TRoute['types']['loaderData'],
349
350
  > {
350
351
  id: TId
@@ -354,13 +355,13 @@ export class RouteApi<
354
355
  }
355
356
 
356
357
  useMatch = <TSelected = TAllContext>(opts?: {
357
- select?: (search: TAllContext) => TSelected
358
+ select?: (s: TAllContext) => TSelected
358
359
  }): TSelected => {
359
360
  return useMatch({ ...opts, from: this.id }) as any
360
361
  }
361
362
 
362
363
  useRouteContext = <TSelected = TAllContext>(opts?: {
363
- select?: (search: TAllContext) => TSelected
364
+ select?: (s: TAllContext) => TSelected
364
365
  }): TSelected => {
365
366
  return useMatch({
366
367
  ...opts,
@@ -370,19 +371,25 @@ export class RouteApi<
370
371
  }
371
372
 
372
373
  useSearch = <TSelected = TFullSearchSchema>(opts?: {
373
- select?: (search: TFullSearchSchema) => TSelected
374
+ select?: (s: TFullSearchSchema) => TSelected
374
375
  }): TSelected => {
375
376
  return useSearch({ ...opts, from: this.id } as any)
376
377
  }
377
378
 
378
379
  useParams = <TSelected = TAllParams>(opts?: {
379
- select?: (search: TAllParams) => TSelected
380
+ select?: (s: TAllParams) => TSelected
380
381
  }): TSelected => {
381
382
  return useParams({ ...opts, from: this.id } as any)
382
383
  }
383
384
 
385
+ useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {
386
+ select?: (s: TLoaderDeps) => TSelected
387
+ }): TSelected => {
388
+ return useLoaderDeps({ ...opts, from: this.id } as any) as any
389
+ }
390
+
384
391
  useLoaderData = <TSelected = TLoaderData>(opts?: {
385
- select?: (search: TLoaderData) => TSelected
392
+ select?: (s: TLoaderData) => TSelected
386
393
  }): TSelected => {
387
394
  return useLoaderData({ ...opts, from: this.id } as any) as any
388
395
  }
@@ -628,6 +635,12 @@ export class Route<
628
635
  return useParams({ ...opts, from: this.id } as any)
629
636
  }
630
637
 
638
+ useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {
639
+ select?: (s: TLoaderDeps) => TSelected
640
+ }): TSelected => {
641
+ return useLoaderDeps({ ...opts, from: this.id } as any) as any
642
+ }
643
+
631
644
  useLoaderData = <TSelected = TLoaderData>(opts?: {
632
645
  select?: (search: TLoaderData) => TSelected
633
646
  }): TSelected => {
package/src/router.ts CHANGED
@@ -989,11 +989,11 @@ export class Router<
989
989
  let firstBadMatchIndex: number | undefined
990
990
 
991
991
  const updateMatch = (match: AnyRouteMatch) => {
992
- const isPreload = this.state.preloadMatches.find((d) => d.id === match.id)
992
+ // const isPreload = this.state.preloadMatches.find((d) => d.id === match.id)
993
993
  const isPending = this.state.pendingMatches?.find(
994
994
  (d) => d.id === match.id,
995
995
  )
996
- const matchesKey = isPreload
996
+ const matchesKey = preload
997
997
  ? 'preloadMatches'
998
998
  : isPending
999
999
  ? 'pendingMatches'