Files
Webklar.com/node_modules/next/dist/esm/client/components/router-reducer/invalidate-cache-below-flight-segmentpath.js
Basilosaurusrex f027651f9b main repo
2025-11-24 18:09:40 +01:00

43 lines
2.0 KiB
JavaScript

import { createRouterCacheKey } from "./create-router-cache-key";
/**
* Fill cache up to the end of the flightSegmentPath, invalidating anything below it.
*/ export function invalidateCacheBelowFlightSegmentPath(newCache, existingCache, flightSegmentPath) {
const isLastEntry = flightSegmentPath.length <= 2;
const [parallelRouteKey, segment] = flightSegmentPath;
const cacheKey = createRouterCacheKey(segment);
const existingChildSegmentMap = existingCache.parallelRoutes.get(parallelRouteKey);
if (!existingChildSegmentMap) {
// Bailout because the existing cache does not have the path to the leaf node
// Will trigger lazy fetch in layout-router because of missing segment
return;
}
let childSegmentMap = newCache.parallelRoutes.get(parallelRouteKey);
if (!childSegmentMap || childSegmentMap === existingChildSegmentMap) {
childSegmentMap = new Map(existingChildSegmentMap);
newCache.parallelRoutes.set(parallelRouteKey, childSegmentMap);
}
// In case of last entry don't copy further down.
if (isLastEntry) {
childSegmentMap.delete(cacheKey);
return;
}
const existingChildCacheNode = existingChildSegmentMap.get(cacheKey);
let childCacheNode = childSegmentMap.get(cacheKey);
if (!childCacheNode || !existingChildCacheNode) {
// Bailout because the existing cache does not have the path to the leaf node
// Will trigger lazy fetch in layout-router because of missing segment
return;
}
if (childCacheNode === existingChildCacheNode) {
childCacheNode = {
status: childCacheNode.status,
data: childCacheNode.data,
subTreeData: childCacheNode.subTreeData,
parallelRoutes: new Map(childCacheNode.parallelRoutes)
};
childSegmentMap.set(cacheKey, childCacheNode);
}
invalidateCacheBelowFlightSegmentPath(childCacheNode, existingChildCacheNode, flightSegmentPath.slice(2));
}
//# sourceMappingURL=invalidate-cache-below-flight-segmentpath.js.map