tanstack-router-cache 0.1.0 → 0.1.2
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/README.md +13 -30
- package/dist/index.cjs +1342 -63
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1336 -9
- package/docs/releases.md +26 -0
- package/docs/usage.md +1 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Route view caching for [`@tanstack/react-router`](https://tanstack.com/router).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Keep selected route trees mounted while they are hidden, then restore them when the user navigates back.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
|
|
10
|
+
npm install tanstack-router-cache
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
|
|
14
|
+
bun add tanstack-router-cache
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Requirements
|
|
18
18
|
|
|
19
|
-
Your app should already
|
|
19
|
+
Your app should already install these packages:
|
|
20
20
|
|
|
21
21
|
| Package | Supported versions |
|
|
22
22
|
| --- | --- |
|
|
@@ -24,27 +24,23 @@ Your app should already use React and TanStack Router. This package keeps them a
|
|
|
24
24
|
| `react-dom` | Match your React version. |
|
|
25
25
|
| `@tanstack/react-router` | `>=1.168.14 <2.0.0` |
|
|
26
26
|
|
|
27
|
-
## Maintenance
|
|
28
|
-
|
|
29
|
-
This package is intended to stay compatible with current TanStack Router 1.x releases. The peer dependency floor is tested against the oldest version supported by the current implementation, while development tracks the latest compatible TanStack Router version.
|
|
30
|
-
|
|
31
27
|
## Usage
|
|
32
28
|
|
|
33
|
-
Wrap
|
|
29
|
+
Wrap your route outlet once:
|
|
34
30
|
|
|
35
31
|
```tsx
|
|
36
32
|
import { RouterCacheOutlet, RouterCacheProvider } from "tanstack-router-cache";
|
|
37
33
|
|
|
38
34
|
export function RootRoute() {
|
|
39
35
|
return (
|
|
40
|
-
<RouterCacheProvider
|
|
36
|
+
<RouterCacheProvider>
|
|
41
37
|
<RouterCacheOutlet />
|
|
42
38
|
</RouterCacheProvider>
|
|
43
39
|
);
|
|
44
40
|
}
|
|
45
41
|
```
|
|
46
42
|
|
|
47
|
-
Enable caching on
|
|
43
|
+
Enable caching on any route that should stay mounted:
|
|
48
44
|
|
|
49
45
|
```tsx
|
|
50
46
|
export const Route = createFileRoute("/customers")({
|
|
@@ -55,29 +51,16 @@ export const Route = createFileRoute("/customers")({
|
|
|
55
51
|
});
|
|
56
52
|
```
|
|
57
53
|
|
|
58
|
-
|
|
54
|
+
For the full API, see [docs](./docs).
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
import { useRouteCacheEffect } from "tanstack-router-cache";
|
|
62
|
-
|
|
63
|
-
function CustomersPage() {
|
|
64
|
-
useRouteCacheEffect(() => {
|
|
65
|
-
const controller = new AbortController();
|
|
66
|
-
|
|
67
|
-
return () => {
|
|
68
|
-
controller.abort();
|
|
69
|
-
};
|
|
70
|
-
}, []);
|
|
71
|
-
|
|
72
|
-
return <CustomersTable />;
|
|
73
|
-
}
|
|
74
|
-
```
|
|
56
|
+
## Examples
|
|
75
57
|
|
|
76
|
-
|
|
58
|
+
- [Basic](https://github.com/santiago-ramos-02/tanstack-router-cache/tree/main/examples/basic): the smallest useful setup. Start here; most apps only need this pattern.
|
|
59
|
+
- [Power-user demo](https://github.com/santiago-ramos-02/tanstack-router-cache/tree/main/examples/power-user-demo): a larger demo with retained forms, filtered lists, cache controls, route lifecycle state, and window scroll restoration. Use it when you need to inspect edge cases.
|
|
77
60
|
|
|
78
61
|
## Acknowledgements
|
|
79
62
|
|
|
80
|
-
This project originated from [`hemengke1997/tanstack-router-keepalive`](https://github.com/hemengke1997/tanstack-router-keepalive)
|
|
63
|
+
This project originated from [`hemengke1997/tanstack-router-keepalive`](https://github.com/hemengke1997/tanstack-router-keepalive), then diverged with current TanStack Router compatibility, a different API, cache limits, error handling, navigation lifecycle tools, dependency updates, and memory-focused eviction.
|
|
81
64
|
|
|
82
65
|
## License
|
|
83
66
|
|