Rocky_Mountain_Vending/.pnpm-store/v10/files/3a/b6357d1c0a56aa9c23158cca3fe1942be8181b2ca50d1975ec30ec444e347e27c3a7b443b422eb742e26d24fbbe5a5048bca171d878b85d4aa21db76b84a2f
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

89 lines
No EOL
4.3 KiB
Text

import { fetchServerResponse } from '../fetch-server-response';
import { createHrefFromUrl } from '../create-href-from-url';
import { applyRouterStatePatchToTree } from '../apply-router-state-patch-to-tree';
import { isNavigatingToNewRootLayout } from '../is-navigating-to-new-root-layout';
import { handleExternalUrl } from './navigate-reducer';
import { handleMutable } from '../handle-mutable';
import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head';
import { createEmptyCacheNode } from '../../app-router';
import { handleSegmentMismatch } from '../handle-segment-mismatch';
import { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree';
import { refreshInactiveParallelSegments } from '../refetch-inactive-parallel-segments';
import { revalidateEntireCache } from '../../segment-cache';
export function refreshReducer(state, action) {
const { origin } = action;
const mutable = {};
const href = state.canonicalUrl;
let currentTree = state.tree;
mutable.preserveCustomHistoryState = false;
const cache = createEmptyCacheNode();
// If the current tree was intercepted, the nextUrl should be included in the request.
// This is to ensure that the refresh request doesn't get intercepted, accidentally triggering the interception route.
const includeNextUrl = hasInterceptionRouteInCurrentTree(state.tree);
// TODO-APP: verify that `href` is not an external url.
// Fetch data from the root of the tree.
cache.lazyData = fetchServerResponse(new URL(href, origin), {
flightRouterState: [
currentTree[0],
currentTree[1],
currentTree[2],
'refetch'
],
nextUrl: includeNextUrl ? state.nextUrl : null
});
const navigatedAt = Date.now();
return cache.lazyData.then(async (result)=>{
// Handle case when navigating to page in `pages` from `app`
if (typeof result === 'string') {
return handleExternalUrl(state, mutable, result, state.pushRef.pendingPush);
}
const { flightData, canonicalUrl, renderedSearch } = result;
// Remove cache.lazyData as it has been resolved at this point.
cache.lazyData = null;
for (const normalizedFlightData of flightData){
const { tree: treePatch, seedData: cacheNodeSeedData, head, isRootRender } = normalizedFlightData;
if (!isRootRender) {
// TODO-APP: handle this case better
console.log('REFRESH FAILED');
return state;
}
const newTree = applyRouterStatePatchToTree(// TODO-APP: remove ''
[
''
], currentTree, treePatch, state.canonicalUrl);
if (newTree === null) {
return handleSegmentMismatch(state, action, treePatch);
}
if (isNavigatingToNewRootLayout(currentTree, newTree)) {
return handleExternalUrl(state, mutable, href, state.pushRef.pendingPush);
}
mutable.canonicalUrl = createHrefFromUrl(canonicalUrl);
// Handles case where prefetch only returns the router tree patch without rendered components.
if (cacheNodeSeedData !== null) {
const rsc = cacheNodeSeedData[0];
const loading = cacheNodeSeedData[2];
cache.rsc = rsc;
cache.prefetchRsc = null;
cache.loading = loading;
fillLazyItemsTillLeafWithHead(navigatedAt, cache, // Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache.
undefined, treePatch, cacheNodeSeedData, head);
revalidateEntireCache(state.nextUrl, newTree);
}
await refreshInactiveParallelSegments({
navigatedAt,
state,
updatedTree: newTree,
updatedCache: cache,
includeNextUrl,
canonicalUrl: mutable.canonicalUrl || state.canonicalUrl
});
mutable.cache = cache;
mutable.patchedTree = newTree;
mutable.renderedSearch = renderedSearch;
currentTree = newTree;
}
return handleMutable(state, mutable);
}, ()=>state);
}
//# sourceMappingURL=refresh-reducer.js.map