tanstack-router-cache 0.1.4 → 0.1.5
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/dist/index.cjs +19 -35
- package/dist/index.js +19 -35
- package/docs/releases.md +12 -4
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1036,17 +1036,7 @@ function restoreCachedHref(router, href) {
|
|
|
1036
1036
|
resetScroll: false
|
|
1037
1037
|
}).catch(() => void 0);
|
|
1038
1038
|
}
|
|
1039
|
-
function
|
|
1040
|
-
if (ancestorPathname === pathname) return false;
|
|
1041
|
-
if (ancestorPathname === "/") return pathname.startsWith("/");
|
|
1042
|
-
return pathname.startsWith(`${ancestorPathname}/`);
|
|
1043
|
-
}
|
|
1044
|
-
function getShouldRenderLiveOutlet({ cachedRoutes, bypassCachedPathname, visiblePathname }) {
|
|
1045
|
-
if (visiblePathname === bypassCachedPathname) return true;
|
|
1046
|
-
const visibleRoute = cachedRoutes[visiblePathname];
|
|
1047
|
-
return !isReadyCachedRoute(visibleRoute);
|
|
1048
|
-
}
|
|
1049
|
-
function renderCachedRoute({ bypassCachedPathname, pathname, route, visiblePathname }) {
|
|
1039
|
+
function renderCachedRoute({ bypassCachedPathname, pathname, route, routerPathname }) {
|
|
1050
1040
|
if (pathname === bypassCachedPathname) return null;
|
|
1051
1041
|
const content = route.matchId && route.routerSnapshot ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CachedOutlet, {
|
|
1052
1042
|
matchId: route.matchId,
|
|
@@ -1054,18 +1044,18 @@ function renderCachedRoute({ bypassCachedPathname, pathname, route, visiblePathn
|
|
|
1054
1044
|
}) : null;
|
|
1055
1045
|
if (!content) return null;
|
|
1056
1046
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OffScreen, {
|
|
1057
|
-
mode:
|
|
1047
|
+
mode: routerPathname === pathname ? "visible" : "hidden",
|
|
1058
1048
|
pathname,
|
|
1059
1049
|
children: content
|
|
1060
1050
|
}, pathname);
|
|
1061
1051
|
}
|
|
1062
|
-
function buildRouteCacheModes(cachedRoutes,
|
|
1052
|
+
function buildRouteCacheModes(cachedRoutes, routerPathname) {
|
|
1063
1053
|
const nextModes = /* @__PURE__ */ new Map();
|
|
1064
|
-
for (const pathname of Object.keys(cachedRoutes)) nextModes.set(pathname,
|
|
1054
|
+
for (const pathname of Object.keys(cachedRoutes)) nextModes.set(pathname, routerPathname === pathname ? "visible" : "hidden");
|
|
1065
1055
|
return nextModes;
|
|
1066
1056
|
}
|
|
1067
1057
|
function syncCachedRouteActivityEvents(params) {
|
|
1068
|
-
const nextModes = buildRouteCacheModes(params.cachedRoutes, params.
|
|
1058
|
+
const nextModes = buildRouteCacheModes(params.cachedRoutes, params.routerPathname);
|
|
1069
1059
|
for (const [pathname, mode] of nextModes) {
|
|
1070
1060
|
const previousMode = params.previousRouteCacheModes.get(pathname);
|
|
1071
1061
|
if (previousMode === void 0 && mode === "hidden") continue;
|
|
@@ -1099,7 +1089,6 @@ function RouteCacheManager() {
|
|
|
1099
1089
|
const routerResolvedLocation = (0, _tanstack_react_router.useRouterState)({ select: (state) => state.resolvedLocation ? toRouterLocation(state.resolvedLocation) : void 0 });
|
|
1100
1090
|
const resolvedPathname = normalizeCachedRoutePathname(routerResolvedLocation?.pathname ?? routerPathname);
|
|
1101
1091
|
const destinationRoute = cachedRoutes[routerPathname];
|
|
1102
|
-
const visiblePathname = routerPathname !== resolvedPathname && (isReadyCachedRoute(destinationRoute) || isAncestorPathname(routerPathname, resolvedPathname)) ? routerPathname : resolvedPathname;
|
|
1103
1092
|
const matches = (0, _tanstack_react_router.useMatches)();
|
|
1104
1093
|
const childMatches = (0, _tanstack_react_router.useChildMatches)();
|
|
1105
1094
|
const router = (0, _tanstack_react_router.useRouter)();
|
|
@@ -1167,7 +1156,7 @@ function RouteCacheManager() {
|
|
|
1167
1156
|
(0, react.useLayoutEffect)(() => {
|
|
1168
1157
|
const lastVisitedPathname = previousPathnameRef.current;
|
|
1169
1158
|
const pendingNavigation = pendingCachedNavigationRef.current;
|
|
1170
|
-
if (pendingNavigation && pendingNavigation.pathname !== routerPathname
|
|
1159
|
+
if (pendingNavigation && pendingNavigation.pathname !== routerPathname) {
|
|
1171
1160
|
eventListener.emit("cachedNavigationCancel", pendingNavigation);
|
|
1172
1161
|
pendingCachedNavigationRef.current = null;
|
|
1173
1162
|
}
|
|
@@ -1183,8 +1172,7 @@ function RouteCacheManager() {
|
|
|
1183
1172
|
}, [
|
|
1184
1173
|
destinationRoute,
|
|
1185
1174
|
eventListener,
|
|
1186
|
-
routerPathname
|
|
1187
|
-
visiblePathname
|
|
1175
|
+
routerPathname
|
|
1188
1176
|
]);
|
|
1189
1177
|
(0, react.useLayoutEffect)(() => {
|
|
1190
1178
|
previousRouteCacheModesRef.current ??= /* @__PURE__ */ new Map();
|
|
@@ -1192,28 +1180,28 @@ function RouteCacheManager() {
|
|
|
1192
1180
|
cachedRoutes,
|
|
1193
1181
|
eventListener,
|
|
1194
1182
|
previousRouteCacheModes: previousRouteCacheModesRef.current,
|
|
1195
|
-
|
|
1183
|
+
routerPathname
|
|
1196
1184
|
});
|
|
1197
1185
|
}, [
|
|
1198
1186
|
cachedRoutes,
|
|
1199
1187
|
eventListener,
|
|
1200
|
-
|
|
1188
|
+
routerPathname
|
|
1201
1189
|
]);
|
|
1202
1190
|
(0, react.useLayoutEffect)(() => {
|
|
1203
|
-
if (previousVisiblePathnameRef.current ===
|
|
1204
|
-
previousVisiblePathnameRef.current =
|
|
1191
|
+
if (previousVisiblePathnameRef.current === routerPathname || !cachedRoutes[routerPathname]) {
|
|
1192
|
+
previousVisiblePathnameRef.current = routerPathname;
|
|
1205
1193
|
return;
|
|
1206
1194
|
}
|
|
1207
|
-
previousVisiblePathnameRef.current =
|
|
1208
|
-
touchCachedRoutes([
|
|
1195
|
+
previousVisiblePathnameRef.current = routerPathname;
|
|
1196
|
+
touchCachedRoutes([routerPathname]);
|
|
1209
1197
|
}, [
|
|
1210
1198
|
cachedRoutes,
|
|
1211
1199
|
touchCachedRoutes,
|
|
1212
|
-
|
|
1200
|
+
routerPathname
|
|
1213
1201
|
]);
|
|
1214
1202
|
(0, react.useEffect)(() => {
|
|
1215
1203
|
const pendingNavigation = pendingCachedNavigationRef.current;
|
|
1216
|
-
if (
|
|
1204
|
+
if (routerPathname !== pendingNavigation?.pathname) return;
|
|
1217
1205
|
let firstFrameId = 0;
|
|
1218
1206
|
let secondFrameId = 0;
|
|
1219
1207
|
firstFrameId = globalThis.requestAnimationFrame(() => {
|
|
@@ -1234,7 +1222,7 @@ function RouteCacheManager() {
|
|
|
1234
1222
|
globalThis.cancelAnimationFrame(firstFrameId);
|
|
1235
1223
|
globalThis.cancelAnimationFrame(secondFrameId);
|
|
1236
1224
|
};
|
|
1237
|
-
}, [eventListener,
|
|
1225
|
+
}, [eventListener, routerPathname]);
|
|
1238
1226
|
(0, react.useLayoutEffect)(() => {
|
|
1239
1227
|
if (!(shouldRestoreDestinationHref && destinationRoute?.href)) return;
|
|
1240
1228
|
restoreCachedHref(router, destinationRoute.href);
|
|
@@ -1247,17 +1235,13 @@ function RouteCacheManager() {
|
|
|
1247
1235
|
previousPathnameRef.current = routerPathname;
|
|
1248
1236
|
previousHrefRef.current = routerHref;
|
|
1249
1237
|
}, [routerHref, routerPathname]);
|
|
1250
|
-
const shouldRenderLiveOutlet =
|
|
1251
|
-
|
|
1252
|
-
bypassCachedPathname,
|
|
1253
|
-
visiblePathname
|
|
1254
|
-
});
|
|
1255
|
-
useRouterCacheDebug(cachedRoutes, visiblePathname);
|
|
1238
|
+
const shouldRenderLiveOutlet = routerPathname === bypassCachedPathname || !isReadyCachedRoute(destinationRoute);
|
|
1239
|
+
useRouterCacheDebug(cachedRoutes, routerPathname);
|
|
1256
1240
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [Object.entries(cachedRoutes).map(([pathname, route]) => renderCachedRoute({
|
|
1257
1241
|
bypassCachedPathname,
|
|
1258
1242
|
pathname,
|
|
1259
1243
|
route,
|
|
1260
|
-
|
|
1244
|
+
routerPathname
|
|
1261
1245
|
})), shouldRenderLiveOutlet ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tanstack_react_router.Outlet, {}, `live-${routerPathname}`) : null] });
|
|
1262
1246
|
}
|
|
1263
1247
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1035,17 +1035,7 @@ function restoreCachedHref(router, href) {
|
|
|
1035
1035
|
resetScroll: false
|
|
1036
1036
|
}).catch(() => void 0);
|
|
1037
1037
|
}
|
|
1038
|
-
function
|
|
1039
|
-
if (ancestorPathname === pathname) return false;
|
|
1040
|
-
if (ancestorPathname === "/") return pathname.startsWith("/");
|
|
1041
|
-
return pathname.startsWith(`${ancestorPathname}/`);
|
|
1042
|
-
}
|
|
1043
|
-
function getShouldRenderLiveOutlet({ cachedRoutes, bypassCachedPathname, visiblePathname }) {
|
|
1044
|
-
if (visiblePathname === bypassCachedPathname) return true;
|
|
1045
|
-
const visibleRoute = cachedRoutes[visiblePathname];
|
|
1046
|
-
return !isReadyCachedRoute(visibleRoute);
|
|
1047
|
-
}
|
|
1048
|
-
function renderCachedRoute({ bypassCachedPathname, pathname, route, visiblePathname }) {
|
|
1038
|
+
function renderCachedRoute({ bypassCachedPathname, pathname, route, routerPathname }) {
|
|
1049
1039
|
if (pathname === bypassCachedPathname) return null;
|
|
1050
1040
|
const content = route.matchId && route.routerSnapshot ? /* @__PURE__ */ jsx(CachedOutlet, {
|
|
1051
1041
|
matchId: route.matchId,
|
|
@@ -1053,18 +1043,18 @@ function renderCachedRoute({ bypassCachedPathname, pathname, route, visiblePathn
|
|
|
1053
1043
|
}) : null;
|
|
1054
1044
|
if (!content) return null;
|
|
1055
1045
|
return /* @__PURE__ */ jsx(OffScreen, {
|
|
1056
|
-
mode:
|
|
1046
|
+
mode: routerPathname === pathname ? "visible" : "hidden",
|
|
1057
1047
|
pathname,
|
|
1058
1048
|
children: content
|
|
1059
1049
|
}, pathname);
|
|
1060
1050
|
}
|
|
1061
|
-
function buildRouteCacheModes(cachedRoutes,
|
|
1051
|
+
function buildRouteCacheModes(cachedRoutes, routerPathname) {
|
|
1062
1052
|
const nextModes = /* @__PURE__ */ new Map();
|
|
1063
|
-
for (const pathname of Object.keys(cachedRoutes)) nextModes.set(pathname,
|
|
1053
|
+
for (const pathname of Object.keys(cachedRoutes)) nextModes.set(pathname, routerPathname === pathname ? "visible" : "hidden");
|
|
1064
1054
|
return nextModes;
|
|
1065
1055
|
}
|
|
1066
1056
|
function syncCachedRouteActivityEvents(params) {
|
|
1067
|
-
const nextModes = buildRouteCacheModes(params.cachedRoutes, params.
|
|
1057
|
+
const nextModes = buildRouteCacheModes(params.cachedRoutes, params.routerPathname);
|
|
1068
1058
|
for (const [pathname, mode] of nextModes) {
|
|
1069
1059
|
const previousMode = params.previousRouteCacheModes.get(pathname);
|
|
1070
1060
|
if (previousMode === void 0 && mode === "hidden") continue;
|
|
@@ -1098,7 +1088,6 @@ function RouteCacheManager() {
|
|
|
1098
1088
|
const routerResolvedLocation = useRouterState({ select: (state) => state.resolvedLocation ? toRouterLocation(state.resolvedLocation) : void 0 });
|
|
1099
1089
|
const resolvedPathname = normalizeCachedRoutePathname(routerResolvedLocation?.pathname ?? routerPathname);
|
|
1100
1090
|
const destinationRoute = cachedRoutes[routerPathname];
|
|
1101
|
-
const visiblePathname = routerPathname !== resolvedPathname && (isReadyCachedRoute(destinationRoute) || isAncestorPathname(routerPathname, resolvedPathname)) ? routerPathname : resolvedPathname;
|
|
1102
1091
|
const matches = useMatches();
|
|
1103
1092
|
const childMatches = useChildMatches();
|
|
1104
1093
|
const router = useRouter();
|
|
@@ -1166,7 +1155,7 @@ function RouteCacheManager() {
|
|
|
1166
1155
|
useLayoutEffect(() => {
|
|
1167
1156
|
const lastVisitedPathname = previousPathnameRef.current;
|
|
1168
1157
|
const pendingNavigation = pendingCachedNavigationRef.current;
|
|
1169
|
-
if (pendingNavigation && pendingNavigation.pathname !== routerPathname
|
|
1158
|
+
if (pendingNavigation && pendingNavigation.pathname !== routerPathname) {
|
|
1170
1159
|
eventListener.emit("cachedNavigationCancel", pendingNavigation);
|
|
1171
1160
|
pendingCachedNavigationRef.current = null;
|
|
1172
1161
|
}
|
|
@@ -1182,8 +1171,7 @@ function RouteCacheManager() {
|
|
|
1182
1171
|
}, [
|
|
1183
1172
|
destinationRoute,
|
|
1184
1173
|
eventListener,
|
|
1185
|
-
routerPathname
|
|
1186
|
-
visiblePathname
|
|
1174
|
+
routerPathname
|
|
1187
1175
|
]);
|
|
1188
1176
|
useLayoutEffect(() => {
|
|
1189
1177
|
previousRouteCacheModesRef.current ??= /* @__PURE__ */ new Map();
|
|
@@ -1191,28 +1179,28 @@ function RouteCacheManager() {
|
|
|
1191
1179
|
cachedRoutes,
|
|
1192
1180
|
eventListener,
|
|
1193
1181
|
previousRouteCacheModes: previousRouteCacheModesRef.current,
|
|
1194
|
-
|
|
1182
|
+
routerPathname
|
|
1195
1183
|
});
|
|
1196
1184
|
}, [
|
|
1197
1185
|
cachedRoutes,
|
|
1198
1186
|
eventListener,
|
|
1199
|
-
|
|
1187
|
+
routerPathname
|
|
1200
1188
|
]);
|
|
1201
1189
|
useLayoutEffect(() => {
|
|
1202
|
-
if (previousVisiblePathnameRef.current ===
|
|
1203
|
-
previousVisiblePathnameRef.current =
|
|
1190
|
+
if (previousVisiblePathnameRef.current === routerPathname || !cachedRoutes[routerPathname]) {
|
|
1191
|
+
previousVisiblePathnameRef.current = routerPathname;
|
|
1204
1192
|
return;
|
|
1205
1193
|
}
|
|
1206
|
-
previousVisiblePathnameRef.current =
|
|
1207
|
-
touchCachedRoutes([
|
|
1194
|
+
previousVisiblePathnameRef.current = routerPathname;
|
|
1195
|
+
touchCachedRoutes([routerPathname]);
|
|
1208
1196
|
}, [
|
|
1209
1197
|
cachedRoutes,
|
|
1210
1198
|
touchCachedRoutes,
|
|
1211
|
-
|
|
1199
|
+
routerPathname
|
|
1212
1200
|
]);
|
|
1213
1201
|
useEffect(() => {
|
|
1214
1202
|
const pendingNavigation = pendingCachedNavigationRef.current;
|
|
1215
|
-
if (
|
|
1203
|
+
if (routerPathname !== pendingNavigation?.pathname) return;
|
|
1216
1204
|
let firstFrameId = 0;
|
|
1217
1205
|
let secondFrameId = 0;
|
|
1218
1206
|
firstFrameId = globalThis.requestAnimationFrame(() => {
|
|
@@ -1233,7 +1221,7 @@ function RouteCacheManager() {
|
|
|
1233
1221
|
globalThis.cancelAnimationFrame(firstFrameId);
|
|
1234
1222
|
globalThis.cancelAnimationFrame(secondFrameId);
|
|
1235
1223
|
};
|
|
1236
|
-
}, [eventListener,
|
|
1224
|
+
}, [eventListener, routerPathname]);
|
|
1237
1225
|
useLayoutEffect(() => {
|
|
1238
1226
|
if (!(shouldRestoreDestinationHref && destinationRoute?.href)) return;
|
|
1239
1227
|
restoreCachedHref(router, destinationRoute.href);
|
|
@@ -1246,17 +1234,13 @@ function RouteCacheManager() {
|
|
|
1246
1234
|
previousPathnameRef.current = routerPathname;
|
|
1247
1235
|
previousHrefRef.current = routerHref;
|
|
1248
1236
|
}, [routerHref, routerPathname]);
|
|
1249
|
-
const shouldRenderLiveOutlet =
|
|
1250
|
-
|
|
1251
|
-
bypassCachedPathname,
|
|
1252
|
-
visiblePathname
|
|
1253
|
-
});
|
|
1254
|
-
useRouterCacheDebug(cachedRoutes, visiblePathname);
|
|
1237
|
+
const shouldRenderLiveOutlet = routerPathname === bypassCachedPathname || !isReadyCachedRoute(destinationRoute);
|
|
1238
|
+
useRouterCacheDebug(cachedRoutes, routerPathname);
|
|
1255
1239
|
return /* @__PURE__ */ jsxs(Fragment, { children: [Object.entries(cachedRoutes).map(([pathname, route]) => renderCachedRoute({
|
|
1256
1240
|
bypassCachedPathname,
|
|
1257
1241
|
pathname,
|
|
1258
1242
|
route,
|
|
1259
|
-
|
|
1243
|
+
routerPathname
|
|
1260
1244
|
})), shouldRenderLiveOutlet ? /* @__PURE__ */ jsx(Outlet, {}, `live-${routerPathname}`) : null] });
|
|
1261
1245
|
}
|
|
1262
1246
|
//#endregion
|
package/docs/releases.md
CHANGED
|
@@ -34,15 +34,23 @@ That updates GitHub and runs CI, but it does not publish to npm.
|
|
|
34
34
|
For a release, start from a clean `main` branch after your changes are already committed:
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
|
-
bun run release
|
|
38
|
-
bun run release:push
|
|
37
|
+
bun run release patch
|
|
39
38
|
```
|
|
40
39
|
|
|
41
40
|
Use `minor`, `major`, or an exact version when needed:
|
|
42
41
|
|
|
43
42
|
```sh
|
|
44
|
-
bun run release
|
|
45
|
-
bun run release
|
|
43
|
+
bun run release minor
|
|
44
|
+
bun run release 0.2.0
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`release` updates `package.json`, runs the package checks, commits the version bump, creates the matching tag, pushes `main` and the tag, creates the GitHub Release, waits for the publish workflow, and verifies that npm has the new package version.
|
|
48
|
+
|
|
49
|
+
The lower-level commands are still available when you need to split the release into two steps:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
bun run release:prepare patch
|
|
53
|
+
bun run release:push
|
|
46
54
|
```
|
|
47
55
|
|
|
48
56
|
`release:prepare` updates `package.json`, runs the package checks, commits the version bump, and creates the matching tag locally. `release:push` pushes `main` and that exact tag. The tag starts the npm publish workflow.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tanstack-router-cache",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Route view caching for TanStack Router.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"lint:fix": "biome lint src scripts .github/scripts rolldown.config.ts --write --skip=lint/performance/noBarrelFile --skip=lint/style/useConsistentTypeDefinitions --skip=lint/suspicious/noConsole",
|
|
51
51
|
"check": "bun run lint && bun run typecheck && bun run build && bun run pack:dry-run",
|
|
52
52
|
"pack:dry-run": "npm pack --dry-run",
|
|
53
|
+
"release": "node scripts/release.mjs release",
|
|
53
54
|
"release:prepare": "node scripts/release.mjs prepare",
|
|
54
55
|
"release:push": "node scripts/release.mjs push",
|
|
55
56
|
"prepack": "bun run build",
|