@tanstack/react-router 1.22.4 → 1.22.6

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 (161) hide show
  1. package/dist/cjs/CatchBoundary.cjs +1 -2
  2. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +15 -15
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/Matches.d.cts +15 -15
  6. package/dist/cjs/RouterProvider.cjs +16 -15
  7. package/dist/cjs/RouterProvider.cjs.map +1 -1
  8. package/dist/cjs/RouterProvider.d.cts +6 -6
  9. package/dist/cjs/awaited.cjs +1 -1
  10. package/dist/cjs/awaited.cjs.map +1 -1
  11. package/dist/cjs/awaited.d.cts +1 -1
  12. package/dist/cjs/defer.cjs.map +1 -1
  13. package/dist/cjs/fileRoute.cjs +1 -1
  14. package/dist/cjs/fileRoute.cjs.map +1 -1
  15. package/dist/cjs/fileRoute.d.cts +17 -17
  16. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  17. package/dist/cjs/lazyRouteComponent.d.cts +1 -1
  18. package/dist/cjs/link.cjs +10 -11
  19. package/dist/cjs/link.cjs.map +1 -1
  20. package/dist/cjs/link.d.cts +16 -13
  21. package/dist/cjs/location.d.cts +2 -2
  22. package/dist/cjs/not-found.cjs.map +1 -1
  23. package/dist/cjs/not-found.d.cts +2 -2
  24. package/dist/cjs/path.cjs +2 -2
  25. package/dist/cjs/path.cjs.map +1 -1
  26. package/dist/cjs/path.d.cts +4 -4
  27. package/dist/cjs/qss.cjs +4 -3
  28. package/dist/cjs/qss.cjs.map +1 -1
  29. package/dist/cjs/redirects.cjs.map +1 -1
  30. package/dist/cjs/redirects.d.cts +5 -5
  31. package/dist/cjs/route.cjs.map +1 -1
  32. package/dist/cjs/route.d.cts +34 -36
  33. package/dist/cjs/routeInfo.d.cts +5 -5
  34. package/dist/cjs/router.cjs +63 -66
  35. package/dist/cjs/router.cjs.map +1 -1
  36. package/dist/cjs/router.d.cts +28 -28
  37. package/dist/cjs/routerContext.cjs +1 -1
  38. package/dist/cjs/routerContext.cjs.map +1 -1
  39. package/dist/cjs/routerContext.d.cts +1 -1
  40. package/dist/cjs/scroll-restoration.cjs +7 -9
  41. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  42. package/dist/cjs/scroll-restoration.d.cts +1 -1
  43. package/dist/cjs/searchParams.cjs +10 -12
  44. package/dist/cjs/searchParams.cjs.map +1 -1
  45. package/dist/cjs/searchParams.d.cts +1 -1
  46. package/dist/cjs/useBlocker.cjs.map +1 -1
  47. package/dist/cjs/useBlocker.d.cts +2 -2
  48. package/dist/cjs/useNavigate.cjs +1 -1
  49. package/dist/cjs/useNavigate.cjs.map +1 -1
  50. package/dist/cjs/useNavigate.d.cts +4 -4
  51. package/dist/cjs/useParams.cjs +1 -1
  52. package/dist/cjs/useParams.cjs.map +1 -1
  53. package/dist/cjs/useParams.d.cts +5 -5
  54. package/dist/cjs/useRouteContext.cjs +1 -1
  55. package/dist/cjs/useRouteContext.cjs.map +1 -1
  56. package/dist/cjs/useRouteContext.d.cts +4 -4
  57. package/dist/cjs/useRouter.cjs.map +1 -1
  58. package/dist/cjs/useRouter.d.cts +2 -2
  59. package/dist/cjs/useRouterState.cjs.map +1 -1
  60. package/dist/cjs/useRouterState.d.cts +2 -2
  61. package/dist/cjs/useSearch.cjs +1 -1
  62. package/dist/cjs/useSearch.cjs.map +1 -1
  63. package/dist/cjs/useSearch.d.cts +4 -4
  64. package/dist/cjs/utils.cjs +2 -2
  65. package/dist/cjs/utils.cjs.map +1 -1
  66. package/dist/cjs/utils.d.cts +13 -11
  67. package/dist/esm/CatchBoundary.js +1 -2
  68. package/dist/esm/CatchBoundary.js.map +1 -1
  69. package/dist/esm/Matches.d.ts +15 -15
  70. package/dist/esm/Matches.js +15 -15
  71. package/dist/esm/Matches.js.map +1 -1
  72. package/dist/esm/RouterProvider.d.ts +6 -6
  73. package/dist/esm/RouterProvider.js +16 -15
  74. package/dist/esm/RouterProvider.js.map +1 -1
  75. package/dist/esm/awaited.d.ts +1 -1
  76. package/dist/esm/awaited.js +1 -1
  77. package/dist/esm/awaited.js.map +1 -1
  78. package/dist/esm/defer.js.map +1 -1
  79. package/dist/esm/fileRoute.d.ts +17 -17
  80. package/dist/esm/fileRoute.js +1 -1
  81. package/dist/esm/fileRoute.js.map +1 -1
  82. package/dist/esm/lazyRouteComponent.d.ts +1 -1
  83. package/dist/esm/lazyRouteComponent.js.map +1 -1
  84. package/dist/esm/link.d.ts +16 -13
  85. package/dist/esm/link.js +10 -11
  86. package/dist/esm/link.js.map +1 -1
  87. package/dist/esm/location.d.ts +2 -2
  88. package/dist/esm/not-found.d.ts +2 -2
  89. package/dist/esm/not-found.js.map +1 -1
  90. package/dist/esm/path.d.ts +4 -4
  91. package/dist/esm/path.js +2 -2
  92. package/dist/esm/path.js.map +1 -1
  93. package/dist/esm/qss.js +4 -3
  94. package/dist/esm/qss.js.map +1 -1
  95. package/dist/esm/redirects.d.ts +5 -5
  96. package/dist/esm/redirects.js.map +1 -1
  97. package/dist/esm/route.d.ts +34 -36
  98. package/dist/esm/route.js.map +1 -1
  99. package/dist/esm/routeInfo.d.ts +5 -5
  100. package/dist/esm/router.d.ts +28 -28
  101. package/dist/esm/router.js +63 -66
  102. package/dist/esm/router.js.map +1 -1
  103. package/dist/esm/routerContext.d.ts +1 -1
  104. package/dist/esm/routerContext.js +1 -1
  105. package/dist/esm/routerContext.js.map +1 -1
  106. package/dist/esm/scroll-restoration.d.ts +1 -1
  107. package/dist/esm/scroll-restoration.js +7 -9
  108. package/dist/esm/scroll-restoration.js.map +1 -1
  109. package/dist/esm/searchParams.d.ts +1 -1
  110. package/dist/esm/searchParams.js +10 -12
  111. package/dist/esm/searchParams.js.map +1 -1
  112. package/dist/esm/useBlocker.d.ts +2 -2
  113. package/dist/esm/useBlocker.js.map +1 -1
  114. package/dist/esm/useNavigate.d.ts +4 -4
  115. package/dist/esm/useNavigate.js +1 -1
  116. package/dist/esm/useNavigate.js.map +1 -1
  117. package/dist/esm/useParams.d.ts +5 -5
  118. package/dist/esm/useParams.js +1 -1
  119. package/dist/esm/useParams.js.map +1 -1
  120. package/dist/esm/useRouteContext.d.ts +4 -4
  121. package/dist/esm/useRouteContext.js +1 -1
  122. package/dist/esm/useRouteContext.js.map +1 -1
  123. package/dist/esm/useRouter.d.ts +2 -2
  124. package/dist/esm/useRouter.js.map +1 -1
  125. package/dist/esm/useRouterState.d.ts +2 -2
  126. package/dist/esm/useRouterState.js.map +1 -1
  127. package/dist/esm/useSearch.d.ts +4 -4
  128. package/dist/esm/useSearch.js +1 -1
  129. package/dist/esm/useSearch.js.map +1 -1
  130. package/dist/esm/utils.d.ts +13 -11
  131. package/dist/esm/utils.js +2 -2
  132. package/dist/esm/utils.js.map +1 -1
  133. package/package.json +3 -2
  134. package/src/CatchBoundary.tsx +1 -1
  135. package/src/Matches.tsx +48 -47
  136. package/src/RouterProvider.tsx +22 -16
  137. package/src/awaited.tsx +3 -3
  138. package/src/defer.ts +1 -0
  139. package/src/fileRoute.ts +53 -53
  140. package/src/history.ts +1 -1
  141. package/src/lazyRouteComponent.tsx +2 -1
  142. package/src/link.tsx +50 -42
  143. package/src/location.ts +2 -2
  144. package/src/not-found.tsx +3 -2
  145. package/src/path.ts +8 -8
  146. package/src/qss.ts +4 -5
  147. package/src/redirects.ts +5 -5
  148. package/src/route.ts +73 -67
  149. package/src/routeInfo.ts +8 -6
  150. package/src/router.ts +150 -145
  151. package/src/routerContext.tsx +2 -2
  152. package/src/scroll-restoration.tsx +9 -12
  153. package/src/searchParams.ts +11 -13
  154. package/src/useBlocker.tsx +3 -3
  155. package/src/useNavigate.tsx +7 -5
  156. package/src/useParams.tsx +6 -6
  157. package/src/useRouteContext.ts +7 -8
  158. package/src/useRouter.tsx +2 -2
  159. package/src/useRouterState.tsx +2 -2
  160. package/src/useSearch.tsx +7 -6
  161. package/src/utils.ts +36 -24
package/src/Matches.tsx CHANGED
@@ -4,14 +4,17 @@ import warning from 'tiny-warning'
4
4
  import { CatchBoundary, ErrorComponent } from './CatchBoundary'
5
5
  import { useRouterState } from './useRouterState'
6
6
  import { useRouter } from './useRouter'
7
- import { ResolveRelativePath, ToOptions } from './link'
8
- import {
7
+ import { isServer, pick } from './utils'
8
+ import { CatchNotFound, DefaultGlobalNotFound, isNotFound } from './not-found'
9
+ import { isRedirect } from './redirects'
10
+ import type { ResolveRelativePath, ToOptions } from './link'
11
+ import type {
9
12
  AnyRoute,
10
13
  ReactNode,
11
14
  RootSearchSchema,
12
15
  StaticDataRouteOption,
13
16
  } from './route'
14
- import {
17
+ import type {
15
18
  AllParams,
16
19
  FullSearchSchema,
17
20
  ParseRoute,
@@ -20,17 +23,8 @@ import {
20
23
  RouteIds,
21
24
  RoutePaths,
22
25
  } from './routeInfo'
23
- import { AnyRouter, RegisteredRouter, RouterState } from './router'
24
- import {
25
- DeepPartial,
26
- Expand,
27
- NoInfer,
28
- StrictOrFrom,
29
- isServer,
30
- pick,
31
- } from './utils'
32
- import { CatchNotFound, DefaultGlobalNotFound, isNotFound } from './not-found'
33
- import { isRedirect } from './redirects'
26
+ import type { AnyRouter, RegisteredRouter, RouterState } from './router'
27
+ import type { DeepPartial, Expand, NoInfer, StrictOrFrom } from './utils'
34
28
 
35
29
  export const matchContext = React.createContext<string | undefined>(undefined)
36
30
 
@@ -71,9 +65,9 @@ export interface RouteMatch<
71
65
  preload: boolean
72
66
  invalid: boolean
73
67
  pendingPromise?: Promise<void>
74
- meta?: JSX.IntrinsicElements['meta'][]
75
- links?: JSX.IntrinsicElements['link'][]
76
- scripts?: JSX.IntrinsicElements['script'][]
68
+ meta?: Array<JSX.IntrinsicElements['meta']>
69
+ links?: Array<JSX.IntrinsicElements['link']>
70
+ scripts?: Array<JSX.IntrinsicElements['script']>
77
71
  headers?: Record<string, string>
78
72
  globalNotFound?: boolean
79
73
  staticData: StaticDataRouteOption
@@ -89,10 +83,14 @@ export function Matches() {
89
83
  },
90
84
  })
91
85
 
86
+ const resetKey = useRouterState({
87
+ select: (s) => s.resolvedLocation.state.key!,
88
+ })
89
+
92
90
  return (
93
91
  <matchContext.Provider value={matchId}>
94
92
  <CatchBoundary
95
- getResetKey={() => router.state.resolvedLocation.state?.key!}
93
+ getResetKey={() => router.state.resolvedLocation.state.key!}
96
94
  errorComponent={ErrorComponent}
97
95
  onCatch={(error) => {
98
96
  warning(
@@ -126,8 +124,8 @@ export function Match({ matchId }: { matchId: string }) {
126
124
 
127
125
  const route = router.routesById[routeId]!
128
126
 
129
- const PendingComponent = (route.options.pendingComponent ??
130
- router.options.defaultPendingComponent) as any
127
+ const PendingComponent =
128
+ route.options.pendingComponent ?? router.options.defaultPendingComponent
131
129
 
132
130
  const pendingElement = PendingComponent ? <PendingComponent /> : null
133
131
 
@@ -145,7 +143,7 @@ export function Match({ matchId }: { matchId: string }) {
145
143
  PendingComponent ??
146
144
  route.options.component?.preload ??
147
145
  route.options.pendingComponent?.preload ??
148
- (route.options.errorComponent as any)?.preload
146
+ route.options.errorComponent?.preload
149
147
  ? React.Suspense
150
148
  : SafeFragment
151
149
 
@@ -157,11 +155,15 @@ export function Match({ matchId }: { matchId: string }) {
157
155
  ? CatchNotFound
158
156
  : SafeFragment
159
157
 
158
+ const resetKey = useRouterState({
159
+ select: (s) => s.resolvedLocation.state.key!,
160
+ })
161
+
160
162
  return (
161
163
  <matchContext.Provider value={matchId}>
162
164
  <ResolvedSuspenseBoundary fallback={pendingElement}>
163
165
  <ResolvedCatchBoundary
164
- getResetKey={() => router.state.resolvedLocation.state?.key!}
166
+ getResetKey={() => resetKey}
165
167
  errorComponent={routeErrorComponent ?? ErrorComponent}
166
168
  onCatch={(error) => {
167
169
  // Forward not found errors (we don't want to show the error component for these)
@@ -184,7 +186,7 @@ export function Match({ matchId }: { matchId: string }) {
184
186
  return React.createElement(routeNotFoundComponent, error as any)
185
187
  }}
186
188
  >
187
- <MatchInner matchId={matchId!} pendingElement={pendingElement} />
189
+ <MatchInner matchId={matchId} pendingElement={pendingElement} />
188
190
  </ResolvedNotFoundBoundary>
189
191
  </ResolvedCatchBoundary>
190
192
  </ResolvedSuspenseBoundary>
@@ -283,8 +285,9 @@ function MatchInner({
283
285
  throw match.loadPromise
284
286
  }
285
287
 
288
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
286
289
  if (match.status === 'success') {
287
- let Comp = route.options.component ?? router.options.defaultComponent
290
+ const Comp = route.options.component ?? router.options.defaultComponent
288
291
 
289
292
  if (Comp) {
290
293
  return <Comp />
@@ -374,16 +377,16 @@ export type UseMatchRouteOptions<
374
377
  TTo extends string = '',
375
378
  TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
376
379
  TMaskTo extends string = '',
377
- Options extends ToOptions<
380
+ TOptions extends ToOptions<
378
381
  TRouteTree,
379
382
  TFrom,
380
383
  TTo,
381
384
  TMaskFrom,
382
385
  TMaskTo
383
386
  > = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,
384
- RelaxedOptions = Omit<Options, 'search' | 'params'> &
385
- DeepPartial<Pick<Options, 'search' | 'params'>>,
386
- > = RelaxedOptions & MatchRouteOptions
387
+ TRelaxedOptions = Omit<TOptions, 'search' | 'params'> &
388
+ DeepPartial<Pick<TOptions, 'search' | 'params'>>,
389
+ > = TRelaxedOptions & MatchRouteOptions
387
390
 
388
391
  export function useMatchRoute<
389
392
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
@@ -447,7 +450,7 @@ export function MatchRoute<
447
450
  return (props.children as any)(params)
448
451
  }
449
452
 
450
- return !!params ? props.children : null
453
+ return params ? props.children : null
451
454
  }
452
455
 
453
456
  export function getRenderedMatches<
@@ -474,19 +477,17 @@ export function useMatch<
474
477
  const matchSelection = useRouterState({
475
478
  select: (state) => {
476
479
  const match = getRenderedMatches(state).find((d) =>
477
- opts?.from ? opts?.from === d.routeId : d.id === nearestMatchId,
480
+ opts.from ? opts.from === d.routeId : d.id === nearestMatchId,
478
481
  )
479
482
 
480
483
  invariant(
481
484
  match,
482
485
  `Could not find ${
483
- opts?.from
484
- ? `an active match from "${opts.from}"`
485
- : 'a nearest match!'
486
+ opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'
486
487
  }`,
487
488
  )
488
489
 
489
- return opts?.select ? opts.select(match as any) : match
490
+ return opts.select ? opts.select(match as any) : match
490
491
  },
491
492
  })
492
493
 
@@ -498,16 +499,16 @@ export function useMatches<
498
499
  TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
499
500
  TReturnIntersection extends boolean = false,
500
501
  TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,
501
- T = TRouteMatch[],
502
+ T = Array<TRouteMatch>,
502
503
  >(opts?: {
503
- select?: (matches: TRouteMatch[]) => T
504
+ select?: (matches: Array<TRouteMatch>) => T
504
505
  experimental_returnIntersection?: TReturnIntersection
505
506
  }): T {
506
507
  return useRouterState({
507
508
  select: (state) => {
508
509
  const matches = getRenderedMatches(state)
509
510
  return opts?.select
510
- ? opts.select(matches as TRouteMatch[])
511
+ ? opts.select(matches as Array<TRouteMatch>)
511
512
  : (matches as T)
512
513
  },
513
514
  })
@@ -518,9 +519,9 @@ export function useParentMatches<
518
519
  TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
519
520
  TReturnIntersection extends boolean = false,
520
521
  TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,
521
- T = TRouteMatch[],
522
+ T = Array<TRouteMatch>,
522
523
  >(opts?: {
523
- select?: (matches: TRouteMatch[]) => T
524
+ select?: (matches: Array<TRouteMatch>) => T
524
525
  experimental_returnIntersection?: TReturnIntersection
525
526
  }): T {
526
527
  const contextMatchId = React.useContext(matchContext)
@@ -532,7 +533,7 @@ export function useParentMatches<
532
533
  matches.findIndex((d) => d.id === contextMatchId),
533
534
  )
534
535
  return opts?.select
535
- ? opts.select(matches as TRouteMatch[])
536
+ ? opts.select(matches as Array<TRouteMatch>)
536
537
  : (matches as T)
537
538
  },
538
539
  })
@@ -543,9 +544,9 @@ export function useChildMatches<
543
544
  TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
544
545
  TReturnIntersection extends boolean = false,
545
546
  TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,
546
- T = TRouteMatch[],
547
+ T = Array<TRouteMatch>,
547
548
  >(opts?: {
548
- select?: (matches: TRouteMatch[]) => T
549
+ select?: (matches: Array<TRouteMatch>) => T
549
550
  experimental_returnIntersection?: TReturnIntersection
550
551
  }): T {
551
552
  const contextMatchId = React.useContext(matchContext)
@@ -556,7 +557,7 @@ export function useChildMatches<
556
557
  matches.findIndex((d) => d.id === contextMatchId) + 1,
557
558
  )
558
559
  return opts?.select
559
- ? opts.select(matches as TRouteMatch[])
560
+ ? opts.select(matches as Array<TRouteMatch>)
560
561
  : (matches as T)
561
562
  },
562
563
  })
@@ -579,8 +580,8 @@ export function useLoaderDeps<
579
580
  ...opts,
580
581
  select: (s) => {
581
582
  return typeof opts.select === 'function'
582
- ? opts.select(s?.loaderDeps)
583
- : s?.loaderDeps
583
+ ? opts.select(s.loaderDeps)
584
+ : s.loaderDeps
584
585
  },
585
586
  })
586
587
  }
@@ -602,8 +603,8 @@ export function useLoaderData<
602
603
  ...opts,
603
604
  select: (s) => {
604
605
  return typeof opts.select === 'function'
605
- ? opts.select(s?.loaderData)
606
- : s?.loaderData
606
+ ? opts.select(s.loaderData)
607
+ : s.loaderData
607
608
  },
608
609
  })
609
610
  }
@@ -1,18 +1,24 @@
1
1
  import * as React from 'react'
2
2
  import { Matches } from './Matches'
3
- import { NavigateOptions, ToOptions } from './link'
4
- import { ParsedLocation } from './location'
5
- import { AnyRoute } from './route'
6
- import { RoutePaths } from './routeInfo'
7
- import { RegisteredRouter, Router, RouterOptions, RouterState } from './router'
8
3
  import { pick, useLayoutEffect } from './utils'
9
-
10
- import { RouteMatch } from './Matches'
11
4
  import { useRouter } from './useRouter'
12
5
  import { useRouterState } from './useRouterState'
13
6
  import { getRouterContext } from './routerContext'
7
+ import type { NavigateOptions, ToOptions } from './link'
8
+ import type { ParsedLocation } from './location'
9
+ import type { AnyRoute } from './route'
10
+ import type { RoutePaths } from './routeInfo'
11
+ import type {
12
+ RegisteredRouter,
13
+ Router,
14
+ RouterOptions,
15
+ RouterState,
16
+ } from './router'
17
+
18
+ import type { RouteMatch } from './Matches'
14
19
 
15
20
  const useTransition =
21
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
16
22
  React.useTransition ||
17
23
  (() => [
18
24
  false,
@@ -67,7 +73,7 @@ export function RouterProvider<
67
73
  ...rest,
68
74
  context: {
69
75
  ...router.options.context,
70
- ...rest?.context,
76
+ ...rest.context,
71
77
  },
72
78
  } as any)
73
79
 
@@ -114,7 +120,7 @@ function Transitioner() {
114
120
  isTransitioning,
115
121
  }))
116
122
  }
117
- }, [isTransitioning])
123
+ }, [isTransitioning, router])
118
124
 
119
125
  const tryLoad = () => {
120
126
  const apply = (cb: () => void) => {
@@ -157,14 +163,14 @@ function Transitioner() {
157
163
  return () => {
158
164
  unsub()
159
165
  }
160
- }, [router.history])
166
+ // eslint-disable-next-line react-hooks/exhaustive-deps
167
+ }, [router, router.history])
161
168
 
162
169
  useLayoutEffect(() => {
163
170
  if (
164
171
  (React.useTransition as any)
165
172
  ? routerState.isTransitioning && !isTransitioning
166
- : true &&
167
- !routerState.isLoading &&
173
+ : !routerState.isLoading &&
168
174
  routerState.resolvedLocation !== routerState.location
169
175
  ) {
170
176
  router.emit({
@@ -172,14 +178,12 @@ function Transitioner() {
172
178
  fromLocation: routerState.resolvedLocation,
173
179
  toLocation: routerState.location,
174
180
  pathChanged:
175
- routerState.location!.href !== routerState.resolvedLocation?.href,
181
+ routerState.location.href !== routerState.resolvedLocation.href,
176
182
  })
177
183
 
178
184
  if ((document as any).querySelector) {
179
185
  if (routerState.location.hash !== '') {
180
- const el = document.getElementById(
181
- routerState.location.hash,
182
- ) as HTMLElement | null
186
+ const el = document.getElementById(routerState.location.hash)
183
187
  if (el) {
184
188
  el.scrollIntoView()
185
189
  }
@@ -198,6 +202,7 @@ function Transitioner() {
198
202
  routerState.isLoading,
199
203
  routerState.resolvedLocation,
200
204
  routerState.location,
205
+ router,
201
206
  ])
202
207
 
203
208
  useLayoutEffect(() => {
@@ -210,6 +215,7 @@ function Transitioner() {
210
215
  }
211
216
  mountLoadForRouter.current = { router, mounted: true }
212
217
  tryLoad()
218
+ // eslint-disable-next-line react-hooks/exhaustive-deps
213
219
  }, [router])
214
220
 
215
221
  return null
package/src/awaited.tsx CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react'
2
+ import warning from 'tiny-warning'
2
3
  import { useRouter } from './useRouter'
3
4
  import { defaultSerializeError } from './router'
4
- import { DeferredPromise, isDehydratedDeferred } from './defer'
5
+ import { isDehydratedDeferred } from './defer'
5
6
  import { defaultDeserializeError, isServerSideError } from './Matches'
6
-
7
- import warning from 'tiny-warning'
7
+ import type { DeferredPromise } from './defer'
8
8
 
9
9
  export type AwaitOptions<T> = {
10
10
  promise: DeferredPromise<T>
package/src/defer.ts CHANGED
@@ -34,6 +34,7 @@ export function defer<T>(
34
34
  ) {
35
35
  const promise = _promise as DeferredPromise<T>
36
36
 
37
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
37
38
  if (!promise.__deferredState) {
38
39
  promise.__deferredState = {
39
40
  uid: Math.random().toString(36).slice(2),
package/src/fileRoute.ts CHANGED
@@ -1,33 +1,33 @@
1
- import { NoInfer } from '@tanstack/react-store'
2
- import { ParsePathParams } from './link'
3
- import {
1
+ import warning from 'tiny-warning'
2
+ import { RouteOptions, createRoute } from './route'
3
+ import { useLoaderData, useLoaderDeps, useMatch } from './Matches'
4
+ import { useSearch } from './useSearch'
5
+ import { useParams } from './useParams'
6
+ import type { ParsePathParams } from './link'
7
+ import type {
8
+ AnyContext,
9
+ AnyPathParams,
4
10
  AnyRoute,
11
+ AnySearchSchema,
12
+ FileBaseRouteOptions,
13
+ MergeFromFromParent,
5
14
  ResolveFullPath,
6
15
  ResolveFullSearchSchema,
7
- MergeFromFromParent,
8
- RouteContext,
9
- AnyContext,
10
- RouteOptions,
11
- UpdatableRouteOptions,
12
- Route,
13
- createRoute,
16
+ ResolveFullSearchSchemaInput,
14
17
  RootRouteId,
15
- TrimPathLeft,
18
+ Route,
16
19
  RouteConstraints,
17
- ResolveFullSearchSchemaInput,
18
- SearchSchemaInput,
20
+ RouteContext,
19
21
  RouteLoaderFn,
20
- AnyPathParams,
21
- AnySearchSchema,
22
- FileBaseRouteOptions,
22
+ SearchSchemaInput,
23
+ TrimPathLeft,
24
+ UpdatableRouteOptions,
23
25
  } from './route'
24
- import { Assign, Expand, IsAny } from './utils'
25
- import { useMatch, useLoaderDeps, useLoaderData, RouteMatch } from './Matches'
26
- import { useSearch } from './useSearch'
27
- import { useParams } from './useParams'
28
- import warning from 'tiny-warning'
29
- import { RegisteredRouter } from './router'
30
- import { RouteById, RouteIds } from './routeInfo'
26
+ import type { Assign, Expand, IsAny } from './utils'
27
+ import type { RouteMatch } from './Matches'
28
+ import type { NoInfer } from '@tanstack/react-store'
29
+ import type { RegisteredRouter } from './router'
30
+ import type { RouteById, RouteIds } from './routeInfo'
31
31
 
32
32
  export interface FileRoutesByPath {
33
33
  // '/': {
@@ -36,26 +36,26 @@ export interface FileRoutesByPath {
36
36
  }
37
37
 
38
38
  type Replace<
39
- S extends string,
40
- From extends string,
41
- To extends string,
42
- > = S extends `${infer Start}${From}${infer Rest}`
43
- ? `${Start}${To}${Replace<Rest, From, To>}`
44
- : S
39
+ TValue extends string,
40
+ TFrom extends string,
41
+ TTo extends string,
42
+ > = TValue extends `${infer Start}${TFrom}${infer Rest}`
43
+ ? `${Start}${TTo}${Replace<Rest, TFrom, TTo>}`
44
+ : TValue
45
45
 
46
46
  export type TrimLeft<
47
- T extends string,
48
- S extends string,
49
- > = T extends `${S}${infer U}` ? U : T
47
+ TValue extends string,
48
+ TStartsWith extends string,
49
+ > = TValue extends `${TStartsWith}${infer U}` ? U : TValue
50
50
 
51
51
  export type TrimRight<
52
- T extends string,
53
- S extends string,
54
- > = T extends `${infer U}${S}` ? U : T
52
+ TValue extends string,
53
+ TEndsWith extends string,
54
+ > = TValue extends `${infer U}${TEndsWith}` ? U : TValue
55
55
 
56
- export type Trim<T extends string, S extends string> = TrimLeft<
57
- TrimRight<T, S>,
58
- S
56
+ export type Trim<TValue extends string, TFind extends string> = TrimLeft<
57
+ TrimRight<TValue, TFind>,
58
+ TFind
59
59
  >
60
60
 
61
61
  export type RemoveUnderScores<T extends string> = Replace<
@@ -64,23 +64,23 @@ export type RemoveUnderScores<T extends string> = Replace<
64
64
  '/'
65
65
  >
66
66
 
67
- type RemoveRouteGroups<S extends string> =
68
- S extends `${infer Before}(${infer RouteGroup})${infer After}`
67
+ type RemoveRouteGroups<T extends string> =
68
+ T extends `${infer Before}(${infer RouteGroup})${infer After}`
69
69
  ? RemoveRouteGroups<`${Before}${After}`>
70
- : S
70
+ : T
71
71
 
72
- type NormalizeSlashes<S extends string> =
73
- S extends `${infer Before}//${infer After}`
72
+ type NormalizeSlashes<T extends string> =
73
+ T extends `${infer Before}//${infer After}`
74
74
  ? NormalizeSlashes<`${Before}/${After}`>
75
- : S
75
+ : T
76
76
 
77
77
  type ReplaceFirstOccurrence<
78
- T extends string,
79
- Search extends string,
80
- Replacement extends string,
81
- > = T extends `${infer Prefix}${Search}${infer Suffix}`
82
- ? `${Prefix}${Replacement}${Suffix}`
83
- : T
78
+ TValue extends string,
79
+ TSearch extends string,
80
+ TReplacement extends string,
81
+ > = TValue extends `${infer Prefix}${TSearch}${infer Suffix}`
82
+ ? `${Prefix}${TReplacement}${Suffix}`
83
+ : TValue
84
84
 
85
85
  export type ResolveFilePath<
86
86
  TParentRoute extends AnyRoute,
@@ -189,8 +189,8 @@ export class FileRoute<
189
189
  >,
190
190
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
191
191
  TLoaderDeps extends Record<string, any> = {},
192
- TLoaderDataReturn extends any = unknown,
193
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
192
+ TLoaderDataReturn = unknown,
193
+ TLoaderData = [TLoaderDataReturn] extends [never]
194
194
  ? undefined
195
195
  : TLoaderDataReturn,
196
196
  TChildren extends RouteConstraints['TChildren'] = unknown,
@@ -255,7 +255,7 @@ export function FileRouteLoader<
255
255
  TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
256
256
  >(
257
257
  _path: TFilePath,
258
- ): <TLoaderData extends any>(
258
+ ): <TLoaderData>(
259
259
  loaderFn: RouteLoaderFn<
260
260
  TRoute['types']['allParams'],
261
261
  TRoute['types']['loaderDeps'],
package/src/history.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HistoryLocation } from '@tanstack/history'
1
+ import type { HistoryLocation } from '@tanstack/history'
2
2
 
3
3
  declare module '@tanstack/history' {
4
4
  interface HistoryState {
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react'
2
- import { AsyncRouteComponent } from './route'
2
+ import type { AsyncRouteComponent } from './route'
3
3
 
4
4
  // If the load fails due to module not found, it may mean a new version of
5
5
  // the build was deployed and the user's browser is still using an old version.
@@ -27,6 +27,7 @@ export function lazyRouteComponent<
27
27
  }
28
28
 
29
29
  const load = () => {
30
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
30
31
  if (!loadPromise) {
31
32
  loadPromise = importer().catch((error) => {
32
33
  if (isModuleNotFoundError(error)) {