@tanstack/react-router 1.22.5 → 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.
- package/dist/cjs/CatchBoundary.cjs +1 -2
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +12 -18
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +15 -15
- package/dist/cjs/RouterProvider.cjs +16 -15
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +6 -6
- package/dist/cjs/awaited.cjs +1 -1
- package/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/awaited.d.cts +1 -1
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +17 -17
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
- package/dist/cjs/lazyRouteComponent.d.cts +1 -1
- package/dist/cjs/link.cjs +10 -11
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +16 -13
- package/dist/cjs/location.d.cts +2 -2
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +2 -2
- package/dist/cjs/path.cjs +2 -2
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +4 -4
- package/dist/cjs/qss.cjs +4 -3
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +5 -5
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +34 -36
- package/dist/cjs/routeInfo.d.cts +5 -5
- package/dist/cjs/router.cjs +63 -66
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +28 -28
- package/dist/cjs/routerContext.cjs +1 -1
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerContext.d.cts +1 -1
- package/dist/cjs/scroll-restoration.cjs +7 -9
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -1
- package/dist/cjs/searchParams.cjs +10 -12
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/searchParams.d.cts +1 -1
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +2 -2
- package/dist/cjs/useNavigate.cjs +1 -1
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +4 -4
- package/dist/cjs/useParams.cjs +1 -1
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +5 -5
- package/dist/cjs/useRouteContext.cjs +1 -1
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +4 -4
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouter.d.cts +2 -2
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useRouterState.d.cts +2 -2
- package/dist/cjs/useSearch.cjs +1 -1
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +4 -4
- package/dist/cjs/utils.cjs +2 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +13 -11
- package/dist/esm/CatchBoundary.js +1 -2
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/Matches.d.ts +15 -15
- package/dist/esm/Matches.js +12 -18
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +6 -6
- package/dist/esm/RouterProvider.js +16 -15
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/awaited.d.ts +1 -1
- package/dist/esm/awaited.js +1 -1
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +17 -17
- package/dist/esm/fileRoute.js +1 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/lazyRouteComponent.d.ts +1 -1
- package/dist/esm/lazyRouteComponent.js.map +1 -1
- package/dist/esm/link.d.ts +16 -13
- package/dist/esm/link.js +10 -11
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/location.d.ts +2 -2
- package/dist/esm/not-found.d.ts +2 -2
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/path.d.ts +4 -4
- package/dist/esm/path.js +2 -2
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/qss.js +4 -3
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/redirects.d.ts +5 -5
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +34 -36
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +5 -5
- package/dist/esm/router.d.ts +28 -28
- package/dist/esm/router.js +63 -66
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -1
- package/dist/esm/routerContext.js +1 -1
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -1
- package/dist/esm/scroll-restoration.js +7 -9
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchParams.d.ts +1 -1
- package/dist/esm/searchParams.js +10 -12
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/useBlocker.d.ts +2 -2
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +4 -4
- package/dist/esm/useNavigate.js +1 -1
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +5 -5
- package/dist/esm/useParams.js +1 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +4 -4
- package/dist/esm/useRouteContext.js +1 -1
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.d.ts +2 -2
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.d.ts +2 -2
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.d.ts +4 -4
- package/dist/esm/useSearch.js +1 -1
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +13 -11
- package/dist/esm/utils.js +2 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/CatchBoundary.tsx +1 -1
- package/src/Matches.tsx +41 -48
- package/src/RouterProvider.tsx +22 -16
- package/src/awaited.tsx +3 -3
- package/src/defer.ts +1 -0
- package/src/fileRoute.ts +53 -53
- package/src/history.ts +1 -1
- package/src/lazyRouteComponent.tsx +2 -1
- package/src/link.tsx +50 -42
- package/src/location.ts +2 -2
- package/src/not-found.tsx +3 -2
- package/src/path.ts +8 -8
- package/src/qss.ts +4 -5
- package/src/redirects.ts +5 -5
- package/src/route.ts +73 -67
- package/src/routeInfo.ts +8 -6
- package/src/router.ts +150 -145
- package/src/routerContext.tsx +2 -2
- package/src/scroll-restoration.tsx +9 -12
- package/src/searchParams.ts +11 -13
- package/src/useBlocker.tsx +3 -3
- package/src/useNavigate.tsx +7 -5
- package/src/useParams.tsx +6 -6
- package/src/useRouteContext.ts +7 -8
- package/src/useRouter.tsx +2 -2
- package/src/useRouterState.tsx +2 -2
- package/src/useSearch.tsx +7 -6
- 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 {
|
|
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
|
|
@@ -90,13 +84,13 @@ export function Matches() {
|
|
|
90
84
|
})
|
|
91
85
|
|
|
92
86
|
const resetKey = useRouterState({
|
|
93
|
-
select: (s) => s.resolvedLocation.state
|
|
87
|
+
select: (s) => s.resolvedLocation.state.key!,
|
|
94
88
|
})
|
|
95
89
|
|
|
96
90
|
return (
|
|
97
91
|
<matchContext.Provider value={matchId}>
|
|
98
92
|
<CatchBoundary
|
|
99
|
-
getResetKey={() =>
|
|
93
|
+
getResetKey={() => router.state.resolvedLocation.state.key!}
|
|
100
94
|
errorComponent={ErrorComponent}
|
|
101
95
|
onCatch={(error) => {
|
|
102
96
|
warning(
|
|
@@ -130,8 +124,8 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
130
124
|
|
|
131
125
|
const route = router.routesById[routeId]!
|
|
132
126
|
|
|
133
|
-
const PendingComponent =
|
|
134
|
-
router.options.defaultPendingComponent
|
|
127
|
+
const PendingComponent =
|
|
128
|
+
route.options.pendingComponent ?? router.options.defaultPendingComponent
|
|
135
129
|
|
|
136
130
|
const pendingElement = PendingComponent ? <PendingComponent /> : null
|
|
137
131
|
|
|
@@ -149,7 +143,7 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
149
143
|
PendingComponent ??
|
|
150
144
|
route.options.component?.preload ??
|
|
151
145
|
route.options.pendingComponent?.preload ??
|
|
152
|
-
|
|
146
|
+
route.options.errorComponent?.preload
|
|
153
147
|
? React.Suspense
|
|
154
148
|
: SafeFragment
|
|
155
149
|
|
|
@@ -162,7 +156,7 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
162
156
|
: SafeFragment
|
|
163
157
|
|
|
164
158
|
const resetKey = useRouterState({
|
|
165
|
-
select: (s) => s.resolvedLocation.state
|
|
159
|
+
select: (s) => s.resolvedLocation.state.key!,
|
|
166
160
|
})
|
|
167
161
|
|
|
168
162
|
return (
|
|
@@ -192,7 +186,7 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
192
186
|
return React.createElement(routeNotFoundComponent, error as any)
|
|
193
187
|
}}
|
|
194
188
|
>
|
|
195
|
-
<MatchInner matchId={matchId
|
|
189
|
+
<MatchInner matchId={matchId} pendingElement={pendingElement} />
|
|
196
190
|
</ResolvedNotFoundBoundary>
|
|
197
191
|
</ResolvedCatchBoundary>
|
|
198
192
|
</ResolvedSuspenseBoundary>
|
|
@@ -291,8 +285,9 @@ function MatchInner({
|
|
|
291
285
|
throw match.loadPromise
|
|
292
286
|
}
|
|
293
287
|
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
294
289
|
if (match.status === 'success') {
|
|
295
|
-
|
|
290
|
+
const Comp = route.options.component ?? router.options.defaultComponent
|
|
296
291
|
|
|
297
292
|
if (Comp) {
|
|
298
293
|
return <Comp />
|
|
@@ -382,16 +377,16 @@ export type UseMatchRouteOptions<
|
|
|
382
377
|
TTo extends string = '',
|
|
383
378
|
TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
|
|
384
379
|
TMaskTo extends string = '',
|
|
385
|
-
|
|
380
|
+
TOptions extends ToOptions<
|
|
386
381
|
TRouteTree,
|
|
387
382
|
TFrom,
|
|
388
383
|
TTo,
|
|
389
384
|
TMaskFrom,
|
|
390
385
|
TMaskTo
|
|
391
386
|
> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
392
|
-
|
|
393
|
-
DeepPartial<Pick<
|
|
394
|
-
> =
|
|
387
|
+
TRelaxedOptions = Omit<TOptions, 'search' | 'params'> &
|
|
388
|
+
DeepPartial<Pick<TOptions, 'search' | 'params'>>,
|
|
389
|
+
> = TRelaxedOptions & MatchRouteOptions
|
|
395
390
|
|
|
396
391
|
export function useMatchRoute<
|
|
397
392
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
@@ -455,7 +450,7 @@ export function MatchRoute<
|
|
|
455
450
|
return (props.children as any)(params)
|
|
456
451
|
}
|
|
457
452
|
|
|
458
|
-
return
|
|
453
|
+
return params ? props.children : null
|
|
459
454
|
}
|
|
460
455
|
|
|
461
456
|
export function getRenderedMatches<
|
|
@@ -482,19 +477,17 @@ export function useMatch<
|
|
|
482
477
|
const matchSelection = useRouterState({
|
|
483
478
|
select: (state) => {
|
|
484
479
|
const match = getRenderedMatches(state).find((d) =>
|
|
485
|
-
opts
|
|
480
|
+
opts.from ? opts.from === d.routeId : d.id === nearestMatchId,
|
|
486
481
|
)
|
|
487
482
|
|
|
488
483
|
invariant(
|
|
489
484
|
match,
|
|
490
485
|
`Could not find ${
|
|
491
|
-
opts
|
|
492
|
-
? `an active match from "${opts.from}"`
|
|
493
|
-
: 'a nearest match!'
|
|
486
|
+
opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'
|
|
494
487
|
}`,
|
|
495
488
|
)
|
|
496
489
|
|
|
497
|
-
return opts
|
|
490
|
+
return opts.select ? opts.select(match as any) : match
|
|
498
491
|
},
|
|
499
492
|
})
|
|
500
493
|
|
|
@@ -506,16 +499,16 @@ export function useMatches<
|
|
|
506
499
|
TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
507
500
|
TReturnIntersection extends boolean = false,
|
|
508
501
|
TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,
|
|
509
|
-
T = TRouteMatch
|
|
502
|
+
T = Array<TRouteMatch>,
|
|
510
503
|
>(opts?: {
|
|
511
|
-
select?: (matches: TRouteMatch
|
|
504
|
+
select?: (matches: Array<TRouteMatch>) => T
|
|
512
505
|
experimental_returnIntersection?: TReturnIntersection
|
|
513
506
|
}): T {
|
|
514
507
|
return useRouterState({
|
|
515
508
|
select: (state) => {
|
|
516
509
|
const matches = getRenderedMatches(state)
|
|
517
510
|
return opts?.select
|
|
518
|
-
? opts.select(matches as TRouteMatch
|
|
511
|
+
? opts.select(matches as Array<TRouteMatch>)
|
|
519
512
|
: (matches as T)
|
|
520
513
|
},
|
|
521
514
|
})
|
|
@@ -526,9 +519,9 @@ export function useParentMatches<
|
|
|
526
519
|
TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
527
520
|
TReturnIntersection extends boolean = false,
|
|
528
521
|
TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,
|
|
529
|
-
T = TRouteMatch
|
|
522
|
+
T = Array<TRouteMatch>,
|
|
530
523
|
>(opts?: {
|
|
531
|
-
select?: (matches: TRouteMatch
|
|
524
|
+
select?: (matches: Array<TRouteMatch>) => T
|
|
532
525
|
experimental_returnIntersection?: TReturnIntersection
|
|
533
526
|
}): T {
|
|
534
527
|
const contextMatchId = React.useContext(matchContext)
|
|
@@ -540,7 +533,7 @@ export function useParentMatches<
|
|
|
540
533
|
matches.findIndex((d) => d.id === contextMatchId),
|
|
541
534
|
)
|
|
542
535
|
return opts?.select
|
|
543
|
-
? opts.select(matches as TRouteMatch
|
|
536
|
+
? opts.select(matches as Array<TRouteMatch>)
|
|
544
537
|
: (matches as T)
|
|
545
538
|
},
|
|
546
539
|
})
|
|
@@ -551,9 +544,9 @@ export function useChildMatches<
|
|
|
551
544
|
TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
552
545
|
TReturnIntersection extends boolean = false,
|
|
553
546
|
TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,
|
|
554
|
-
T = TRouteMatch
|
|
547
|
+
T = Array<TRouteMatch>,
|
|
555
548
|
>(opts?: {
|
|
556
|
-
select?: (matches: TRouteMatch
|
|
549
|
+
select?: (matches: Array<TRouteMatch>) => T
|
|
557
550
|
experimental_returnIntersection?: TReturnIntersection
|
|
558
551
|
}): T {
|
|
559
552
|
const contextMatchId = React.useContext(matchContext)
|
|
@@ -564,7 +557,7 @@ export function useChildMatches<
|
|
|
564
557
|
matches.findIndex((d) => d.id === contextMatchId) + 1,
|
|
565
558
|
)
|
|
566
559
|
return opts?.select
|
|
567
|
-
? opts.select(matches as TRouteMatch
|
|
560
|
+
? opts.select(matches as Array<TRouteMatch>)
|
|
568
561
|
: (matches as T)
|
|
569
562
|
},
|
|
570
563
|
})
|
|
@@ -587,8 +580,8 @@ export function useLoaderDeps<
|
|
|
587
580
|
...opts,
|
|
588
581
|
select: (s) => {
|
|
589
582
|
return typeof opts.select === 'function'
|
|
590
|
-
? opts.select(s
|
|
591
|
-
: s
|
|
583
|
+
? opts.select(s.loaderDeps)
|
|
584
|
+
: s.loaderDeps
|
|
592
585
|
},
|
|
593
586
|
})
|
|
594
587
|
}
|
|
@@ -610,8 +603,8 @@ export function useLoaderData<
|
|
|
610
603
|
...opts,
|
|
611
604
|
select: (s) => {
|
|
612
605
|
return typeof opts.select === 'function'
|
|
613
|
-
? opts.select(s
|
|
614
|
-
: s
|
|
606
|
+
? opts.select(s.loaderData)
|
|
607
|
+
: s.loaderData
|
|
615
608
|
},
|
|
616
609
|
})
|
|
617
610
|
}
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
:
|
|
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
|
|
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 {
|
|
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
|
|
2
|
-
import {
|
|
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
|
-
|
|
8
|
-
RouteContext,
|
|
9
|
-
AnyContext,
|
|
10
|
-
RouteOptions,
|
|
11
|
-
UpdatableRouteOptions,
|
|
12
|
-
Route,
|
|
13
|
-
createRoute,
|
|
16
|
+
ResolveFullSearchSchemaInput,
|
|
14
17
|
RootRouteId,
|
|
15
|
-
|
|
18
|
+
Route,
|
|
16
19
|
RouteConstraints,
|
|
17
|
-
|
|
18
|
-
SearchSchemaInput,
|
|
20
|
+
RouteContext,
|
|
19
21
|
RouteLoaderFn,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
SearchSchemaInput,
|
|
23
|
+
TrimPathLeft,
|
|
24
|
+
UpdatableRouteOptions,
|
|
23
25
|
} from './route'
|
|
24
|
-
import { Assign, Expand, IsAny } from './utils'
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
> =
|
|
43
|
-
? `${Start}${
|
|
44
|
-
:
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
> =
|
|
47
|
+
TValue extends string,
|
|
48
|
+
TStartsWith extends string,
|
|
49
|
+
> = TValue extends `${TStartsWith}${infer U}` ? U : TValue
|
|
50
50
|
|
|
51
51
|
export type TrimRight<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
> =
|
|
52
|
+
TValue extends string,
|
|
53
|
+
TEndsWith extends string,
|
|
54
|
+
> = TValue extends `${infer U}${TEndsWith}` ? U : TValue
|
|
55
55
|
|
|
56
|
-
export type Trim<
|
|
57
|
-
TrimRight<
|
|
58
|
-
|
|
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<
|
|
68
|
-
|
|
67
|
+
type RemoveRouteGroups<T extends string> =
|
|
68
|
+
T extends `${infer Before}(${infer RouteGroup})${infer After}`
|
|
69
69
|
? RemoveRouteGroups<`${Before}${After}`>
|
|
70
|
-
:
|
|
70
|
+
: T
|
|
71
71
|
|
|
72
|
-
type NormalizeSlashes<
|
|
73
|
-
|
|
72
|
+
type NormalizeSlashes<T extends string> =
|
|
73
|
+
T extends `${infer Before}//${infer After}`
|
|
74
74
|
? NormalizeSlashes<`${Before}/${After}`>
|
|
75
|
-
:
|
|
75
|
+
: T
|
|
76
76
|
|
|
77
77
|
type ReplaceFirstOccurrence<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
> =
|
|
82
|
-
? `${Prefix}${
|
|
83
|
-
:
|
|
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
|
|
193
|
-
TLoaderData
|
|
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
|
|
258
|
+
): <TLoaderData>(
|
|
259
259
|
loaderFn: RouteLoaderFn<
|
|
260
260
|
TRoute['types']['allParams'],
|
|
261
261
|
TRoute['types']['loaderDeps'],
|
package/src/history.ts
CHANGED
|
@@ -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)) {
|