@tanstack/react-router 1.15.14 → 1.15.15

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/src/link.tsx CHANGED
@@ -448,25 +448,24 @@ export function useLinkProps<
448
448
  }
449
449
  }
450
450
 
451
- // The click handler
452
- const handleFocus = (e: MouseEvent) => {
453
- if (preload) {
451
+ const doPreload = () => {
452
+ React.startTransition(() => {
454
453
  router.preloadRoute(dest as any).catch((err) => {
455
454
  console.warn(err)
456
455
  console.warn(preloadWarning)
457
456
  })
458
- }
457
+ })
459
458
  }
460
459
 
461
- const handleTouchStart = (e: TouchEvent) => {
460
+ // The click handler
461
+ const handleFocus = (e: MouseEvent) => {
462
462
  if (preload) {
463
- router.preloadRoute(dest as any).catch((err) => {
464
- console.warn(err)
465
- console.warn(preloadWarning)
466
- })
463
+ doPreload()
467
464
  }
468
465
  }
469
466
 
467
+ const handleTouchStart = handleFocus
468
+
470
469
  const handleEnter = (e: MouseEvent) => {
471
470
  const target = (e.target || {}) as LinkCurrentTargetElement
472
471
 
@@ -477,10 +476,7 @@ export function useLinkProps<
477
476
 
478
477
  target.preloadTimeout = setTimeout(() => {
479
478
  target.preloadTimeout = null
480
- router.preloadRoute(dest as any).catch((err) => {
481
- console.warn(err)
482
- console.warn(preloadWarning)
483
- })
479
+ doPreload()
484
480
  }, preloadDelay)
485
481
  }
486
482
  }
package/src/route.ts CHANGED
@@ -220,6 +220,9 @@ export type UpdatableRouteOptions<
220
220
  | Promise<JSX.IntrinsicElements['meta'][]>
221
221
  links?: () => JSX.IntrinsicElements['link'][]
222
222
  scripts?: () => JSX.IntrinsicElements['script'][]
223
+ headers?: (ctx: {
224
+ loaderData: TLoaderData
225
+ }) => Promise<Record<string, string>> | Record<string, string>
223
226
  } & UpdatableStaticRouteOption
224
227
 
225
228
  export type UpdatableStaticRouteOption =
package/src/router.ts CHANGED
@@ -67,6 +67,14 @@ import { isRedirect } from './redirects'
67
67
  import { NotFoundError, isNotFound } from './not-found'
68
68
  import { ResolveRelativePath, ToOptions } from './link'
69
69
  import { NoInfer } from '@tanstack/react-store'
70
+ import warning from 'tiny-warning'
71
+ import {
72
+ DeferredPromise,
73
+ DeferredPromiseState,
74
+ defaultDeserializeError,
75
+ isDehydratedDeferred,
76
+ isServerSideError,
77
+ } from '.'
70
78
  // import warning from 'tiny-warning'
71
79
 
72
80
  //
@@ -304,6 +312,10 @@ export class Router<
304
312
  parseSearch: options?.parseSearch ?? defaultParseSearch,
305
313
  transformer: options?.transformer ?? JSON,
306
314
  })
315
+
316
+ if (typeof document !== 'undefined') {
317
+ ;(window as any).__TSR__ROUTER__ = this
318
+ }
307
319
  }
308
320
 
309
321
  // These are default implementations that can optionally be overridden
@@ -719,6 +731,7 @@ export class Router<
719
731
  path: route.fullPath,
720
732
  params: routeParams,
721
733
  })
734
+
722
735
  const matchId =
723
736
  interpolatePath({
724
737
  path: route.id,
@@ -743,7 +756,7 @@ export class Router<
743
756
  isGlobalNotFound && route.id === rootRouteId
744
757
  ? { global: true }
745
758
  : undefined,
746
- params: replaceEqualDeep(existingMatch.params, routeParams),
759
+ params: routeParams,
747
760
  }
748
761
  : {
749
762
  id: matchId,
@@ -1707,7 +1720,30 @@ export class Router<
1707
1720
  this.injectedHtml.push(html)
1708
1721
  }
1709
1722
 
1723
+ // We use a token -> weak map to keep track of deferred promises
1724
+ // that are registered on the server and need to be resolved
1725
+ registeredDeferredsIds = new Map<string, {}>()
1726
+ registeredDeferreds = new WeakMap<{}, DeferredPromiseState<any>>()
1727
+
1728
+ getDeferred = (uid: string) => {
1729
+ const token = this.registeredDeferredsIds.get(uid)
1730
+
1731
+ if (!token) {
1732
+ return undefined
1733
+ }
1734
+
1735
+ return this.registeredDeferreds.get(token)
1736
+ }
1737
+
1738
+ /**
1739
+ * @deprecated Please inject your own html using the `injectHtml` method
1740
+ */
1710
1741
  dehydrateData = <T>(key: any, getData: T | (() => Promise<T> | T)) => {
1742
+ warning(
1743
+ false,
1744
+ `The dehydrateData method is deprecated. Please use the injectHtml method to inject your own data.`,
1745
+ )
1746
+
1711
1747
  if (typeof document === 'undefined') {
1712
1748
  const strKey = typeof key === 'string' ? key : JSON.stringify(key)
1713
1749
 
@@ -1728,7 +1764,15 @@ export class Router<
1728
1764
  return () => undefined
1729
1765
  }
1730
1766
 
1767
+ /**
1768
+ * @deprecated Please extract your own data from scripts injected using the `injectHtml` method
1769
+ */
1731
1770
  hydrateData = <T extends any = unknown>(key: any) => {
1771
+ warning(
1772
+ false,
1773
+ `The hydrateData method is deprecated. Please use the extractHtml method to extract your own data.`,
1774
+ )
1775
+
1732
1776
  if (typeof document !== 'undefined') {
1733
1777
  const strKey = typeof key === 'string' ? key : JSON.stringify(key)
1734
1778