@tanstack/react-router 1.76.3 → 1.77.2
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/link.cjs +11 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -1
- package/dist/cjs/router.cjs +4 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +6 -6
- package/dist/esm/link.d.ts +1 -1
- package/dist/esm/link.js +12 -2
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.d.ts +6 -6
- package/dist/esm/router.js +4 -2
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/link.tsx +14 -2
- package/src/router.ts +11 -8
package/package.json
CHANGED
package/src/link.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
functionalUpdate,
|
|
10
10
|
useForwardedRef,
|
|
11
11
|
useIntersectionObserver,
|
|
12
|
+
useLayoutEffect,
|
|
12
13
|
} from './utils'
|
|
13
14
|
import { exactPathTest, removeTrailingSlash } from './path'
|
|
14
15
|
import type { ParsedLocation } from './location'
|
|
@@ -497,7 +498,7 @@ export interface LinkOptionsProps {
|
|
|
497
498
|
* - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.
|
|
498
499
|
* - `'viewport'` - Preload the linked route when it enters the viewport
|
|
499
500
|
*/
|
|
500
|
-
preload?: false | 'intent' | 'viewport'
|
|
501
|
+
preload?: false | 'intent' | 'viewport' | 'render'
|
|
501
502
|
/**
|
|
502
503
|
* When a preload strategy is set, this delays the preload by this many milliseconds.
|
|
503
504
|
* If the user exits the link before this delay, the preload will be cancelled.
|
|
@@ -589,6 +590,7 @@ export function useLinkProps<
|
|
|
589
590
|
): React.ComponentPropsWithRef<'a'> {
|
|
590
591
|
const router = useRouter()
|
|
591
592
|
const [isTransitioning, setIsTransitioning] = React.useState(false)
|
|
593
|
+
const hasRenderFetched = React.useRef(false)
|
|
592
594
|
const innerRef = useForwardedRef(forwardedRef)
|
|
593
595
|
|
|
594
596
|
const {
|
|
@@ -722,9 +724,19 @@ export function useLinkProps<
|
|
|
722
724
|
innerRef,
|
|
723
725
|
preloadViewportIoCallback,
|
|
724
726
|
{ rootMargin: '100px' },
|
|
725
|
-
{ disabled: !!disabled || preload
|
|
727
|
+
{ disabled: !!disabled || !(preload === 'viewport') },
|
|
726
728
|
)
|
|
727
729
|
|
|
730
|
+
useLayoutEffect(() => {
|
|
731
|
+
if (hasRenderFetched.current) {
|
|
732
|
+
return
|
|
733
|
+
}
|
|
734
|
+
if (!disabled && preload === 'render') {
|
|
735
|
+
doPreload()
|
|
736
|
+
hasRenderFetched.current = true
|
|
737
|
+
}
|
|
738
|
+
}, [disabled, doPreload, preload])
|
|
739
|
+
|
|
728
740
|
if (type === 'external') {
|
|
729
741
|
return {
|
|
730
742
|
...propsSafeToSpread,
|
package/src/router.ts
CHANGED
|
@@ -70,6 +70,7 @@ import type {
|
|
|
70
70
|
import type {
|
|
71
71
|
AnyRouteMatch,
|
|
72
72
|
MakeRouteMatch,
|
|
73
|
+
MakeRouteMatchUnion,
|
|
73
74
|
MatchRouteOptions,
|
|
74
75
|
} from './Matches'
|
|
75
76
|
import type { ParsedLocation } from './location'
|
|
@@ -211,7 +212,7 @@ export interface RouterOptions<
|
|
|
211
212
|
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreload-property)
|
|
212
213
|
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
|
|
213
214
|
*/
|
|
214
|
-
defaultPreload?: false | 'intent' | 'viewport'
|
|
215
|
+
defaultPreload?: false | 'intent' | 'viewport' | 'render'
|
|
215
216
|
/**
|
|
216
217
|
* The delay in milliseconds that a route must be hovered over or touched before it is preloaded.
|
|
217
218
|
*
|
|
@@ -1622,7 +1623,7 @@ export class Router<
|
|
|
1622
1623
|
})
|
|
1623
1624
|
|
|
1624
1625
|
if (foundMask) {
|
|
1625
|
-
const { from, ...maskProps } = foundMask
|
|
1626
|
+
const { from: _from, ...maskProps } = foundMask
|
|
1626
1627
|
maskedDest = {
|
|
1627
1628
|
...pick(opts, ['from']),
|
|
1628
1629
|
...maskProps,
|
|
@@ -2553,11 +2554,11 @@ export class Router<
|
|
|
2553
2554
|
return matches
|
|
2554
2555
|
}
|
|
2555
2556
|
|
|
2556
|
-
invalidate = (opts?: {
|
|
2557
|
-
filter?: (d:
|
|
2557
|
+
invalidate = <TRouter extends AnyRouter = RegisteredRouter>(opts?: {
|
|
2558
|
+
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean
|
|
2558
2559
|
}) => {
|
|
2559
2560
|
const invalidate = (d: MakeRouteMatch<TRouteTree>) => {
|
|
2560
|
-
if (opts?.filter?.(d) ?? true) {
|
|
2561
|
+
if (opts?.filter?.(d as MakeRouteMatchUnion<TRouter>) ?? true) {
|
|
2561
2562
|
return {
|
|
2562
2563
|
...d,
|
|
2563
2564
|
invalid: true,
|
|
@@ -2589,15 +2590,17 @@ export class Router<
|
|
|
2589
2590
|
return redirect
|
|
2590
2591
|
}
|
|
2591
2592
|
|
|
2592
|
-
clearCache = (opts?: {
|
|
2593
|
-
filter?: (d:
|
|
2593
|
+
clearCache = <TRouter extends AnyRouter = RegisteredRouter>(opts?: {
|
|
2594
|
+
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean
|
|
2594
2595
|
}) => {
|
|
2595
2596
|
const filter = opts?.filter
|
|
2596
2597
|
if (filter !== undefined) {
|
|
2597
2598
|
this.__store.setState((s) => {
|
|
2598
2599
|
return {
|
|
2599
2600
|
...s,
|
|
2600
|
-
cachedMatches: s.cachedMatches.filter(
|
|
2601
|
+
cachedMatches: s.cachedMatches.filter(
|
|
2602
|
+
(m) => !filter(m as MakeRouteMatchUnion<TRouter>),
|
|
2603
|
+
),
|
|
2601
2604
|
}
|
|
2602
2605
|
})
|
|
2603
2606
|
} else {
|