@tanstack/react-router 1.166.3 → 1.166.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.
@@ -2001,7 +2001,7 @@ To control router dependencies and "freshness", TanStack Router provides a pleth
2001
2001
 
2002
2002
  ### ⚠️ Some Important Defaults
2003
2003
 
2004
- - By default, the \`staleTime\` is set to \`0\`, meaning that the route's data will always be considered stale and will always be reloaded in the background when the route is rematched.
2004
+ - By default, the \`staleTime\` is set to \`0\`, meaning that the route's data is immediately considered stale. Stale matches are reloaded in the background when the route is entered again, when its loader key changes (path params used by the route or \`loaderDeps\`), or when \`router.load()\` is called explicitly.
2005
2005
  - By default, a previously preloaded route is considered fresh for **30 seconds**. This means if a route is preloaded, then preloaded again within 30 seconds, the second preload will be ignored. This prevents unnecessary preloads from happening too frequently. **When a route is loaded normally, the standard \`staleTime\` is used.**
2006
2006
  - By default, the \`gcTime\` is set to **30 minutes**, meaning that any route data that has not been accessed in 30 minutes will be garbage collected and removed from the cache.
2007
2007
  - \`router.invalidate()\` will force all active routes to reload their loaders immediately and mark every cached route's data as stale.
@@ -2048,7 +2048,7 @@ export const Route = createFileRoute('/posts')({
2048
2048
 
2049
2049
  ### Using \`staleTime\` to control how long data is considered fresh
2050
2050
 
2051
- By default, \`staleTime\` for navigations is set to \`0\`ms (and 30 seconds for preloads) which means that the route's data will always be considered stale and will always be reloaded in the background when the route is matched and navigated to.
2051
+ By default, \`staleTime\` for navigations is set to \`0\`ms (and 30 seconds for preloads) which means that the route's data will always be considered stale. When a stale route is entered again, its loader key changes, or \`router.load()\` is called explicitly, the route will reload in the background.
2052
2052
 
2053
2053
  **This is a good default for most use cases, but you may find that some route data is more static or potentially expensive to load.** In these cases, you can use the \`staleTime\` option to control how long the route's data is considered fresh for navigations. Let's take a look at an example:
2054
2054
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.166.3",
3
+ "version": "1.166.6",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -82,7 +82,7 @@
82
82
  "tiny-invariant": "^1.3.3",
83
83
  "tiny-warning": "^1.0.3",
84
84
  "@tanstack/history": "1.161.4",
85
- "@tanstack/router-core": "1.166.2"
85
+ "@tanstack/router-core": "1.166.6"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@testing-library/jest-dom": "^6.6.3",
package/src/fileRoute.ts CHANGED
@@ -8,6 +8,7 @@ import { useSearch } from './useSearch'
8
8
  import { useParams } from './useParams'
9
9
  import { useNavigate } from './useNavigate'
10
10
  import { useRouter } from './useRouter'
11
+ import { useRouteContext } from './useRouteContext'
11
12
  import type { UseParamsRoute } from './useParams'
12
13
  import type { UseMatchRoute } from './useMatch'
13
14
  import type { UseSearchRoute } from './useSearch'
@@ -229,10 +230,7 @@ export class LazyRoute<TRoute extends AnyRoute> {
229
230
  }
230
231
 
231
232
  useRouteContext: UseRouteContextRoute<TRoute['id']> = (opts) => {
232
- return useMatch({
233
- from: this.options.id,
234
- select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
235
- }) as any
233
+ return useRouteContext({ ...(opts as any), from: this.options.id })
236
234
  }
237
235
 
238
236
  useSearch: UseSearchRoute<TRoute['id']> = (opts) => {
package/src/route.tsx CHANGED
@@ -11,6 +11,7 @@ import { useParams } from './useParams'
11
11
  import { useSearch } from './useSearch'
12
12
  import { useNavigate } from './useNavigate'
13
13
  import { useMatch } from './useMatch'
14
+ import { useRouteContext } from './useRouteContext'
14
15
  import { useRouter } from './useRouter'
15
16
  import { Link } from './link'
16
17
  import type {
@@ -114,10 +115,7 @@ export class RouteApi<
114
115
  }
115
116
 
116
117
  useRouteContext: UseRouteContextRoute<TId> = (opts) => {
117
- return useMatch({
118
- from: this.id as any,
119
- select: (d) => (opts?.select ? opts.select(d.context) : d.context),
120
- }) as any
118
+ return useRouteContext({ ...(opts as any), from: this.id as any })
121
119
  }
122
120
 
123
121
  useSearch: UseSearchRoute<TId> = (opts) => {
@@ -272,11 +270,7 @@ export class Route<
272
270
  }
273
271
 
274
272
  useRouteContext: UseRouteContextRoute<TId> = (opts?) => {
275
- return useMatch({
276
- ...opts,
277
- from: this.id,
278
- select: (d) => (opts?.select ? opts.select(d.context) : d.context),
279
- }) as any
273
+ return useRouteContext({ ...(opts as any), from: this.id })
280
274
  }
281
275
 
282
276
  useSearch: UseSearchRoute<TId> = (opts) => {
@@ -548,11 +542,7 @@ export class RootRoute<
548
542
  }
549
543
 
550
544
  useRouteContext: UseRouteContextRoute<RootRouteId> = (opts) => {
551
- return useMatch({
552
- ...opts,
553
- from: this.id,
554
- select: (d) => (opts?.select ? opts.select(d.context) : d.context),
555
- }) as any
545
+ return useRouteContext({ ...(opts as any), from: this.id })
556
546
  }
557
547
 
558
548
  useSearch: UseSearchRoute<RootRouteId> = (opts) => {