@tanstack/react-router 1.76.3 → 1.77.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.76.3",
3
+ "version": "1.77.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
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 !== 'viewport' },
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
@@ -211,7 +211,7 @@ export interface RouterOptions<
211
211
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreload-property)
212
212
  * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
213
213
  */
214
- defaultPreload?: false | 'intent' | 'viewport'
214
+ defaultPreload?: false | 'intent' | 'viewport' | 'render'
215
215
  /**
216
216
  * The delay in milliseconds that a route must be hovered over or touched before it is preloaded.
217
217
  *
@@ -1622,7 +1622,7 @@ export class Router<
1622
1622
  })
1623
1623
 
1624
1624
  if (foundMask) {
1625
- const { from, ...maskProps } = foundMask
1625
+ const { from: _from, ...maskProps } = foundMask
1626
1626
  maskedDest = {
1627
1627
  ...pick(opts, ['from']),
1628
1628
  ...maskProps,