@depup/tanstack__react-router 1.166.8-depup.0 → 1.167.0-depup.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.
@@ -1904,7 +1904,7 @@ The router cache is built-in and is as easy as returning data from any route's \
1904
1904
 
1905
1905
  ## Route \`loader\`s
1906
1906
 
1907
- Route \`loader\` functions are called when a route match is loaded. They are called with a single parameter which is an object containing many helpful properties. We'll go over those in a bit, but first, let's look at an example of a route \`loader\` function:
1907
+ Route \`loader\` functions are called when a route match is loaded. They are called with a single parameter which is an object containing many helpful properties. We'll go over those in a bit, but first, let's look at the two supported \`loader\` forms:
1908
1908
 
1909
1909
  \`\`\`tsx
1910
1910
  // src/routes/posts.tsx
@@ -1913,6 +1913,17 @@ export const Route = createFileRoute('/posts')({
1913
1913
  })
1914
1914
  \`\`\`
1915
1915
 
1916
+ \`\`\`tsx
1917
+ // src/routes/posts.tsx
1918
+ export const Route = createFileRoute('/posts')({
1919
+ loader: {
1920
+ handler: () => fetchPosts(),
1921
+ },
1922
+ })
1923
+ \`\`\`
1924
+
1925
+ Use the object form when you want to configure loader-specific behavior such as \`staleReloadMode\`.
1926
+
1916
1927
  ## \`loader\` Parameters
1917
1928
 
1918
1929
  The \`loader\` function receives a single object with the following properties:
@@ -1998,12 +2009,16 @@ To control router dependencies and "freshness", TanStack Router provides a pleth
1998
2009
  - The number of milliseconds that a route's data should be kept in the cache before being garbage collected.
1999
2010
  - \`routeOptions.shouldReload\`
2000
2011
  - A function that receives the same \`beforeLoad\` and \`loaderContext\` parameters and returns a boolean indicating if the route should reload. This offers one more level of control over when a route should reload beyond \`staleTime\` and \`loaderDeps\` and can be used to implement patterns similar to Remix's \`shouldLoad\` option.
2012
+ - \`routeOptions.loader.staleReloadMode\`
2013
+ - \`routerOptions.defaultStaleReloadMode\`
2014
+ - Controls what happens when a matched route already has stale successful data. Use \`'background'\` for stale-while-revalidate, or \`'blocking'\` to wait for the stale loader reload to finish before continuing.
2001
2015
 
2002
2016
  ### ⚠️ Some Important Defaults
2003
2017
 
2004
2018
  - 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
2019
  - 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
2020
  - 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.
2021
+ - By default, \`staleReloadMode\` is \`'background'\`, so stale successful matches keep rendering with their existing \`loaderData\` while the loader revalidates in the background.
2007
2022
  - \`router.invalidate()\` will force all active routes to reload their loaders immediately and mark every cached route's data as stale.
2008
2023
 
2009
2024
  ### Using \`loaderDeps\` to access search params
@@ -2063,9 +2078,36 @@ export const Route = createFileRoute('/posts')({
2063
2078
 
2064
2079
  By passing \`10_000\` to the \`staleTime\` option, we are telling the router to consider the route's data fresh for 10 seconds. This means that if the user navigates to \`/posts\` from \`/about\` within 10 seconds of the last loader result, the route's data will not be reloaded. If the user then navigates to \`/posts\` from \`/about\` after 10 seconds, the route's data will be reloaded **in the background**.
2065
2080
 
2066
- ## Turning off stale-while-revalidate caching
2081
+ ## Choosing background vs blocking stale reloads
2082
+
2083
+ By default, stale successful matches use stale-while-revalidate behavior. That means the router can render with the existing \`loaderData\` immediately and then refresh it in the background.
2084
+
2085
+ If you want a specific loader to wait for a stale reload to finish before continuing, use the object form and set \`staleReloadMode: 'blocking'\`:
2086
+
2087
+ \`\`\`tsx
2088
+ // /routes/posts.tsx
2089
+ export const Route = createFileRoute('/posts')({
2090
+ loader: {
2091
+ handler: () => fetchPosts(),
2092
+ staleReloadMode: 'blocking',
2093
+ },
2094
+ })
2095
+ \`\`\`
2096
+
2097
+ You can also change the default for the entire router:
2098
+
2099
+ \`\`\`tsx
2100
+ const router = createRouter({
2101
+ routeTree,
2102
+ defaultStaleReloadMode: 'blocking',
2103
+ })
2104
+ \`\`\`
2105
+
2106
+ Use \`'background'\` when showing stale data during revalidation is acceptable. Use \`'blocking'\` when you want stale matches to behave more like a fresh load and wait for the new loader result.
2067
2107
 
2068
- To disable stale-while-revalidate caching for a route, set the \`staleTime\` option to \`Infinity\`:
2108
+ ## Turning off automatic stale reloads
2109
+
2110
+ To disable automatic stale reloads for a route, set the \`staleTime\` option to \`Infinity\`:
2069
2111
 
2070
2112
  \`\`\`tsx
2071
2113
  // /routes/posts.tsx
@@ -2084,6 +2126,11 @@ const router = createRouter({
2084
2126
  })
2085
2127
  \`\`\`
2086
2128
 
2129
+ This differs from \`staleReloadMode: 'blocking'\`:
2130
+
2131
+ - \`staleTime: Infinity\` prevents the route from becoming stale in the first place
2132
+ - \`staleReloadMode: 'blocking'\` still allows stale reloads, but waits for them instead of doing them in the background
2133
+
2087
2134
  ## Using \`shouldReload\` and \`gcTime\` to opt-out of caching
2088
2135
 
2089
2136
  Similar to Remix's default functionality, you may want to configure a route to only load on entry or when critical loader deps change. You can do this by using the \`gcTime\` option combined with the \`shouldReload\` option, which accepts either a \`boolean\` or a function that receives the same \`beforeLoad\` and \`loaderContext\` parameters and returns a boolean indicating if the route should reload.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depup/tanstack__react-router",
3
- "version": "1.166.8-depup.0",
3
+ "version": "1.167.0-depup.0",
4
4
  "description": "[DepUp] Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -86,7 +86,7 @@
86
86
  "tiny-invariant": "^1.3.3",
87
87
  "tiny-warning": "^1.0.3",
88
88
  "@tanstack/history": "1.161.4",
89
- "@tanstack/router-core": "1.166.7"
89
+ "@tanstack/router-core": "1.167.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@testing-library/jest-dom": "^6.6.3",
@@ -135,8 +135,8 @@
135
135
  },
136
136
  "depsUpdated": 2,
137
137
  "originalPackage": "@tanstack/react-router",
138
- "originalVersion": "1.166.8",
139
- "processedAt": "2026-03-14T00:32:41.859Z",
138
+ "originalVersion": "1.167.0",
139
+ "processedAt": "2026-03-14T08:12:03.548Z",
140
140
  "smokeTest": "passed"
141
141
  }
142
142
  }
package/src/fileRoute.ts CHANGED
@@ -28,7 +28,7 @@ import type {
28
28
  RouteById,
29
29
  RouteConstraints,
30
30
  RouteIds,
31
- RouteLoaderFn,
31
+ RouteLoaderEntry,
32
32
  UpdatableRouteOptions,
33
33
  UseNavigateResult,
34
34
  } from '@tanstack/router-core'
@@ -174,7 +174,7 @@ export function FileRouteLoader<
174
174
  ): <TLoaderFn>(
175
175
  loaderFn: Constrain<
176
176
  TLoaderFn,
177
- RouteLoaderFn<
177
+ RouteLoaderEntry<
178
178
  Register,
179
179
  TRoute['parentRoute'],
180
180
  TRoute['types']['id'],