@tanstack/react-router 0.0.1-beta.224 → 0.0.1-beta.226
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/build/cjs/CatchBoundary.js +3 -6
- package/build/cjs/CatchBoundary.js.map +1 -1
- package/build/cjs/Matches.js +8 -15
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +6 -11
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -3
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/awaited.js +0 -2
- package/build/cjs/awaited.js.map +1 -1
- package/build/cjs/defer.js +0 -2
- package/build/cjs/defer.js.map +1 -1
- package/build/cjs/fileRoute.js +0 -2
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/index.js +3 -16
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/lazyRouteComponent.js +3 -6
- package/build/cjs/lazyRouteComponent.js.map +1 -1
- package/build/cjs/link.js +4 -7
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/path.js +0 -2
- package/build/cjs/path.js.map +1 -1
- package/build/cjs/qss.js +0 -2
- package/build/cjs/qss.js.map +1 -1
- package/build/cjs/redirects.js +0 -2
- package/build/cjs/redirects.js.map +1 -1
- package/build/cjs/route.js +2 -7
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +13 -15
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/scroll-restoration.js +3 -6
- package/build/cjs/scroll-restoration.js.map +1 -1
- package/build/cjs/searchParams.js +0 -2
- package/build/cjs/searchParams.js.map +1 -1
- package/build/cjs/useBlocker.js +3 -6
- package/build/cjs/useBlocker.js.map +1 -1
- package/build/cjs/useNavigate.js +3 -6
- package/build/cjs/useNavigate.js.map +1 -1
- package/build/cjs/useParams.js +0 -2
- package/build/cjs/useParams.js.map +1 -1
- package/build/cjs/useSearch.js +0 -2
- package/build/cjs/useSearch.js.map +1 -1
- package/build/cjs/utils.js +9 -6
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +18 -5
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +3494 -2700
- package/build/stats-react.json +290 -290
- package/build/types/CatchBoundary.d.ts +2 -2
- package/build/types/Matches.d.ts +3 -3
- package/build/types/RouterProvider.d.ts +2 -7
- package/build/types/awaited.d.ts +1 -0
- package/build/types/fileRoute.d.ts +3 -2
- package/build/types/route.d.ts +1 -1
- package/build/types/router.d.ts +7 -3
- package/build/umd/index.development.js +22 -11
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/RouterProvider.tsx +6 -8
- package/src/route.ts +37 -37
- package/src/router.ts +20 -13
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.
|
|
4
|
+
"version": "0.0.1-beta.226",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/runtime": "^7.16.7",
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
|
-
"@tanstack/history": "0.0.1-beta.
|
|
45
|
+
"@tanstack/history": "0.0.1-beta.226"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup --config rollup.config.js"
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -102,12 +102,6 @@ export type MatchRouteFn<TRouteTree extends AnyRoute> = <
|
|
|
102
102
|
opts?: MatchRouteOptions,
|
|
103
103
|
) => false | RouteById<TRouteTree, TResolved>['types']['allParams']
|
|
104
104
|
|
|
105
|
-
export type LoadFn = (opts?: {
|
|
106
|
-
next?: ParsedLocation
|
|
107
|
-
throwOnError?: boolean
|
|
108
|
-
__dehydratedMatches?: DehydratedRouteMatch[]
|
|
109
|
-
}) => Promise<void>
|
|
110
|
-
|
|
111
105
|
export type BuildLocationFn<TRouteTree extends AnyRoute> = (
|
|
112
106
|
opts: BuildNextOptions,
|
|
113
107
|
) => ParsedLocation
|
|
@@ -170,11 +164,15 @@ export function RouterProvider<
|
|
|
170
164
|
router.updateOptions({
|
|
171
165
|
...router.options,
|
|
172
166
|
...rest,
|
|
167
|
+
|
|
173
168
|
context: {
|
|
174
169
|
...router.options.context,
|
|
175
170
|
...rest?.context,
|
|
176
171
|
},
|
|
177
|
-
} as PickAsRequired<
|
|
172
|
+
} as PickAsRequired<
|
|
173
|
+
RouterOptions<TRouteTree, TDehydrated>,
|
|
174
|
+
'stringifySearch' | 'parseSearch' | 'context'
|
|
175
|
+
>)
|
|
178
176
|
|
|
179
177
|
const [preState, setState] = React.useState(() => router.state)
|
|
180
178
|
const [isTransitioning, startReactTransition] = React.useTransition()
|
|
@@ -222,7 +220,7 @@ export function RouterProvider<
|
|
|
222
220
|
return () => {
|
|
223
221
|
unsub()
|
|
224
222
|
}
|
|
225
|
-
}, [history])
|
|
223
|
+
}, [router.history])
|
|
226
224
|
|
|
227
225
|
React.useLayoutEffect(() => {
|
|
228
226
|
if (!isTransitioning && state.resolvedLocation !== state.location) {
|
package/src/route.ts
CHANGED
|
@@ -76,13 +76,11 @@ export type RouteOptions<
|
|
|
76
76
|
TAllContext,
|
|
77
77
|
TLoaderData
|
|
78
78
|
> &
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
TLoaderData
|
|
85
|
-
>
|
|
79
|
+
UpdatableRouteOptions<
|
|
80
|
+
NoInfer<TFullSearchSchema>,
|
|
81
|
+
NoInfer<TAllParams>,
|
|
82
|
+
NoInfer<TAllContext>,
|
|
83
|
+
NoInfer<TLoaderData>
|
|
86
84
|
>
|
|
87
85
|
|
|
88
86
|
export type ParamsFallback<
|
|
@@ -389,7 +387,8 @@ export class Route<
|
|
|
389
387
|
TPath
|
|
390
388
|
>,
|
|
391
389
|
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
392
|
-
TFullSearchSchema extends
|
|
390
|
+
TFullSearchSchema extends
|
|
391
|
+
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
393
392
|
TParentRoute,
|
|
394
393
|
TSearchSchema
|
|
395
394
|
>,
|
|
@@ -460,6 +459,7 @@ export class Route<
|
|
|
460
459
|
this.options = (options as any) || {}
|
|
461
460
|
this.isRoot = !options?.getParentRoute as any
|
|
462
461
|
Route.__onInit(this)
|
|
462
|
+
;(this as any).$$typeof = Symbol.for('react.memo')
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
types!: {
|
|
@@ -713,14 +713,14 @@ type RoutePrefix<
|
|
|
713
713
|
> = string extends TPath
|
|
714
714
|
? RootRouteId
|
|
715
715
|
: TPath extends string
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
716
|
+
? TPrefix extends RootRouteId
|
|
717
|
+
? TPath extends '/'
|
|
718
|
+
? '/'
|
|
719
|
+
: `/${TrimPath<TPath>}`
|
|
720
|
+
: `${TPrefix}/${TPath}` extends '/'
|
|
721
|
+
? '/'
|
|
722
|
+
: `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
|
|
723
|
+
: never
|
|
724
724
|
|
|
725
725
|
export type TrimPath<T extends string> = '' extends T
|
|
726
726
|
? ''
|
|
@@ -730,13 +730,13 @@ export type TrimPathLeft<T extends string> =
|
|
|
730
730
|
T extends `${RootRouteId}/${infer U}`
|
|
731
731
|
? TrimPathLeft<U>
|
|
732
732
|
: T extends `/${infer U}`
|
|
733
|
-
|
|
734
|
-
|
|
733
|
+
? TrimPathLeft<U>
|
|
734
|
+
: T
|
|
735
735
|
export type TrimPathRight<T extends string> = T extends '/'
|
|
736
736
|
? '/'
|
|
737
737
|
: T extends `${infer U}/`
|
|
738
|
-
|
|
739
|
-
|
|
738
|
+
? TrimPathRight<U>
|
|
739
|
+
: T
|
|
740
740
|
|
|
741
741
|
export type RouteMask<TRouteTree extends AnyRoute> = {
|
|
742
742
|
routeTree: TRouteTree
|
|
@@ -841,20 +841,20 @@ export type ComponentPropsFromRoute<TRoute> =
|
|
|
841
841
|
TRoute extends (() => infer T extends AnyRoute)
|
|
842
842
|
? ComponentPropsFromRoute<T>
|
|
843
843
|
: TRoute extends Route<
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
844
|
+
infer TParentRoute,
|
|
845
|
+
infer TPath,
|
|
846
|
+
infer TFullPath,
|
|
847
|
+
infer TCustomId,
|
|
848
|
+
infer TId,
|
|
849
|
+
infer TSearchSchema,
|
|
850
|
+
infer TFullSearchSchema,
|
|
851
|
+
infer TParams,
|
|
852
|
+
infer TAllParams,
|
|
853
|
+
infer TRouteContext,
|
|
854
|
+
infer TAllContext,
|
|
855
|
+
infer TRouterContext,
|
|
856
|
+
infer TLoaderData,
|
|
857
|
+
infer TChildren
|
|
858
|
+
>
|
|
859
|
+
? RouteProps<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>
|
|
860
|
+
: {}
|
package/src/router.ts
CHANGED
|
@@ -43,7 +43,6 @@ import {
|
|
|
43
43
|
BuildLocationFn,
|
|
44
44
|
CommitLocationOptions,
|
|
45
45
|
InjectedHtmlEntry,
|
|
46
|
-
LoadFn,
|
|
47
46
|
MatchRouteFn,
|
|
48
47
|
NavigateFn,
|
|
49
48
|
PathParamError,
|
|
@@ -679,8 +678,8 @@ export class Router<
|
|
|
679
678
|
let pathname = this.resolvePathWithBase(fromPathname, `${dest.to ?? ''}`)
|
|
680
679
|
|
|
681
680
|
const fromMatches = this.matchRoutes(fromPathname, from.search)
|
|
682
|
-
const stayingMatches = matches?.filter(
|
|
683
|
-
fromMatches?.find((e) => e.routeId === d.routeId),
|
|
681
|
+
const stayingMatches = matches?.filter(
|
|
682
|
+
(d) => fromMatches?.find((e) => e.routeId === d.routeId),
|
|
684
683
|
)
|
|
685
684
|
|
|
686
685
|
const prevParams = { ...last(fromMatches)?.params }
|
|
@@ -734,10 +733,10 @@ export class Router<
|
|
|
734
733
|
dest.search === true
|
|
735
734
|
? preFilteredSearch // Preserve resolvedFrom true
|
|
736
735
|
: dest.search
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
736
|
+
? functionalUpdate(dest.search, preFilteredSearch) ?? {} // Updater
|
|
737
|
+
: preSearchFilters?.length
|
|
738
|
+
? preFilteredSearch // Preserve resolvedFrom filters
|
|
739
|
+
: {}
|
|
741
740
|
|
|
742
741
|
// Then post filters
|
|
743
742
|
const postFilteredSearch = postSearchFilters?.length
|
|
@@ -752,8 +751,8 @@ export class Router<
|
|
|
752
751
|
dest.hash === true
|
|
753
752
|
? from.hash
|
|
754
753
|
: dest.hash
|
|
755
|
-
|
|
756
|
-
|
|
754
|
+
? functionalUpdate(dest.hash!, from.hash)
|
|
755
|
+
: from.hash
|
|
757
756
|
|
|
758
757
|
const hashStr = hash ? `#${hash}` : ''
|
|
759
758
|
|
|
@@ -761,8 +760,8 @@ export class Router<
|
|
|
761
760
|
dest.state === true
|
|
762
761
|
? from.state
|
|
763
762
|
: dest.state
|
|
764
|
-
|
|
765
|
-
|
|
763
|
+
? functionalUpdate(dest.state, from.state)
|
|
764
|
+
: from.state
|
|
766
765
|
|
|
767
766
|
nextState = replaceEqualDeep(from.state, nextState)
|
|
768
767
|
|
|
@@ -945,10 +944,12 @@ export class Router<
|
|
|
945
944
|
checkLatest,
|
|
946
945
|
matches,
|
|
947
946
|
preload,
|
|
947
|
+
invalidate,
|
|
948
948
|
}: {
|
|
949
949
|
checkLatest: () => Promise<void> | undefined
|
|
950
950
|
matches: AnyRouteMatch[]
|
|
951
951
|
preload?: boolean
|
|
952
|
+
invalidate?: boolean
|
|
952
953
|
}): Promise<RouteMatch[]> => {
|
|
953
954
|
let latestPromise
|
|
954
955
|
let firstBadMatchIndex: number | undefined
|
|
@@ -1086,7 +1087,7 @@ export class Router<
|
|
|
1086
1087
|
? route.options.shouldReload?.(loaderContext)
|
|
1087
1088
|
: !!(route.options.shouldReload ?? true)
|
|
1088
1089
|
|
|
1089
|
-
if (match.cause === 'enter') {
|
|
1090
|
+
if (match.cause === 'enter' || invalidate) {
|
|
1090
1091
|
match.shouldReloadDeps = shouldReloadDeps
|
|
1091
1092
|
} else if (match.cause === 'stay') {
|
|
1092
1093
|
if (typeof shouldReloadDeps === 'object') {
|
|
@@ -1192,7 +1193,12 @@ export class Router<
|
|
|
1192
1193
|
return matches
|
|
1193
1194
|
}
|
|
1194
1195
|
|
|
1195
|
-
|
|
1196
|
+
invalidate = () =>
|
|
1197
|
+
this.load({
|
|
1198
|
+
invalidate: true,
|
|
1199
|
+
})
|
|
1200
|
+
|
|
1201
|
+
load = async (opts?: { invalidate?: boolean }): Promise<void> => {
|
|
1196
1202
|
const promise = new Promise<void>(async (resolve, reject) => {
|
|
1197
1203
|
const next = this.latestLocation
|
|
1198
1204
|
const prevLocation = this.state.resolvedLocation
|
|
@@ -1236,6 +1242,7 @@ export class Router<
|
|
|
1236
1242
|
await this.loadMatches({
|
|
1237
1243
|
matches,
|
|
1238
1244
|
checkLatest: () => this.checkLatest(promise),
|
|
1245
|
+
invalidate: opts?.invalidate,
|
|
1239
1246
|
})
|
|
1240
1247
|
} catch (err) {
|
|
1241
1248
|
// swallow this error, since we'll display the
|