Skip to content

Commit 0d6ac8f

Browse files
committed
Added jsdoc for multiple UpdatableRouteOptions params.
Added preloading doc for GC time.
1 parent 8ddc5c6 commit 0d6ac8f

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

docs/router/framework/react/guide/preloading.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export const Route = createFileRoute('/posts/$postId')({
7979
})
8080
```
8181

82+
## Preloaded data garbage collection & `preloadGcTime`
83+
84+
Similarly to `preloadStaleTime`, you can control how long preloaded data should be kept in the cache before being garbage collected by setting either `routerOptions.defaultPreloadGcTime` or `routeOptions.preloadGcTime`. **By default, preloaded data is kept in cache for 30 minutes.**.
85+
8286
## Preloading with External Libraries
8387

8488
When integrating external caching libraries like React Query, which have their own mechanisms for determining stale data, you may want to override the default preloading and stale-while-revalidate logic of TanStack Router. These libraries often use options like staleTime to control the freshness of data.

packages/react-router/src/route.ts

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,85 @@ export interface UpdatableRouteOptions<
382382
in out TRouteContextFn,
383383
in out TBeforeLoadFn,
384384
> extends UpdatableStaticRouteOption {
385-
// If true, this route will be matched as case-sensitive
385+
/**
386+
* If true, this route will be matched as case-sensitive.
387+
*/
386388
caseSensitive?: boolean
387-
// If true, this route will be forcefully wrapped in a suspense boundary
389+
/**
390+
* If true, this route will be forcefully wrapped in a suspense boundary.
391+
*/
388392
wrapInSuspense?: boolean
389-
// The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
393+
/**
394+
* The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`.
395+
*/
390396
component?: RouteComponent
397+
/**
398+
* The component that is rendered when an error occurs during the route loading or rendering lifecycle
399+
* If not set, defaults to `defaultErrorComponent`.
400+
*
401+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
402+
*/
391403
errorComponent?: false | null | ErrorRouteComponent
404+
/**
405+
* The `notFoundComponent` will be displayed when no route is matched.
406+
* If not set, defaults to `defaultNotFoundComponent`.
407+
*
408+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#default-router-wide-not-found-handling)
409+
*/
392410
notFoundComponent?: NotFoundRouteComponent
411+
/**
412+
* The `pendingComponent` will be displayed for loaders which take longer than `pendingMs` to resolve.
413+
* If not set, defaults to `defaultPendingComponent` (**unset by default**).
414+
*
415+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
416+
*/
393417
pendingComponent?: RouteComponent
418+
/**
419+
* The time (in milliseconds) to wait before showing the pending component.
420+
* If not set, defaults to `defaultPendingMs`.
421+
*
422+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
423+
*/
394424
pendingMs?: number
425+
/**
426+
* The minimum time (in milliseconds) a pending component would be potentially displayed for. This avoids flashing the pending component for very short durations.
427+
* If not set, defaults to `defaultPendingMs`.
428+
*
429+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
430+
*/
395431
pendingMinMs?: number
432+
/**
433+
* The time (in milliseconds) for which a route's data should be considered fresh when attempting to load.
434+
* If not set, defaults to `defaultStaleTime`.
435+
*
436+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
437+
*/
396438
staleTime?: number
439+
/**
440+
* The time (in milliseconds) for which a route's data should be kept in the cache before being garbage collected.
441+
*
442+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
443+
*/
397444
gcTime?: number
445+
/**
446+
* Turn on/off data preloading for this route.
447+
*
448+
* @todo allow specifying strategies available in `defaultPreload` ('intent' | 'viewport' | 'render')
449+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#supported-preloading-strategies)
450+
*/
398451
preload?: boolean
452+
/**
453+
* The time (in milliseconds) for which a route's **preloaded data** should be considered fresh when attempting to load.
454+
*
455+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#built-in-preloading--preloadstaletime)
456+
*/
399457
preloadStaleTime?: number
458+
/**
459+
* The time (in milliseconds) for which a route's **preloaded data** should be kept in the cache before being garbage collected.
460+
* If not set, defaults to `defaultPreloadGcTime`.
461+
*
462+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#built-in-preloading--preloadstaletime)
463+
*/
400464
preloadGcTime?: number
401465
search?: {
402466
middlewares?: Array<

packages/react-router/src/router.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export interface RouterOptions<
187187
*
188188
* If `'viewport'`, routes will be preloaded by default when they are within the viewport.
189189
*
190+
* If `'render'`, routes will be preloaded by default when the corresponding `Link` component gets rendered.
191+
*
190192
* @default false
191193
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreload-property)
192194
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
@@ -223,15 +225,15 @@ export interface RouterOptions<
223225
*/
224226
defaultPendingComponent?: RouteComponent
225227
/**
226-
* The default `pendingMs` a route should use if no pendingMs is provided.
228+
* The default `pendingMs` a route should use if no `pendingMs` is provided.
227229
*
228230
* @default 1000
229231
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingms-property)
230-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
232+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
231233
*/
232234
defaultPendingMs?: number
233235
/**
234-
* The default `pendingMinMs` a route should use if no pendingMinMs is provided.
236+
* The default `pendingMinMs` a route should use if no `pendingMinMs` is provided.
235237
*
236238
* @default 500
237239
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingminms-property)
@@ -251,15 +253,15 @@ export interface RouterOptions<
251253
*
252254
* @default 30_000 `(30 seconds)`
253255
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadstaletime-property)
254-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
256+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#built-in-preloading--preloadstaletime)
255257
*/
256258
defaultPreloadStaleTime?: number
257259
/**
258260
* The default `defaultPreloadGcTime` a route should use if no preloadGcTime is provided.
259261
*
260262
* @default 1_800_000 `(30 minutes)`
261263
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadgctime-property)
262-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
264+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#built-in-preloading--preloadstaletime)
263265
*/
264266
defaultPreloadGcTime?: number
265267
/**

0 commit comments

Comments
 (0)