main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import { FlightDataPath } from '../../../server/app-render/types';
export declare function applyFlightData(existingCache: CacheNode, cache: CacheNode, flightDataPath: FlightDataPath, wasPrefetched?: boolean): boolean;

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "applyFlightData", {
enumerable: true,
get: function() {
return applyFlightData;
}
});
const _approutercontextsharedruntime = require("../../../shared/lib/app-router-context.shared-runtime");
const _filllazyitemstillleafwithhead = require("./fill-lazy-items-till-leaf-with-head");
const _fillcachewithnewsubtreedata = require("./fill-cache-with-new-subtree-data");
function applyFlightData(existingCache, cache, flightDataPath, wasPrefetched) {
if (wasPrefetched === void 0) wasPrefetched = false;
// The one before last item is the router state tree patch
const [treePatch, subTreeData, head] = flightDataPath.slice(-3);
// Handles case where prefetch only returns the router tree patch without rendered components.
if (subTreeData === null) {
return false;
}
if (flightDataPath.length === 3) {
cache.status = _approutercontextsharedruntime.CacheStates.READY;
cache.subTreeData = subTreeData;
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(cache, existingCache, treePatch, head, wasPrefetched);
} else {
// Copy subTreeData for the root node of the cache.
cache.status = _approutercontextsharedruntime.CacheStates.READY;
cache.subTreeData = existingCache.subTreeData;
cache.parallelRoutes = new Map(existingCache.parallelRoutes);
// Create a copy of the existing cache with the subTreeData applied.
(0, _fillcachewithnewsubtreedata.fillCacheWithNewSubTreeData)(cache, existingCache, flightDataPath, wasPrefetched);
}
return true;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=apply-flight-data.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/apply-flight-data.ts"],"names":["applyFlightData","existingCache","cache","flightDataPath","wasPrefetched","treePatch","subTreeData","head","slice","length","status","CacheStates","READY","fillLazyItemsTillLeafWithHead","parallelRoutes","Map","fillCacheWithNewSubTreeData"],"mappings":";;;;+BAQgBA;;;eAAAA;;;+CALT;+CAEuC;6CACF;AAErC,SAASA,gBACdC,aAAwB,EACxBC,KAAgB,EAChBC,cAA8B,EAC9BC,aAA8B;IAA9BA,IAAAA,0BAAAA,gBAAyB;IAEzB,0DAA0D;IAC1D,MAAM,CAACC,WAAWC,aAAaC,KAAK,GAAGJ,eAAeK,KAAK,CAAC,CAAC;IAE7D,8FAA8F;IAC9F,IAAIF,gBAAgB,MAAM;QACxB,OAAO;IACT;IAEA,IAAIH,eAAeM,MAAM,KAAK,GAAG;QAC/BP,MAAMQ,MAAM,GAAGC,0CAAW,CAACC,KAAK;QAChCV,MAAMI,WAAW,GAAGA;QACpBO,IAAAA,4DAA6B,EAC3BX,OACAD,eACAI,WACAE,MACAH;IAEJ,OAAO;QACL,mDAAmD;QACnDF,MAAMQ,MAAM,GAAGC,0CAAW,CAACC,KAAK;QAChCV,MAAMI,WAAW,GAAGL,cAAcK,WAAW;QAC7CJ,MAAMY,cAAc,GAAG,IAAIC,IAAId,cAAca,cAAc;QAC3D,oEAAoE;QACpEE,IAAAA,wDAA2B,EACzBd,OACAD,eACAE,gBACAC;IAEJ;IAEA,OAAO;AACT"}

View File

@@ -0,0 +1,5 @@
import type { FlightRouterState, FlightSegmentPath } from '../../../server/app-render/types';
/**
* Apply the router state from the Flight response. Creates a new router state tree.
*/
export declare function applyRouterStatePatchToTree(flightSegmentPath: FlightSegmentPath, flightRouterState: FlightRouterState, treePatch: FlightRouterState): FlightRouterState | null;

View File

@@ -0,0 +1,97 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "applyRouterStatePatchToTree", {
enumerable: true,
get: function() {
return applyRouterStatePatchToTree;
}
});
const _matchsegments = require("../match-segments");
/**
* Deep merge of the two router states. Parallel route keys are preserved if the patch doesn't have them.
*/ function applyPatch(initialTree, patchTree) {
const [initialSegment, initialParallelRoutes] = initialTree;
const [patchSegment, patchParallelRoutes] = patchTree;
// if the applied patch segment is __DEFAULT__ then we can ignore it and return the initial tree
// this is because the __DEFAULT__ segment is used as a placeholder on navigation
if (patchSegment === "__DEFAULT__" && initialSegment !== "__DEFAULT__") {
return initialTree;
}
if ((0, _matchsegments.matchSegment)(initialSegment, patchSegment)) {
const newParallelRoutes = {};
for(const key in initialParallelRoutes){
const isInPatchTreeParallelRoutes = typeof patchParallelRoutes[key] !== "undefined";
if (isInPatchTreeParallelRoutes) {
newParallelRoutes[key] = applyPatch(initialParallelRoutes[key], patchParallelRoutes[key]);
} else {
newParallelRoutes[key] = initialParallelRoutes[key];
}
}
for(const key in patchParallelRoutes){
if (newParallelRoutes[key]) {
continue;
}
newParallelRoutes[key] = patchParallelRoutes[key];
}
const tree = [
initialSegment,
newParallelRoutes
];
if (initialTree[2]) {
tree[2] = initialTree[2];
}
if (initialTree[3]) {
tree[3] = initialTree[3];
}
if (initialTree[4]) {
tree[4] = initialTree[4];
}
return tree;
}
return patchTree;
}
function applyRouterStatePatchToTree(flightSegmentPath, flightRouterState, treePatch) {
const [segment, parallelRoutes, , , isRootLayout] = flightRouterState;
// Root refresh
if (flightSegmentPath.length === 1) {
const tree = applyPatch(flightRouterState, treePatch);
return tree;
}
const [currentSegment, parallelRouteKey] = flightSegmentPath;
// Tree path returned from the server should always match up with the current tree in the browser
if (!(0, _matchsegments.matchSegment)(currentSegment, segment)) {
return null;
}
const lastSegment = flightSegmentPath.length === 2;
let parallelRoutePatch;
if (lastSegment) {
parallelRoutePatch = applyPatch(parallelRoutes[parallelRouteKey], treePatch);
} else {
parallelRoutePatch = applyRouterStatePatchToTree(flightSegmentPath.slice(2), parallelRoutes[parallelRouteKey], treePatch);
if (parallelRoutePatch === null) {
return null;
}
}
const tree = [
flightSegmentPath[0],
{
...parallelRoutes,
[parallelRouteKey]: parallelRoutePatch
}
];
// Current segment is the root layout
if (isRootLayout) {
tree[4] = true;
}
return tree;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=apply-router-state-patch-to-tree.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/apply-router-state-patch-to-tree.ts"],"names":["applyRouterStatePatchToTree","applyPatch","initialTree","patchTree","initialSegment","initialParallelRoutes","patchSegment","patchParallelRoutes","matchSegment","newParallelRoutes","key","isInPatchTreeParallelRoutes","tree","flightSegmentPath","flightRouterState","treePatch","segment","parallelRoutes","isRootLayout","length","currentSegment","parallelRouteKey","lastSegment","parallelRoutePatch","slice"],"mappings":";;;;+BAoEgBA;;;eAAAA;;;+BAhEa;AAE7B;;CAEC,GACD,SAASC,WACPC,WAA8B,EAC9BC,SAA4B;IAE5B,MAAM,CAACC,gBAAgBC,sBAAsB,GAAGH;IAChD,MAAM,CAACI,cAAcC,oBAAoB,GAAGJ;IAE5C,gGAAgG;IAChG,iFAAiF;IACjF,IAAIG,iBAAiB,iBAAiBF,mBAAmB,eAAe;QACtE,OAAOF;IACT;IAEA,IAAIM,IAAAA,2BAAY,EAACJ,gBAAgBE,eAAe;QAC9C,MAAMG,oBAA0C,CAAC;QACjD,IAAK,MAAMC,OAAOL,sBAAuB;YACvC,MAAMM,8BACJ,OAAOJ,mBAAmB,CAACG,IAAI,KAAK;YACtC,IAAIC,6BAA6B;gBAC/BF,iBAAiB,CAACC,IAAI,GAAGT,WACvBI,qBAAqB,CAACK,IAAI,EAC1BH,mBAAmB,CAACG,IAAI;YAE5B,OAAO;gBACLD,iBAAiB,CAACC,IAAI,GAAGL,qBAAqB,CAACK,IAAI;YACrD;QACF;QAEA,IAAK,MAAMA,OAAOH,oBAAqB;YACrC,IAAIE,iBAAiB,CAACC,IAAI,EAAE;gBAC1B;YACF;YAEAD,iBAAiB,CAACC,IAAI,GAAGH,mBAAmB,CAACG,IAAI;QACnD;QAEA,MAAME,OAA0B;YAACR;YAAgBK;SAAkB;QAEnE,IAAIP,WAAW,CAAC,EAAE,EAAE;YAClBU,IAAI,CAAC,EAAE,GAAGV,WAAW,CAAC,EAAE;QAC1B;QAEA,IAAIA,WAAW,CAAC,EAAE,EAAE;YAClBU,IAAI,CAAC,EAAE,GAAGV,WAAW,CAAC,EAAE;QAC1B;QAEA,IAAIA,WAAW,CAAC,EAAE,EAAE;YAClBU,IAAI,CAAC,EAAE,GAAGV,WAAW,CAAC,EAAE;QAC1B;QAEA,OAAOU;IACT;IAEA,OAAOT;AACT;AAKO,SAASH,4BACda,iBAAoC,EACpCC,iBAAoC,EACpCC,SAA4B;IAE5B,MAAM,CAACC,SAASC,oBAAoBC,aAAa,GAAGJ;IAEpD,eAAe;IACf,IAAID,kBAAkBM,MAAM,KAAK,GAAG;QAClC,MAAMP,OAA0BX,WAAWa,mBAAmBC;QAE9D,OAAOH;IACT;IAEA,MAAM,CAACQ,gBAAgBC,iBAAiB,GAAGR;IAE3C,iGAAiG;IACjG,IAAI,CAACL,IAAAA,2BAAY,EAACY,gBAAgBJ,UAAU;QAC1C,OAAO;IACT;IAEA,MAAMM,cAAcT,kBAAkBM,MAAM,KAAK;IAEjD,IAAII;IACJ,IAAID,aAAa;QACfC,qBAAqBtB,WAAWgB,cAAc,CAACI,iBAAiB,EAAEN;IACpE,OAAO;QACLQ,qBAAqBvB,4BACnBa,kBAAkBW,KAAK,CAAC,IACxBP,cAAc,CAACI,iBAAiB,EAChCN;QAGF,IAAIQ,uBAAuB,MAAM;YAC/B,OAAO;QACT;IACF;IAEA,MAAMX,OAA0B;QAC9BC,iBAAiB,CAAC,EAAE;QACpB;YACE,GAAGI,cAAc;YACjB,CAACI,iBAAiB,EAAEE;QACtB;KACD;IAED,qCAAqC;IACrC,IAAIL,cAAc;QAChBN,IAAI,CAAC,EAAE,GAAG;IACZ;IAEA,OAAOA;AACT"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,3 @@
import { FlightRouterState } from '../../../server/app-render/types';
export declare function extractPathFromFlightRouterState(flightRouterState: FlightRouterState): string | undefined;
export declare function computeChangedPath(treeA: FlightRouterState, treeB: FlightRouterState): string | null;

View File

@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
extractPathFromFlightRouterState: null,
computeChangedPath: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
extractPathFromFlightRouterState: function() {
return extractPathFromFlightRouterState;
},
computeChangedPath: function() {
return computeChangedPath;
}
});
const _interceptionroutes = require("../../../server/future/helpers/interception-routes");
const _segment = require("../../../shared/lib/segment");
const _matchsegments = require("../match-segments");
const removeLeadingSlash = (segment)=>{
return segment[0] === "/" ? segment.slice(1) : segment;
};
const segmentToPathname = (segment)=>{
if (typeof segment === "string") {
return segment;
}
return segment[1];
};
function normalizeSegments(segments) {
return segments.reduce((acc, segment)=>{
segment = removeLeadingSlash(segment);
if (segment === "" || (0, _segment.isGroupSegment)(segment)) {
return acc;
}
return acc + "/" + segment;
}, "") || "/";
}
function extractPathFromFlightRouterState(flightRouterState) {
const segment = Array.isArray(flightRouterState[0]) ? flightRouterState[0][1] : flightRouterState[0];
if (segment === "__DEFAULT__" || _interceptionroutes.INTERCEPTION_ROUTE_MARKERS.some((m)=>segment.startsWith(m))) return undefined;
if (segment.startsWith("__PAGE__")) return "";
const segments = [
segment
];
var _flightRouterState_;
const parallelRoutes = (_flightRouterState_ = flightRouterState[1]) != null ? _flightRouterState_ : {};
const childrenPath = parallelRoutes.children ? extractPathFromFlightRouterState(parallelRoutes.children) : undefined;
if (childrenPath !== undefined) {
segments.push(childrenPath);
} else {
for (const [key, value] of Object.entries(parallelRoutes)){
if (key === "children") continue;
const childPath = extractPathFromFlightRouterState(value);
if (childPath !== undefined) {
segments.push(childPath);
}
}
}
return normalizeSegments(segments);
}
function computeChangedPathImpl(treeA, treeB) {
const [segmentA, parallelRoutesA] = treeA;
const [segmentB, parallelRoutesB] = treeB;
const normalizedSegmentA = segmentToPathname(segmentA);
const normalizedSegmentB = segmentToPathname(segmentB);
if (_interceptionroutes.INTERCEPTION_ROUTE_MARKERS.some((m)=>normalizedSegmentA.startsWith(m) || normalizedSegmentB.startsWith(m))) {
return "";
}
if (!(0, _matchsegments.matchSegment)(segmentA, segmentB)) {
var _extractPathFromFlightRouterState;
// once we find where the tree changed, we compute the rest of the path by traversing the tree
return (_extractPathFromFlightRouterState = extractPathFromFlightRouterState(treeB)) != null ? _extractPathFromFlightRouterState : "";
}
for(const parallelRouterKey in parallelRoutesA){
if (parallelRoutesB[parallelRouterKey]) {
const changedPath = computeChangedPathImpl(parallelRoutesA[parallelRouterKey], parallelRoutesB[parallelRouterKey]);
if (changedPath !== null) {
return segmentToPathname(segmentB) + "/" + changedPath;
}
}
}
return null;
}
function computeChangedPath(treeA, treeB) {
const changedPath = computeChangedPathImpl(treeA, treeB);
if (changedPath == null || changedPath === "/") {
return changedPath;
}
// lightweight normalization to remove route groups
return normalizeSegments(changedPath.split("/"));
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=compute-changed-path.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/compute-changed-path.ts"],"names":["extractPathFromFlightRouterState","computeChangedPath","removeLeadingSlash","segment","slice","segmentToPathname","normalizeSegments","segments","reduce","acc","isGroupSegment","flightRouterState","Array","isArray","INTERCEPTION_ROUTE_MARKERS","some","m","startsWith","undefined","parallelRoutes","childrenPath","children","push","key","value","Object","entries","childPath","computeChangedPathImpl","treeA","treeB","segmentA","parallelRoutesA","segmentB","parallelRoutesB","normalizedSegmentA","normalizedSegmentB","matchSegment","parallelRouterKey","changedPath","split"],"mappings":";;;;;;;;;;;;;;;IA8BgBA,gCAAgC;eAAhCA;;IA8EAC,kBAAkB;eAAlBA;;;oCA3G2B;yBACZ;+BACF;AAE7B,MAAMC,qBAAqB,CAACC;IAC1B,OAAOA,OAAO,CAAC,EAAE,KAAK,MAAMA,QAAQC,KAAK,CAAC,KAAKD;AACjD;AAEA,MAAME,oBAAoB,CAACF;IACzB,IAAI,OAAOA,YAAY,UAAU;QAC/B,OAAOA;IACT;IAEA,OAAOA,OAAO,CAAC,EAAE;AACnB;AAEA,SAASG,kBAAkBC,QAAkB;IAC3C,OACEA,SAASC,MAAM,CAAC,CAACC,KAAKN;QACpBA,UAAUD,mBAAmBC;QAC7B,IAAIA,YAAY,MAAMO,IAAAA,uBAAc,EAACP,UAAU;YAC7C,OAAOM;QACT;QAEA,OAAO,AAAGA,MAAI,MAAGN;IACnB,GAAG,OAAO;AAEd;AAEO,SAASH,iCACdW,iBAAoC;IAEpC,MAAMR,UAAUS,MAAMC,OAAO,CAACF,iBAAiB,CAAC,EAAE,IAC9CA,iBAAiB,CAAC,EAAE,CAAC,EAAE,GACvBA,iBAAiB,CAAC,EAAE;IAExB,IACER,YAAY,iBACZW,8CAA0B,CAACC,IAAI,CAAC,CAACC,IAAMb,QAAQc,UAAU,CAACD,KAE1D,OAAOE;IAET,IAAIf,QAAQc,UAAU,CAAC,aAAa,OAAO;IAE3C,MAAMV,WAAW;QAACJ;KAAQ;QACHQ;IAAvB,MAAMQ,iBAAiBR,CAAAA,sBAAAA,iBAAiB,CAAC,EAAE,YAApBA,sBAAwB,CAAC;IAEhD,MAAMS,eAAeD,eAAeE,QAAQ,GACxCrB,iCAAiCmB,eAAeE,QAAQ,IACxDH;IAEJ,IAAIE,iBAAiBF,WAAW;QAC9BX,SAASe,IAAI,CAACF;IAChB,OAAO;QACL,KAAK,MAAM,CAACG,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACP,gBAAiB;YACzD,IAAII,QAAQ,YAAY;YAExB,MAAMI,YAAY3B,iCAAiCwB;YAEnD,IAAIG,cAAcT,WAAW;gBAC3BX,SAASe,IAAI,CAACK;YAChB;QACF;IACF;IAEA,OAAOrB,kBAAkBC;AAC3B;AAEA,SAASqB,uBACPC,KAAwB,EACxBC,KAAwB;IAExB,MAAM,CAACC,UAAUC,gBAAgB,GAAGH;IACpC,MAAM,CAACI,UAAUC,gBAAgB,GAAGJ;IAEpC,MAAMK,qBAAqB9B,kBAAkB0B;IAC7C,MAAMK,qBAAqB/B,kBAAkB4B;IAE7C,IACEnB,8CAA0B,CAACC,IAAI,CAC7B,CAACC,IACCmB,mBAAmBlB,UAAU,CAACD,MAAMoB,mBAAmBnB,UAAU,CAACD,KAEtE;QACA,OAAO;IACT;IAEA,IAAI,CAACqB,IAAAA,2BAAY,EAACN,UAAUE,WAAW;YAE9BjC;QADP,8FAA8F;QAC9F,OAAOA,CAAAA,oCAAAA,iCAAiC8B,kBAAjC9B,oCAA2C;IACpD;IAEA,IAAK,MAAMsC,qBAAqBN,gBAAiB;QAC/C,IAAIE,eAAe,CAACI,kBAAkB,EAAE;YACtC,MAAMC,cAAcX,uBAClBI,eAAe,CAACM,kBAAkB,EAClCJ,eAAe,CAACI,kBAAkB;YAEpC,IAAIC,gBAAgB,MAAM;gBACxB,OAAO,AAAGlC,kBAAkB4B,YAAU,MAAGM;YAC3C;QACF;IACF;IAEA,OAAO;AACT;AAEO,SAAStC,mBACd4B,KAAwB,EACxBC,KAAwB;IAExB,MAAMS,cAAcX,uBAAuBC,OAAOC;IAElD,IAAIS,eAAe,QAAQA,gBAAgB,KAAK;QAC9C,OAAOA;IACT;IAEA,mDAAmD;IACnD,OAAOjC,kBAAkBiC,YAAYC,KAAK,CAAC;AAC7C"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1 @@
export declare function createHrefFromUrl(url: Pick<URL, 'pathname' | 'search' | 'hash'>, includeHash?: boolean): string;

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createHrefFromUrl", {
enumerable: true,
get: function() {
return createHrefFromUrl;
}
});
function createHrefFromUrl(url, includeHash) {
if (includeHash === void 0) includeHash = true;
return url.pathname + url.search + (includeHash ? url.hash : "");
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=create-href-from-url.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/create-href-from-url.ts"],"names":["createHrefFromUrl","url","includeHash","pathname","search","hash"],"mappings":";;;;+BAAgBA;;;eAAAA;;;AAAT,SAASA,kBACdC,GAA8C,EAC9CC,WAA2B;IAA3BA,IAAAA,wBAAAA,cAAuB;IAEvB,OAAOD,IAAIE,QAAQ,GAAGF,IAAIG,MAAM,GAAIF,CAAAA,cAAcD,IAAII,IAAI,GAAG,EAAC;AAChE"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,38 @@
import type { ReactNode } from 'react';
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import type { FlightRouterState } from '../../../server/app-render/types';
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime';
export interface InitialRouterStateParameters {
buildId: string;
initialTree: FlightRouterState;
initialCanonicalUrl: string;
children: ReactNode;
initialParallelRoutes: CacheNode['parallelRoutes'];
isServer: boolean;
location: Location | null;
initialHead: ReactNode;
}
export declare function createInitialRouterState({ buildId, initialTree, children, initialCanonicalUrl, initialParallelRoutes, isServer, location, initialHead, }: InitialRouterStateParameters): {
buildId: string;
tree: FlightRouterState;
cache: {
status: CacheStates.READY;
data: null;
head?: ReactNode;
subTreeData: ReactNode;
parallelRoutes: Map<string, import("../../../shared/lib/app-router-context.shared-runtime").ChildSegmentMap>;
};
prefetchCache: Map<any, any>;
pushRef: {
pendingPush: boolean;
mpaNavigation: boolean;
};
focusAndScrollRef: {
apply: boolean;
onlyHashChange: boolean;
hashFragment: null;
segmentPaths: never[];
};
canonicalUrl: string;
nextUrl: string | null;
};

View File

@@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createInitialRouterState", {
enumerable: true,
get: function() {
return createInitialRouterState;
}
});
const _approutercontextsharedruntime = require("../../../shared/lib/app-router-context.shared-runtime");
const _createhreffromurl = require("./create-href-from-url");
const _filllazyitemstillleafwithhead = require("./fill-lazy-items-till-leaf-with-head");
const _computechangedpath = require("./compute-changed-path");
function createInitialRouterState(param) {
let { buildId, initialTree, children, initialCanonicalUrl, initialParallelRoutes, isServer, location, initialHead } = param;
const cache = {
status: _approutercontextsharedruntime.CacheStates.READY,
data: null,
subTreeData: children,
// The cache gets seeded during the first render. `initialParallelRoutes` ensures the cache from the first render is there during the second render.
parallelRoutes: isServer ? new Map() : initialParallelRoutes
};
// When the cache hasn't been seeded yet we fill the cache with the head.
if (initialParallelRoutes === null || initialParallelRoutes.size === 0) {
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(cache, undefined, initialTree, initialHead);
}
var // the || operator is intentional, the pathname can be an empty string
_ref;
return {
buildId,
tree: initialTree,
cache,
prefetchCache: new Map(),
pushRef: {
pendingPush: false,
mpaNavigation: false
},
focusAndScrollRef: {
apply: false,
onlyHashChange: false,
hashFragment: null,
segmentPaths: []
},
canonicalUrl: // location.href is read as the initial value for canonicalUrl in the browser
// This is safe to do as canonicalUrl can't be rendered, it's only used to control the history updates in the useEffect further down in this file.
location ? (0, _createhreffromurl.createHrefFromUrl)(location) : initialCanonicalUrl,
nextUrl: (_ref = (0, _computechangedpath.extractPathFromFlightRouterState)(initialTree) || (location == null ? void 0 : location.pathname)) != null ? _ref : null
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=create-initial-router-state.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/create-initial-router-state.ts"],"names":["createInitialRouterState","buildId","initialTree","children","initialCanonicalUrl","initialParallelRoutes","isServer","location","initialHead","cache","status","CacheStates","READY","data","subTreeData","parallelRoutes","Map","size","fillLazyItemsTillLeafWithHead","undefined","extractPathFromFlightRouterState","tree","prefetchCache","pushRef","pendingPush","mpaNavigation","focusAndScrollRef","apply","onlyHashChange","hashFragment","segmentPaths","canonicalUrl","createHrefFromUrl","nextUrl","pathname"],"mappings":";;;;+BAoBgBA;;;eAAAA;;;+CAhBY;mCACM;+CACY;oCACG;AAa1C,SAASA,yBAAyB,KASV;IATU,IAAA,EACvCC,OAAO,EACPC,WAAW,EACXC,QAAQ,EACRC,mBAAmB,EACnBC,qBAAqB,EACrBC,QAAQ,EACRC,QAAQ,EACRC,WAAW,EACkB,GATU;IAUvC,MAAMC,QAAmB;QACvBC,QAAQC,0CAAW,CAACC,KAAK;QACzBC,MAAM;QACNC,aAAaX;QACb,oJAAoJ;QACpJY,gBAAgBT,WAAW,IAAIU,QAAQX;IACzC;IAEA,yEAAyE;IACzE,IAAIA,0BAA0B,QAAQA,sBAAsBY,IAAI,KAAK,GAAG;QACtEC,IAAAA,4DAA6B,EAACT,OAAOU,WAAWjB,aAAaM;IAC/D;QAsBI,sEAAsE;IACrEY;IArBL,OAAO;QACLnB;QACAoB,MAAMnB;QACNO;QACAa,eAAe,IAAIN;QACnBO,SAAS;YAAEC,aAAa;YAAOC,eAAe;QAAM;QACpDC,mBAAmB;YACjBC,OAAO;YACPC,gBAAgB;YAChBC,cAAc;YACdC,cAAc,EAAE;QAClB;QACAC,cACE,6EAA6E;QAC7E,kJAAkJ;QAClJxB,WAEIyB,IAAAA,oCAAiB,EAACzB,YAClBH;QACN6B,SAEE,CAACb,OAAAA,IAAAA,oDAAgC,EAAClB,iBAAgBK,4BAAAA,SAAU2B,QAAQ,aAAnEd,OACD;IACJ;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,6 @@
import type { FlightRouterState } from '../../../server/app-render/types';
/**
* Create optimistic version of router state based on the existing router state and segments.
* This is used to allow rendering layout-routers up till the point where data is missing.
*/
export declare function createOptimisticTree(segments: string[], flightRouterState: FlightRouterState | null, parentRefetch: boolean): FlightRouterState;

View File

@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createOptimisticTree", {
enumerable: true,
get: function() {
return createOptimisticTree;
}
});
const _matchsegments = require("../match-segments");
function createOptimisticTree(segments, flightRouterState, parentRefetch) {
const [existingSegment, existingParallelRoutes, url, refresh, isRootLayout] = flightRouterState || [
null,
{}
];
const segment = segments[0];
const isLastSegment = segments.length === 1;
const segmentMatches = existingSegment !== null && (0, _matchsegments.matchSegment)(existingSegment, segment);
// if there are multiple parallel routes at this level, we need to refetch here
// to ensure we get the correct tree. This is because we don't know which
// parallel route will match the next segment.
const hasMultipleParallelRoutes = Object.keys(existingParallelRoutes).length > 1;
const shouldRefetchThisLevel = !flightRouterState || !segmentMatches || hasMultipleParallelRoutes;
let parallelRoutes = {};
if (existingSegment !== null && segmentMatches) {
parallelRoutes = existingParallelRoutes;
}
let childTree;
// if there's multiple parallel routes at this level, we shouldn't create an
// optimistic tree for the next level because we don't know which one will
// match the next segment.
if (!isLastSegment && !hasMultipleParallelRoutes) {
const childItem = createOptimisticTree(segments.slice(1), parallelRoutes ? parallelRoutes.children : null, parentRefetch || shouldRefetchThisLevel);
childTree = childItem;
}
const result = [
segment,
{
...parallelRoutes,
...childTree ? {
children: childTree
} : {}
}
];
if (url) {
result[2] = url;
}
if (!parentRefetch && shouldRefetchThisLevel) {
result[3] = "refetch";
} else if (segmentMatches && refresh) {
result[3] = refresh;
}
if (segmentMatches && isRootLayout) {
result[4] = isRootLayout;
}
return result;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=create-optimistic-tree.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/create-optimistic-tree.ts"],"names":["createOptimisticTree","segments","flightRouterState","parentRefetch","existingSegment","existingParallelRoutes","url","refresh","isRootLayout","segment","isLastSegment","length","segmentMatches","matchSegment","hasMultipleParallelRoutes","Object","keys","shouldRefetchThisLevel","parallelRoutes","childTree","childItem","slice","children","result"],"mappings":";;;;+BAOgBA;;;eAAAA;;;+BANa;AAMtB,SAASA,qBACdC,QAAkB,EAClBC,iBAA2C,EAC3CC,aAAsB;IAEtB,MAAM,CAACC,iBAAiBC,wBAAwBC,KAAKC,SAASC,aAAa,GACzEN,qBAAqB;QAAC;QAAM,CAAC;KAAE;IACjC,MAAMO,UAAUR,QAAQ,CAAC,EAAE;IAC3B,MAAMS,gBAAgBT,SAASU,MAAM,KAAK;IAE1C,MAAMC,iBACJR,oBAAoB,QAAQS,IAAAA,2BAAY,EAACT,iBAAiBK;IAE5D,+EAA+E;IAC/E,yEAAyE;IACzE,8CAA8C;IAC9C,MAAMK,4BACJC,OAAOC,IAAI,CAACX,wBAAwBM,MAAM,GAAG;IAC/C,MAAMM,yBACJ,CAACf,qBAAqB,CAACU,kBAAkBE;IAE3C,IAAII,iBAAuC,CAAC;IAC5C,IAAId,oBAAoB,QAAQQ,gBAAgB;QAC9CM,iBAAiBb;IACnB;IAEA,IAAIc;IAEJ,4EAA4E;IAC5E,0EAA0E;IAC1E,0BAA0B;IAC1B,IAAI,CAACT,iBAAiB,CAACI,2BAA2B;QAChD,MAAMM,YAAYpB,qBAChBC,SAASoB,KAAK,CAAC,IACfH,iBAAiBA,eAAeI,QAAQ,GAAG,MAC3CnB,iBAAiBc;QAGnBE,YAAYC;IACd;IAEA,MAAMG,SAA4B;QAChCd;QACA;YACE,GAAGS,cAAc;YACjB,GAAIC,YAAY;gBAAEG,UAAUH;YAAU,IAAI,CAAC,CAAC;QAC9C;KACD;IAED,IAAIb,KAAK;QACPiB,MAAM,CAAC,EAAE,GAAGjB;IACd;IAEA,IAAI,CAACH,iBAAiBc,wBAAwB;QAC5CM,MAAM,CAAC,EAAE,GAAG;IACd,OAAO,IAAIX,kBAAkBL,SAAS;QACpCgB,MAAM,CAAC,EAAE,GAAGhB;IACd;IAEA,IAAIK,kBAAkBJ,cAAc;QAClCe,MAAM,CAAC,EAAE,GAAGf;IACd;IAEA,OAAOe;AACT"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,4 @@
/**
* Create data fetching record for Promise.
*/
export declare function createRecordFromThenable(thenable: any): any;

View File

@@ -0,0 +1,36 @@
/**
* Create data fetching record for Promise.
*/ // TODO-APP: change `any` to type inference.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createRecordFromThenable", {
enumerable: true,
get: function() {
return createRecordFromThenable;
}
});
function createRecordFromThenable(thenable) {
thenable.status = "pending";
thenable.then((value)=>{
if (thenable.status === "pending") {
thenable.status = "fulfilled";
thenable.value = value;
}
}, (err)=>{
if (thenable.status === "pending") {
thenable.status = "rejected";
thenable.value = err;
}
});
return thenable;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=create-record-from-thenable.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/create-record-from-thenable.ts"],"names":["createRecordFromThenable","thenable","status","then","value","err"],"mappings":"AAAA;;CAEC,GACD,4CAA4C;;;;;+BAC5BA;;;eAAAA;;;AAAT,SAASA,yBAAyBC,QAAa;IACpDA,SAASC,MAAM,GAAG;IAClBD,SAASE,IAAI,CACX,CAACC;QACC,IAAIH,SAASC,MAAM,KAAK,WAAW;YACjCD,SAASC,MAAM,GAAG;YAClBD,SAASG,KAAK,GAAGA;QACnB;IACF,GACA,CAACC;QACC,IAAIJ,SAASC,MAAM,KAAK,WAAW;YACjCD,SAASC,MAAM,GAAG;YAClBD,SAASG,KAAK,GAAGC;QACnB;IACF;IAEF,OAAOJ;AACT"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import { Segment } from '../../../server/app-render/types';
export declare function createRouterCacheKey(segment: Segment, withoutSearchParameters?: boolean): string;

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createRouterCacheKey", {
enumerable: true,
get: function() {
return createRouterCacheKey;
}
});
function createRouterCacheKey(segment, withoutSearchParameters) {
if (withoutSearchParameters === void 0) withoutSearchParameters = false;
return Array.isArray(segment) ? segment[0] + "|" + segment[1] + "|" + segment[2] : withoutSearchParameters && segment.startsWith("__PAGE__") ? "__PAGE__" : segment;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=create-router-cache-key.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/create-router-cache-key.ts"],"names":["createRouterCacheKey","segment","withoutSearchParameters","Array","isArray","startsWith"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,qBACdC,OAAgB,EAChBC,uBAAwC;IAAxCA,IAAAA,oCAAAA,0BAAmC;IAEnC,OAAOC,MAAMC,OAAO,CAACH,WACjB,AAAGA,OAAO,CAAC,EAAE,GAAC,MAAGA,OAAO,CAAC,EAAE,GAAC,MAAGA,OAAO,CAAC,EAAE,GACzCC,2BAA2BD,QAAQI,UAAU,CAAC,cAC9C,aACAJ;AACN"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,11 @@
import type { FlightRouterState, FlightData } from '../../../server/app-render/types';
import { PrefetchKind } from './router-reducer-types';
type FetchServerResponseResult = [
flightData: FlightData,
canonicalUrlOverride: URL | undefined
];
/**
* Fetch the flight data for the provided url. Takes in the current router state to decide what to render server-side.
*/
export declare function fetchServerResponse(url: URL, flightRouterState: FlightRouterState, nextUrl: string | null, currentBuildId: string, prefetchKind?: PrefetchKind): Promise<FetchServerResponseResult>;
export {};

View File

@@ -0,0 +1,114 @@
"use client";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fetchServerResponse", {
enumerable: true,
get: function() {
return fetchServerResponse;
}
});
const _approuterheaders = require("../app-router-headers");
const _approuter = require("../app-router");
const _appcallserver = require("../../app-call-server");
const _routerreducertypes = require("./router-reducer-types");
const _hash = require("../../../shared/lib/hash");
// @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies
// import { createFromFetch } from 'react-server-dom-webpack/client'
const { createFromFetch } = !!process.env.NEXT_RUNTIME ? require("react-server-dom-webpack/client.edge") : require("react-server-dom-webpack/client");
function doMpaNavigation(url) {
return [
(0, _approuter.urlToUrlWithoutFlightMarker)(url).toString(),
undefined
];
}
async function fetchServerResponse(url, flightRouterState, nextUrl, currentBuildId, prefetchKind) {
const headers = {
// Enable flight response
[_approuterheaders.RSC]: "1",
// Provide the current router state
[_approuterheaders.NEXT_ROUTER_STATE_TREE]: encodeURIComponent(JSON.stringify(flightRouterState))
};
/**
* Three cases:
* - `prefetchKind` is `undefined`, it means it's a normal navigation, so we want to prefetch the page data fully
* - `prefetchKind` is `full` - we want to prefetch the whole page so same as above
* - `prefetchKind` is `auto` - if the page is dynamic, prefetch the page data partially, if static prefetch the page data fully
*/ if (prefetchKind === _routerreducertypes.PrefetchKind.AUTO) {
headers[_approuterheaders.NEXT_ROUTER_PREFETCH] = "1";
}
if (nextUrl) {
headers[_approuterheaders.NEXT_URL] = nextUrl;
}
const uniqueCacheQuery = (0, _hash.hexHash)([
headers[_approuterheaders.NEXT_ROUTER_PREFETCH] || "0",
headers[_approuterheaders.NEXT_ROUTER_STATE_TREE],
headers[_approuterheaders.NEXT_URL]
].join(","));
try {
let fetchUrl = new URL(url);
if (process.env.NODE_ENV === "production") {
if (process.env.__NEXT_CONFIG_OUTPUT === "export") {
if (fetchUrl.pathname.endsWith("/")) {
fetchUrl.pathname += "index.txt";
} else {
fetchUrl.pathname += ".txt";
}
}
}
// Add unique cache query to avoid caching conflicts on CDN which don't respect to Vary header
fetchUrl.searchParams.set(_approuterheaders.NEXT_RSC_UNION_QUERY, uniqueCacheQuery);
const res = await fetch(fetchUrl, {
// Backwards compat for older browsers. `same-origin` is the default in modern browsers.
credentials: "same-origin",
headers
});
const responseUrl = (0, _approuter.urlToUrlWithoutFlightMarker)(res.url);
const canonicalUrl = res.redirected ? responseUrl : undefined;
const contentType = res.headers.get("content-type") || "";
let isFlightResponse = contentType === _approuterheaders.RSC_CONTENT_TYPE_HEADER;
if (process.env.NODE_ENV === "production") {
if (process.env.__NEXT_CONFIG_OUTPUT === "export") {
if (!isFlightResponse) {
isFlightResponse = contentType.startsWith("text/plain");
}
}
}
// If fetch returns something different than flight response handle it like a mpa navigation
// If the fetch was not 200, we also handle it like a mpa navigation
if (!isFlightResponse || !res.ok) {
return doMpaNavigation(responseUrl.toString());
}
// Handle the `fetch` readable stream that can be unwrapped by `React.use`.
const [buildId, flightData] = await createFromFetch(Promise.resolve(res), {
callServer: _appcallserver.callServer
});
if (currentBuildId !== buildId) {
return doMpaNavigation(res.url);
}
return [
flightData,
canonicalUrl
];
} catch (err) {
console.error("Failed to fetch RSC payload. Falling back to browser navigation.", err);
// If fetch fails handle it like a mpa navigation
// TODO-APP: Add a test for the case where a CORS request fails, e.g. external url redirect coming from the response.
// See https://github.com/vercel/next.js/issues/43605#issuecomment-1451617521 for a reproduction.
return [
url.toString(),
undefined
];
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=fetch-server-response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/fetch-server-response.ts"],"names":["fetchServerResponse","createFromFetch","process","env","NEXT_RUNTIME","require","doMpaNavigation","url","urlToUrlWithoutFlightMarker","toString","undefined","flightRouterState","nextUrl","currentBuildId","prefetchKind","headers","RSC","NEXT_ROUTER_STATE_TREE","encodeURIComponent","JSON","stringify","PrefetchKind","AUTO","NEXT_ROUTER_PREFETCH","NEXT_URL","uniqueCacheQuery","hexHash","join","fetchUrl","URL","NODE_ENV","__NEXT_CONFIG_OUTPUT","pathname","endsWith","searchParams","set","NEXT_RSC_UNION_QUERY","res","fetch","credentials","responseUrl","canonicalUrl","redirected","contentType","get","isFlightResponse","RSC_CONTENT_TYPE_HEADER","startsWith","ok","buildId","flightData","Promise","resolve","callServer","err","console","error"],"mappings":"AAAA;;;;;+BA2CsBA;;;eAAAA;;;kCAlBf;2BACqC;+BACjB;oCACE;sBACL;AA3BxB,aAAa;AACb,6DAA6D;AAC7D,oEAAoE;AACpE,MAAM,EAAEC,eAAe,EAAE,GACvB,CAAC,CAACC,QAAQC,GAAG,CAACC,YAAY,GAEtBC,QAAQ,0CAERA,QAAQ;AA0Bd,SAASC,gBAAgBC,GAAW;IAClC,OAAO;QAACC,IAAAA,sCAA2B,EAACD,KAAKE,QAAQ;QAAIC;KAAU;AACjE;AAKO,eAAeV,oBACpBO,GAAQ,EACRI,iBAAoC,EACpCC,OAAsB,EACtBC,cAAsB,EACtBC,YAA2B;IAE3B,MAAMC,UAKF;QACF,yBAAyB;QACzB,CAACC,qBAAG,CAAC,EAAE;QACP,mCAAmC;QACnC,CAACC,wCAAsB,CAAC,EAAEC,mBACxBC,KAAKC,SAAS,CAACT;IAEnB;IAEA;;;;;GAKC,GACD,IAAIG,iBAAiBO,gCAAY,CAACC,IAAI,EAAE;QACtCP,OAAO,CAACQ,sCAAoB,CAAC,GAAG;IAClC;IAEA,IAAIX,SAAS;QACXG,OAAO,CAACS,0BAAQ,CAAC,GAAGZ;IACtB;IAEA,MAAMa,mBAAmBC,IAAAA,aAAO,EAC9B;QACEX,OAAO,CAACQ,sCAAoB,CAAC,IAAI;QACjCR,OAAO,CAACE,wCAAsB,CAAC;QAC/BF,OAAO,CAACS,0BAAQ,CAAC;KAClB,CAACG,IAAI,CAAC;IAGT,IAAI;QACF,IAAIC,WAAW,IAAIC,IAAItB;QACvB,IAAIL,QAAQC,GAAG,CAAC2B,QAAQ,KAAK,cAAc;YACzC,IAAI5B,QAAQC,GAAG,CAAC4B,oBAAoB,KAAK,UAAU;gBACjD,IAAIH,SAASI,QAAQ,CAACC,QAAQ,CAAC,MAAM;oBACnCL,SAASI,QAAQ,IAAI;gBACvB,OAAO;oBACLJ,SAASI,QAAQ,IAAI;gBACvB;YACF;QACF;QAEA,8FAA8F;QAC9FJ,SAASM,YAAY,CAACC,GAAG,CAACC,sCAAoB,EAAEX;QAEhD,MAAMY,MAAM,MAAMC,MAAMV,UAAU;YAChC,wFAAwF;YACxFW,aAAa;YACbxB;QACF;QAEA,MAAMyB,cAAchC,IAAAA,sCAA2B,EAAC6B,IAAI9B,GAAG;QACvD,MAAMkC,eAAeJ,IAAIK,UAAU,GAAGF,cAAc9B;QAEpD,MAAMiC,cAAcN,IAAItB,OAAO,CAAC6B,GAAG,CAAC,mBAAmB;QACvD,IAAIC,mBAAmBF,gBAAgBG,yCAAuB;QAE9D,IAAI5C,QAAQC,GAAG,CAAC2B,QAAQ,KAAK,cAAc;YACzC,IAAI5B,QAAQC,GAAG,CAAC4B,oBAAoB,KAAK,UAAU;gBACjD,IAAI,CAACc,kBAAkB;oBACrBA,mBAAmBF,YAAYI,UAAU,CAAC;gBAC5C;YACF;QACF;QAEA,4FAA4F;QAC5F,oEAAoE;QACpE,IAAI,CAACF,oBAAoB,CAACR,IAAIW,EAAE,EAAE;YAChC,OAAO1C,gBAAgBkC,YAAY/B,QAAQ;QAC7C;QAEA,2EAA2E;QAC3E,MAAM,CAACwC,SAASC,WAAW,GAAuB,MAAMjD,gBACtDkD,QAAQC,OAAO,CAACf,MAChB;YACEgB,YAAAA,yBAAU;QACZ;QAGF,IAAIxC,mBAAmBoC,SAAS;YAC9B,OAAO3C,gBAAgB+B,IAAI9B,GAAG;QAChC;QAEA,OAAO;YAAC2C;YAAYT;SAAa;IACnC,EAAE,OAAOa,KAAK;QACZC,QAAQC,KAAK,CACX,oEACAF;QAEF,iDAAiD;QACjD,qHAAqH;QACrH,iGAAiG;QACjG,OAAO;YAAC/C,IAAIE,QAAQ;YAAIC;SAAU;IACpC;AACF"}

View File

@@ -0,0 +1,9 @@
import { FlightSegmentPath } from '../../../server/app-render/types';
import { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import { fetchServerResponse } from './fetch-server-response';
/**
* Kick off fetch based on the common layout between two routes. Fill cache with data property holding the in-progress fetch.
*/
export declare function fillCacheWithDataProperty(newCache: CacheNode, existingCache: CacheNode, flightSegmentPath: FlightSegmentPath, fetchResponse: () => ReturnType<typeof fetchServerResponse>, bailOnParallelRoutes?: boolean): {
bailOptimistic: boolean;
} | undefined;

View File

@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fillCacheWithDataProperty", {
enumerable: true,
get: function() {
return fillCacheWithDataProperty;
}
});
const _approutercontextsharedruntime = require("../../../shared/lib/app-router-context.shared-runtime");
const _createroutercachekey = require("./create-router-cache-key");
function fillCacheWithDataProperty(newCache, existingCache, flightSegmentPath, fetchResponse, bailOnParallelRoutes) {
if (bailOnParallelRoutes === void 0) bailOnParallelRoutes = false;
const isLastEntry = flightSegmentPath.length <= 2;
const [parallelRouteKey, segment] = flightSegmentPath;
const cacheKey = (0, _createroutercachekey.createRouterCacheKey)(segment);
const existingChildSegmentMap = existingCache.parallelRoutes.get(parallelRouteKey);
if (!existingChildSegmentMap || bailOnParallelRoutes && existingCache.parallelRoutes.size > 1) {
// Bailout because the existing cache does not have the path to the leaf node
// or the existing cache has multiple parallel routes
// Will trigger lazy fetch in layout-router because of missing segment
return {
bailOptimistic: true
};
}
let childSegmentMap = newCache.parallelRoutes.get(parallelRouteKey);
if (!childSegmentMap || childSegmentMap === existingChildSegmentMap) {
childSegmentMap = new Map(existingChildSegmentMap);
newCache.parallelRoutes.set(parallelRouteKey, childSegmentMap);
}
const existingChildCacheNode = existingChildSegmentMap.get(cacheKey);
let childCacheNode = childSegmentMap.get(cacheKey);
// In case of last segment start off the fetch at this level and don't copy further down.
if (isLastEntry) {
if (!childCacheNode || !childCacheNode.data || childCacheNode === existingChildCacheNode) {
childSegmentMap.set(cacheKey, {
status: _approutercontextsharedruntime.CacheStates.DATA_FETCH,
data: fetchResponse(),
subTreeData: null,
parallelRoutes: new Map()
});
}
return;
}
if (!childCacheNode || !existingChildCacheNode) {
// Start fetch in the place where the existing cache doesn't have the data yet.
if (!childCacheNode) {
childSegmentMap.set(cacheKey, {
status: _approutercontextsharedruntime.CacheStates.DATA_FETCH,
data: fetchResponse(),
subTreeData: null,
parallelRoutes: new Map()
});
}
return;
}
if (childCacheNode === existingChildCacheNode) {
childCacheNode = {
status: childCacheNode.status,
data: childCacheNode.data,
subTreeData: childCacheNode.subTreeData,
parallelRoutes: new Map(childCacheNode.parallelRoutes)
};
childSegmentMap.set(cacheKey, childCacheNode);
}
return fillCacheWithDataProperty(childCacheNode, existingChildCacheNode, flightSegmentPath.slice(2), fetchResponse);
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=fill-cache-with-data-property.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/fill-cache-with-data-property.ts"],"names":["fillCacheWithDataProperty","newCache","existingCache","flightSegmentPath","fetchResponse","bailOnParallelRoutes","isLastEntry","length","parallelRouteKey","segment","cacheKey","createRouterCacheKey","existingChildSegmentMap","parallelRoutes","get","size","bailOptimistic","childSegmentMap","Map","set","existingChildCacheNode","childCacheNode","data","status","CacheStates","DATA_FETCH","subTreeData","slice"],"mappings":";;;;+BAWgBA;;;eAAAA;;;+CAPT;sCAC8B;AAM9B,SAASA,0BACdC,QAAmB,EACnBC,aAAwB,EACxBC,iBAAoC,EACpCC,aAA2D,EAC3DC,oBAAqC;IAArCA,IAAAA,iCAAAA,uBAAgC;IAEhC,MAAMC,cAAcH,kBAAkBI,MAAM,IAAI;IAEhD,MAAM,CAACC,kBAAkBC,QAAQ,GAAGN;IACpC,MAAMO,WAAWC,IAAAA,0CAAoB,EAACF;IAEtC,MAAMG,0BACJV,cAAcW,cAAc,CAACC,GAAG,CAACN;IAEnC,IACE,CAACI,2BACAP,wBAAwBH,cAAcW,cAAc,CAACE,IAAI,GAAG,GAC7D;QACA,6EAA6E;QAC7E,qDAAqD;QACrD,sEAAsE;QACtE,OAAO;YAAEC,gBAAgB;QAAK;IAChC;IAEA,IAAIC,kBAAkBhB,SAASY,cAAc,CAACC,GAAG,CAACN;IAElD,IAAI,CAACS,mBAAmBA,oBAAoBL,yBAAyB;QACnEK,kBAAkB,IAAIC,IAAIN;QAC1BX,SAASY,cAAc,CAACM,GAAG,CAACX,kBAAkBS;IAChD;IAEA,MAAMG,yBAAyBR,wBAAwBE,GAAG,CAACJ;IAC3D,IAAIW,iBAAiBJ,gBAAgBH,GAAG,CAACJ;IAEzC,yFAAyF;IACzF,IAAIJ,aAAa;QACf,IACE,CAACe,kBACD,CAACA,eAAeC,IAAI,IACpBD,mBAAmBD,wBACnB;YACAH,gBAAgBE,GAAG,CAACT,UAAU;gBAC5Ba,QAAQC,0CAAW,CAACC,UAAU;gBAC9BH,MAAMlB;gBACNsB,aAAa;gBACbb,gBAAgB,IAAIK;YACtB;QACF;QACA;IACF;IAEA,IAAI,CAACG,kBAAkB,CAACD,wBAAwB;QAC9C,+EAA+E;QAC/E,IAAI,CAACC,gBAAgB;YACnBJ,gBAAgBE,GAAG,CAACT,UAAU;gBAC5Ba,QAAQC,0CAAW,CAACC,UAAU;gBAC9BH,MAAMlB;gBACNsB,aAAa;gBACbb,gBAAgB,IAAIK;YACtB;QACF;QACA;IACF;IAEA,IAAIG,mBAAmBD,wBAAwB;QAC7CC,iBAAiB;YACfE,QAAQF,eAAeE,MAAM;YAC7BD,MAAMD,eAAeC,IAAI;YACzBI,aAAaL,eAAeK,WAAW;YACvCb,gBAAgB,IAAIK,IAAIG,eAAeR,cAAc;QACvD;QACAI,gBAAgBE,GAAG,CAACT,UAAUW;IAChC;IAEA,OAAOrB,0BACLqB,gBACAD,wBACAjB,kBAAkBwB,KAAK,CAAC,IACxBvB;AAEJ"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,6 @@
import { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import type { FlightDataPath } from '../../../server/app-render/types';
/**
* Fill cache with subTreeData based on flightDataPath
*/
export declare function fillCacheWithNewSubTreeData(newCache: CacheNode, existingCache: CacheNode, flightDataPath: FlightDataPath, wasPrefetched?: boolean): void;

View File

@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fillCacheWithNewSubTreeData", {
enumerable: true,
get: function() {
return fillCacheWithNewSubTreeData;
}
});
const _approutercontextsharedruntime = require("../../../shared/lib/app-router-context.shared-runtime");
const _invalidatecachebyrouterstate = require("./invalidate-cache-by-router-state");
const _filllazyitemstillleafwithhead = require("./fill-lazy-items-till-leaf-with-head");
const _createroutercachekey = require("./create-router-cache-key");
function fillCacheWithNewSubTreeData(newCache, existingCache, flightDataPath, wasPrefetched) {
const isLastEntry = flightDataPath.length <= 5;
const [parallelRouteKey, segment] = flightDataPath;
const cacheKey = (0, _createroutercachekey.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);
}
const existingChildCacheNode = existingChildSegmentMap.get(cacheKey);
let childCacheNode = childSegmentMap.get(cacheKey);
if (isLastEntry) {
if (!childCacheNode || !childCacheNode.data || childCacheNode === existingChildCacheNode) {
childCacheNode = {
status: _approutercontextsharedruntime.CacheStates.READY,
data: null,
subTreeData: flightDataPath[3],
// Ensure segments other than the one we got data for are preserved.
parallelRoutes: existingChildCacheNode ? new Map(existingChildCacheNode.parallelRoutes) : new Map()
};
if (existingChildCacheNode) {
(0, _invalidatecachebyrouterstate.invalidateCacheByRouterState)(childCacheNode, existingChildCacheNode, flightDataPath[2]);
}
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(childCacheNode, existingChildCacheNode, flightDataPath[2], flightDataPath[4], wasPrefetched);
childSegmentMap.set(cacheKey, childCacheNode);
}
return;
}
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);
}
fillCacheWithNewSubTreeData(childCacheNode, existingChildCacheNode, flightDataPath.slice(2), wasPrefetched);
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=fill-cache-with-new-subtree-data.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/fill-cache-with-new-subtree-data.ts"],"names":["fillCacheWithNewSubTreeData","newCache","existingCache","flightDataPath","wasPrefetched","isLastEntry","length","parallelRouteKey","segment","cacheKey","createRouterCacheKey","existingChildSegmentMap","parallelRoutes","get","childSegmentMap","Map","set","existingChildCacheNode","childCacheNode","data","status","CacheStates","READY","subTreeData","invalidateCacheByRouterState","fillLazyItemsTillLeafWithHead","slice"],"mappings":";;;;+BAYgBA;;;eAAAA;;;+CATT;8CAEsC;+CACC;sCACT;AAK9B,SAASA,4BACdC,QAAmB,EACnBC,aAAwB,EACxBC,cAA8B,EAC9BC,aAAuB;IAEvB,MAAMC,cAAcF,eAAeG,MAAM,IAAI;IAC7C,MAAM,CAACC,kBAAkBC,QAAQ,GAAGL;IAEpC,MAAMM,WAAWC,IAAAA,0CAAoB,EAACF;IAEtC,MAAMG,0BACJT,cAAcU,cAAc,CAACC,GAAG,CAACN;IAEnC,IAAI,CAACI,yBAAyB;QAC5B,6EAA6E;QAC7E,sEAAsE;QACtE;IACF;IAEA,IAAIG,kBAAkBb,SAASW,cAAc,CAACC,GAAG,CAACN;IAClD,IAAI,CAACO,mBAAmBA,oBAAoBH,yBAAyB;QACnEG,kBAAkB,IAAIC,IAAIJ;QAC1BV,SAASW,cAAc,CAACI,GAAG,CAACT,kBAAkBO;IAChD;IAEA,MAAMG,yBAAyBN,wBAAwBE,GAAG,CAACJ;IAC3D,IAAIS,iBAAiBJ,gBAAgBD,GAAG,CAACJ;IAEzC,IAAIJ,aAAa;QACf,IACE,CAACa,kBACD,CAACA,eAAeC,IAAI,IACpBD,mBAAmBD,wBACnB;YACAC,iBAAiB;gBACfE,QAAQC,0CAAW,CAACC,KAAK;gBACzBH,MAAM;gBACNI,aAAapB,cAAc,CAAC,EAAE;gBAC9B,oEAAoE;gBACpES,gBAAgBK,yBACZ,IAAIF,IAAIE,uBAAuBL,cAAc,IAC7C,IAAIG;YACV;YAEA,IAAIE,wBAAwB;gBAC1BO,IAAAA,0DAA4B,EAC1BN,gBACAD,wBACAd,cAAc,CAAC,EAAE;YAErB;YAEAsB,IAAAA,4DAA6B,EAC3BP,gBACAD,wBACAd,cAAc,CAAC,EAAE,EACjBA,cAAc,CAAC,EAAE,EACjBC;YAGFU,gBAAgBE,GAAG,CAACP,UAAUS;QAChC;QACA;IACF;IAEA,IAAI,CAACA,kBAAkB,CAACD,wBAAwB;QAC9C,6EAA6E;QAC7E,sEAAsE;QACtE;IACF;IAEA,IAAIC,mBAAmBD,wBAAwB;QAC7CC,iBAAiB;YACfE,QAAQF,eAAeE,MAAM;YAC7BD,MAAMD,eAAeC,IAAI;YACzBI,aAAaL,eAAeK,WAAW;YACvCX,gBAAgB,IAAIG,IAAIG,eAAeN,cAAc;QACvD;QACAE,gBAAgBE,GAAG,CAACP,UAAUS;IAChC;IAEAlB,4BACEkB,gBACAD,wBACAd,eAAeuB,KAAK,CAAC,IACrBtB;AAEJ"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,4 @@
/// <reference types="react" />
import { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import type { FlightRouterState } from '../../../server/app-render/types';
export declare function fillLazyItemsTillLeafWithHead(newCache: CacheNode, existingCache: CacheNode | undefined, routerState: FlightRouterState, head: React.ReactNode, wasPrefetched?: boolean): void;

View File

@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fillLazyItemsTillLeafWithHead", {
enumerable: true,
get: function() {
return fillLazyItemsTillLeafWithHead;
}
});
const _approutercontextsharedruntime = require("../../../shared/lib/app-router-context.shared-runtime");
const _createroutercachekey = require("./create-router-cache-key");
function fillLazyItemsTillLeafWithHead(newCache, existingCache, routerState, head, wasPrefetched) {
const isLastSegment = Object.keys(routerState[1]).length === 0;
if (isLastSegment) {
newCache.head = head;
return;
}
// Remove segment that we got data for so that it is filled in during rendering of subTreeData.
for(const key in routerState[1]){
const parallelRouteState = routerState[1][key];
const segmentForParallelRoute = parallelRouteState[0];
const cacheKey = (0, _createroutercachekey.createRouterCacheKey)(segmentForParallelRoute);
if (existingCache) {
const existingParallelRoutesCacheNode = existingCache.parallelRoutes.get(key);
if (existingParallelRoutesCacheNode) {
let parallelRouteCacheNode = new Map(existingParallelRoutesCacheNode);
const existingCacheNode = parallelRouteCacheNode.get(cacheKey);
const newCacheNode = wasPrefetched && existingCacheNode ? {
status: existingCacheNode.status,
data: existingCacheNode.data,
subTreeData: existingCacheNode.subTreeData,
parallelRoutes: new Map(existingCacheNode.parallelRoutes)
} : {
status: _approutercontextsharedruntime.CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(existingCacheNode == null ? void 0 : existingCacheNode.parallelRoutes)
};
// Overrides the cache key with the new cache node.
parallelRouteCacheNode.set(cacheKey, newCacheNode);
// Traverse deeper to apply the head / fill lazy items till the head.
fillLazyItemsTillLeafWithHead(newCacheNode, existingCacheNode, parallelRouteState, head, wasPrefetched);
newCache.parallelRoutes.set(key, parallelRouteCacheNode);
continue;
}
}
const newCacheNode = {
status: _approutercontextsharedruntime.CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map()
};
const existingParallelRoutes = newCache.parallelRoutes.get(key);
if (existingParallelRoutes) {
existingParallelRoutes.set(cacheKey, newCacheNode);
} else {
newCache.parallelRoutes.set(key, new Map([
[
cacheKey,
newCacheNode
]
]));
}
fillLazyItemsTillLeafWithHead(newCacheNode, undefined, parallelRouteState, head, wasPrefetched);
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=fill-lazy-items-till-leaf-with-head.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/fill-lazy-items-till-leaf-with-head.ts"],"names":["fillLazyItemsTillLeafWithHead","newCache","existingCache","routerState","head","wasPrefetched","isLastSegment","Object","keys","length","key","parallelRouteState","segmentForParallelRoute","cacheKey","createRouterCacheKey","existingParallelRoutesCacheNode","parallelRoutes","get","parallelRouteCacheNode","Map","existingCacheNode","newCacheNode","status","data","subTreeData","CacheStates","LAZY_INITIALIZED","set","existingParallelRoutes","undefined"],"mappings":";;;;+BAOgBA;;;eAAAA;;;+CAJT;sCAE8B;AAE9B,SAASA,8BACdC,QAAmB,EACnBC,aAAoC,EACpCC,WAA8B,EAC9BC,IAAqB,EACrBC,aAAuB;IAEvB,MAAMC,gBAAgBC,OAAOC,IAAI,CAACL,WAAW,CAAC,EAAE,EAAEM,MAAM,KAAK;IAC7D,IAAIH,eAAe;QACjBL,SAASG,IAAI,GAAGA;QAChB;IACF;IACA,+FAA+F;IAC/F,IAAK,MAAMM,OAAOP,WAAW,CAAC,EAAE,CAAE;QAChC,MAAMQ,qBAAqBR,WAAW,CAAC,EAAE,CAACO,IAAI;QAC9C,MAAME,0BAA0BD,kBAAkB,CAAC,EAAE;QACrD,MAAME,WAAWC,IAAAA,0CAAoB,EAACF;QAEtC,IAAIV,eAAe;YACjB,MAAMa,kCACJb,cAAcc,cAAc,CAACC,GAAG,CAACP;YACnC,IAAIK,iCAAiC;gBACnC,IAAIG,yBAAyB,IAAIC,IAAIJ;gBACrC,MAAMK,oBAAoBF,uBAAuBD,GAAG,CAACJ;gBACrD,MAAMQ,eACJhB,iBAAiBe,oBACZ;oBACCE,QAAQF,kBAAkBE,MAAM;oBAChCC,MAAMH,kBAAkBG,IAAI;oBAC5BC,aAAaJ,kBAAkBI,WAAW;oBAC1CR,gBAAgB,IAAIG,IAAIC,kBAAkBJ,cAAc;gBAC1D,IACA;oBACEM,QAAQG,0CAAW,CAACC,gBAAgB;oBACpCH,MAAM;oBACNC,aAAa;oBACbR,gBAAgB,IAAIG,IAAIC,qCAAAA,kBAAmBJ,cAAc;gBAC3D;gBACN,mDAAmD;gBACnDE,uBAAuBS,GAAG,CAACd,UAAUQ;gBACrC,qEAAqE;gBACrErB,8BACEqB,cACAD,mBACAT,oBACAP,MACAC;gBAGFJ,SAASe,cAAc,CAACW,GAAG,CAACjB,KAAKQ;gBACjC;YACF;QACF;QAEA,MAAMG,eAA0B;YAC9BC,QAAQG,0CAAW,CAACC,gBAAgB;YACpCH,MAAM;YACNC,aAAa;YACbR,gBAAgB,IAAIG;QACtB;QAEA,MAAMS,yBAAyB3B,SAASe,cAAc,CAACC,GAAG,CAACP;QAC3D,IAAIkB,wBAAwB;YAC1BA,uBAAuBD,GAAG,CAACd,UAAUQ;QACvC,OAAO;YACLpB,SAASe,cAAc,CAACW,GAAG,CAACjB,KAAK,IAAIS,IAAI;gBAAC;oBAACN;oBAAUQ;iBAAa;aAAC;QACrE;QAEArB,8BACEqB,cACAQ,WACAlB,oBACAP,MACAC;IAEJ;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,8 @@
import { PrefetchCacheEntry } from './router-reducer-types';
export declare enum PrefetchCacheEntryStatus {
fresh = "fresh",
reusable = "reusable",
expired = "expired",
stale = "stale"
}
export declare function getPrefetchEntryCacheStatus({ kind, prefetchTime, lastUsedTime, }: PrefetchCacheEntry): PrefetchCacheEntryStatus;

View File

@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
PrefetchCacheEntryStatus: null,
getPrefetchEntryCacheStatus: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
PrefetchCacheEntryStatus: function() {
return PrefetchCacheEntryStatus;
},
getPrefetchEntryCacheStatus: function() {
return getPrefetchEntryCacheStatus;
}
});
const FIVE_MINUTES = 5 * 60 * 1000;
const THIRTY_SECONDS = 30 * 1000;
var PrefetchCacheEntryStatus;
(function(PrefetchCacheEntryStatus) {
PrefetchCacheEntryStatus["fresh"] = "fresh";
PrefetchCacheEntryStatus["reusable"] = "reusable";
PrefetchCacheEntryStatus["expired"] = "expired";
PrefetchCacheEntryStatus["stale"] = "stale";
})(PrefetchCacheEntryStatus || (PrefetchCacheEntryStatus = {}));
function getPrefetchEntryCacheStatus(param) {
let { kind, prefetchTime, lastUsedTime } = param;
// if the cache entry was prefetched or read less than 30s ago, then we want to re-use it
if (Date.now() < (lastUsedTime != null ? lastUsedTime : prefetchTime) + THIRTY_SECONDS) {
return lastUsedTime ? "reusable" : "fresh";
}
// if the cache entry was prefetched less than 5 mins ago, then we want to re-use only the loading state
if (kind === "auto") {
if (Date.now() < prefetchTime + FIVE_MINUTES) {
return "stale";
}
}
// if the cache entry was prefetched less than 5 mins ago and was a "full" prefetch, then we want to re-use it "full
if (kind === "full") {
if (Date.now() < prefetchTime + FIVE_MINUTES) {
return "reusable";
}
}
return "expired";
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=get-prefetch-cache-entry-status.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/get-prefetch-cache-entry-status.ts"],"names":["getPrefetchEntryCacheStatus","FIVE_MINUTES","THIRTY_SECONDS","PrefetchCacheEntryStatus","fresh","reusable","expired","stale","kind","prefetchTime","lastUsedTime","Date","now"],"mappings":";;;;;;;;;;;;;;;;;;IAYgBA,2BAA2B;eAA3BA;;;AAVhB,MAAMC,eAAe,IAAI,KAAK;AAC9B,MAAMC,iBAAiB,KAAK;IAErB;UAAKC,wBAAwB;IAAxBA,yBACVC,WAAAA;IADUD,yBAEVE,cAAAA;IAFUF,yBAGVG,aAAAA;IAHUH,yBAIVI,WAAAA;GAJUJ,6BAAAA;AAOL,SAASH,4BAA4B,KAIvB;IAJuB,IAAA,EAC1CQ,IAAI,EACJC,YAAY,EACZC,YAAY,EACO,GAJuB;IAK1C,yFAAyF;IACzF,IAAIC,KAAKC,GAAG,KAAK,AAACF,CAAAA,uBAAAA,eAAgBD,YAAW,IAAKP,gBAAgB;QAChE,OAAOQ,eAZE,aADH;IAgBR;IAEA,wGAAwG;IACxG,IAAIF,SAAS,QAAQ;QACnB,IAAIG,KAAKC,GAAG,KAAKH,eAAeR,cAAc;YAC5C,OAlBI;QAmBN;IACF;IAEA,oHAAoH;IACpH,IAAIO,SAAS,QAAQ;QACnB,IAAIG,KAAKC,GAAG,KAAKH,eAAeR,cAAc;YAC5C,OA3BO;QA4BT;IACF;IAEA,OA9BU;AA+BZ"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import { Mutable, ReadonlyReducerState, ReducerState } from './router-reducer-types';
export declare function handleMutable(state: ReadonlyReducerState, mutable: Mutable): ReducerState;

View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "handleMutable", {
enumerable: true,
get: function() {
return handleMutable;
}
});
const _computechangedpath = require("./compute-changed-path");
function handleMutable(state, mutable) {
var _mutable_canonicalUrl;
var _mutable_shouldScroll;
// shouldScroll is true by default, can override to false.
const shouldScroll = (_mutable_shouldScroll = mutable.shouldScroll) != null ? _mutable_shouldScroll : true;
var _mutable_scrollableSegments, _computeChangedPath;
return {
buildId: state.buildId,
// Set href.
canonicalUrl: mutable.canonicalUrl != null ? mutable.canonicalUrl === state.canonicalUrl ? state.canonicalUrl : mutable.canonicalUrl : state.canonicalUrl,
pushRef: {
pendingPush: mutable.pendingPush != null ? mutable.pendingPush : state.pushRef.pendingPush,
mpaNavigation: mutable.mpaNavigation != null ? mutable.mpaNavigation : state.pushRef.mpaNavigation
},
// All navigation requires scroll and focus management to trigger.
focusAndScrollRef: {
apply: shouldScroll ? (mutable == null ? void 0 : mutable.scrollableSegments) !== undefined ? true : state.focusAndScrollRef.apply : false,
onlyHashChange: !!mutable.hashFragment && state.canonicalUrl.split("#")[0] === ((_mutable_canonicalUrl = mutable.canonicalUrl) == null ? void 0 : _mutable_canonicalUrl.split("#")[0]),
hashFragment: shouldScroll ? // #top is handled in layout-router.
mutable.hashFragment && mutable.hashFragment !== "" ? decodeURIComponent(mutable.hashFragment.slice(1)) : state.focusAndScrollRef.hashFragment : null,
segmentPaths: shouldScroll ? (_mutable_scrollableSegments = mutable == null ? void 0 : mutable.scrollableSegments) != null ? _mutable_scrollableSegments : state.focusAndScrollRef.segmentPaths : []
},
// Apply cache.
cache: mutable.cache ? mutable.cache : state.cache,
prefetchCache: mutable.prefetchCache ? mutable.prefetchCache : state.prefetchCache,
// Apply patched router state.
tree: mutable.patchedTree !== undefined ? mutable.patchedTree : state.tree,
nextUrl: mutable.patchedTree !== undefined ? (_computeChangedPath = (0, _computechangedpath.computeChangedPath)(state.tree, mutable.patchedTree)) != null ? _computeChangedPath : state.canonicalUrl : state.nextUrl
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=handle-mutable.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/handle-mutable.ts"],"names":["handleMutable","state","mutable","shouldScroll","computeChangedPath","buildId","canonicalUrl","pushRef","pendingPush","mpaNavigation","focusAndScrollRef","apply","scrollableSegments","undefined","onlyHashChange","hashFragment","split","decodeURIComponent","slice","segmentPaths","cache","prefetchCache","tree","patchedTree","nextUrl"],"mappings":";;;;+BAOgBA;;;eAAAA;;;oCAPmB;AAO5B,SAASA,cACdC,KAA2B,EAC3BC,OAAgB;QAmCRA;QAhCaA;IADrB,0DAA0D;IAC1D,MAAMC,eAAeD,CAAAA,wBAAAA,QAAQC,YAAY,YAApBD,wBAAwB;QA2CrCA,6BAaAE;IAtDR,OAAO;QACLC,SAASJ,MAAMI,OAAO;QACtB,YAAY;QACZC,cACEJ,QAAQI,YAAY,IAAI,OACpBJ,QAAQI,YAAY,KAAKL,MAAMK,YAAY,GACzCL,MAAMK,YAAY,GAClBJ,QAAQI,YAAY,GACtBL,MAAMK,YAAY;QACxBC,SAAS;YACPC,aACEN,QAAQM,WAAW,IAAI,OACnBN,QAAQM,WAAW,GACnBP,MAAMM,OAAO,CAACC,WAAW;YAC/BC,eACEP,QAAQO,aAAa,IAAI,OACrBP,QAAQO,aAAa,GACrBR,MAAMM,OAAO,CAACE,aAAa;QACnC;QACA,kEAAkE;QAClEC,mBAAmB;YACjBC,OAAOR,eACHD,CAAAA,2BAAAA,QAASU,kBAAkB,MAAKC,YAC9B,OACAZ,MAAMS,iBAAiB,CAACC,KAAK,GAE/B;YACJG,gBACE,CAAC,CAACZ,QAAQa,YAAY,IACtBd,MAAMK,YAAY,CAACU,KAAK,CAAC,IAAI,CAAC,EAAE,OAC9Bd,wBAAAA,QAAQI,YAAY,qBAApBJ,sBAAsBc,KAAK,CAAC,IAAI,CAAC,EAAE;YACvCD,cAAcZ,eAEV,oCAAoC;YACpCD,QAAQa,YAAY,IAAIb,QAAQa,YAAY,KAAK,KAE/CE,mBAAmBf,QAAQa,YAAY,CAACG,KAAK,CAAC,MAC9CjB,MAAMS,iBAAiB,CAACK,YAAY,GAEtC;YACJI,cAAchB,eACVD,CAAAA,8BAAAA,2BAAAA,QAASU,kBAAkB,YAA3BV,8BAA+BD,MAAMS,iBAAiB,CAACS,YAAY,GAEnE,EAAE;QACR;QACA,eAAe;QACfC,OAAOlB,QAAQkB,KAAK,GAAGlB,QAAQkB,KAAK,GAAGnB,MAAMmB,KAAK;QAClDC,eAAenB,QAAQmB,aAAa,GAChCnB,QAAQmB,aAAa,GACrBpB,MAAMoB,aAAa;QACvB,8BAA8B;QAC9BC,MAAMpB,QAAQqB,WAAW,KAAKV,YAAYX,QAAQqB,WAAW,GAAGtB,MAAMqB,IAAI;QAC1EE,SACEtB,QAAQqB,WAAW,KAAKV,YACpBT,CAAAA,sBAAAA,IAAAA,sCAAkB,EAACH,MAAMqB,IAAI,EAAEpB,QAAQqB,WAAW,aAAlDnB,sBACAH,MAAMK,YAAY,GAClBL,MAAMuB,OAAO;IACrB;AACF"}

View File

@@ -0,0 +1,6 @@
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import type { FlightSegmentPath } from '../../../server/app-render/types';
/**
* Fill cache up to the end of the flightSegmentPath, invalidating anything below it.
*/
export declare function invalidateCacheBelowFlightSegmentPath(newCache: CacheNode, existingCache: CacheNode, flightSegmentPath: FlightSegmentPath): void;

View File

@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "invalidateCacheBelowFlightSegmentPath", {
enumerable: true,
get: function() {
return invalidateCacheBelowFlightSegmentPath;
}
});
const _createroutercachekey = require("./create-router-cache-key");
function invalidateCacheBelowFlightSegmentPath(newCache, existingCache, flightSegmentPath) {
const isLastEntry = flightSegmentPath.length <= 2;
const [parallelRouteKey, segment] = flightSegmentPath;
const cacheKey = (0, _createroutercachekey.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));
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=invalidate-cache-below-flight-segmentpath.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/invalidate-cache-below-flight-segmentpath.ts"],"names":["invalidateCacheBelowFlightSegmentPath","newCache","existingCache","flightSegmentPath","isLastEntry","length","parallelRouteKey","segment","cacheKey","createRouterCacheKey","existingChildSegmentMap","parallelRoutes","get","childSegmentMap","Map","set","delete","existingChildCacheNode","childCacheNode","status","data","subTreeData","slice"],"mappings":";;;;+BAOgBA;;;eAAAA;;;sCALqB;AAK9B,SAASA,sCACdC,QAAmB,EACnBC,aAAwB,EACxBC,iBAAoC;IAEpC,MAAMC,cAAcD,kBAAkBE,MAAM,IAAI;IAChD,MAAM,CAACC,kBAAkBC,QAAQ,GAAGJ;IAEpC,MAAMK,WAAWC,IAAAA,0CAAoB,EAACF;IAEtC,MAAMG,0BACJR,cAAcS,cAAc,CAACC,GAAG,CAACN;IAEnC,IAAI,CAACI,yBAAyB;QAC5B,6EAA6E;QAC7E,sEAAsE;QACtE;IACF;IAEA,IAAIG,kBAAkBZ,SAASU,cAAc,CAACC,GAAG,CAACN;IAClD,IAAI,CAACO,mBAAmBA,oBAAoBH,yBAAyB;QACnEG,kBAAkB,IAAIC,IAAIJ;QAC1BT,SAASU,cAAc,CAACI,GAAG,CAACT,kBAAkBO;IAChD;IAEA,iDAAiD;IACjD,IAAIT,aAAa;QACfS,gBAAgBG,MAAM,CAACR;QACvB;IACF;IAEA,MAAMS,yBAAyBP,wBAAwBE,GAAG,CAACJ;IAC3D,IAAIU,iBAAiBL,gBAAgBD,GAAG,CAACJ;IAEzC,IAAI,CAACU,kBAAkB,CAACD,wBAAwB;QAC9C,6EAA6E;QAC7E,sEAAsE;QACtE;IACF;IAEA,IAAIC,mBAAmBD,wBAAwB;QAC7CC,iBAAiB;YACfC,QAAQD,eAAeC,MAAM;YAC7BC,MAAMF,eAAeE,IAAI;YACzBC,aAAaH,eAAeG,WAAW;YACvCV,gBAAgB,IAAIG,IAAII,eAAeP,cAAc;QACvD;QACAE,gBAAgBE,GAAG,CAACP,UAAUU;IAChC;IAEAlB,sCACEkB,gBACAD,wBACAd,kBAAkBmB,KAAK,CAAC;AAE5B"}

View File

@@ -0,0 +1,6 @@
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime';
import type { FlightRouterState } from '../../../server/app-render/types';
/**
* Invalidate cache one level down from the router state.
*/
export declare function invalidateCacheByRouterState(newCache: CacheNode, existingCache: CacheNode, routerState: FlightRouterState): void;

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "invalidateCacheByRouterState", {
enumerable: true,
get: function() {
return invalidateCacheByRouterState;
}
});
const _createroutercachekey = require("./create-router-cache-key");
function invalidateCacheByRouterState(newCache, existingCache, routerState) {
// Remove segment that we got data for so that it is filled in during rendering of subTreeData.
for(const key in routerState[1]){
const segmentForParallelRoute = routerState[1][key][0];
const cacheKey = (0, _createroutercachekey.createRouterCacheKey)(segmentForParallelRoute);
const existingParallelRoutesCacheNode = existingCache.parallelRoutes.get(key);
if (existingParallelRoutesCacheNode) {
let parallelRouteCacheNode = new Map(existingParallelRoutesCacheNode);
parallelRouteCacheNode.delete(cacheKey);
newCache.parallelRoutes.set(key, parallelRouteCacheNode);
}
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=invalidate-cache-by-router-state.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/invalidate-cache-by-router-state.ts"],"names":["invalidateCacheByRouterState","newCache","existingCache","routerState","key","segmentForParallelRoute","cacheKey","createRouterCacheKey","existingParallelRoutesCacheNode","parallelRoutes","get","parallelRouteCacheNode","Map","delete","set"],"mappings":";;;;+BAOgBA;;;eAAAA;;;sCALqB;AAK9B,SAASA,6BACdC,QAAmB,EACnBC,aAAwB,EACxBC,WAA8B;IAE9B,+FAA+F;IAC/F,IAAK,MAAMC,OAAOD,WAAW,CAAC,EAAE,CAAE;QAChC,MAAME,0BAA0BF,WAAW,CAAC,EAAE,CAACC,IAAI,CAAC,EAAE;QACtD,MAAME,WAAWC,IAAAA,0CAAoB,EAACF;QACtC,MAAMG,kCACJN,cAAcO,cAAc,CAACC,GAAG,CAACN;QACnC,IAAII,iCAAiC;YACnC,IAAIG,yBAAyB,IAAIC,IAAIJ;YACrCG,uBAAuBE,MAAM,CAACP;YAC9BL,SAASQ,cAAc,CAACK,GAAG,CAACV,KAAKO;QACnC;IACF;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import type { FlightRouterState } from '../../../server/app-render/types';
export declare function isNavigatingToNewRootLayout(currentTree: FlightRouterState, nextTree: FlightRouterState): boolean;

View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "isNavigatingToNewRootLayout", {
enumerable: true,
get: function() {
return isNavigatingToNewRootLayout;
}
});
function isNavigatingToNewRootLayout(currentTree, nextTree) {
// Compare segments
const currentTreeSegment = currentTree[0];
const nextTreeSegment = nextTree[0];
// If any segment is different before we find the root layout, the root layout has changed.
// E.g. /same/(group1)/layout.js -> /same/(group2)/layout.js
// First segment is 'same' for both, keep looking. (group1) changed to (group2) before the root layout was found, it must have changed.
if (Array.isArray(currentTreeSegment) && Array.isArray(nextTreeSegment)) {
// Compare dynamic param name and type but ignore the value, different values would not affect the current root layout
// /[name] - /slug1 and /slug2, both values (slug1 & slug2) still has the same layout /[name]/layout.js
if (currentTreeSegment[0] !== nextTreeSegment[0] || currentTreeSegment[2] !== nextTreeSegment[2]) {
return true;
}
} else if (currentTreeSegment !== nextTreeSegment) {
return true;
}
// Current tree root layout found
if (currentTree[4]) {
// If the next tree doesn't have the root layout flag, it must have changed.
return !nextTree[4];
}
// Current tree didn't have its root layout here, must have changed.
if (nextTree[4]) {
return true;
}
// We can't assume it's `parallelRoutes.children` here in case the root layout is `app/@something/layout.js`
// But it's not possible to be more than one parallelRoutes before the root layout is found
// TODO-APP: change to traverse all parallel routes
const currentTreeChild = Object.values(currentTree[1])[0];
const nextTreeChild = Object.values(nextTree[1])[0];
if (!currentTreeChild || !nextTreeChild) return true;
return isNavigatingToNewRootLayout(currentTreeChild, nextTreeChild);
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=is-navigating-to-new-root-layout.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/is-navigating-to-new-root-layout.ts"],"names":["isNavigatingToNewRootLayout","currentTree","nextTree","currentTreeSegment","nextTreeSegment","Array","isArray","currentTreeChild","Object","values","nextTreeChild"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,4BACdC,WAA8B,EAC9BC,QAA2B;IAE3B,mBAAmB;IACnB,MAAMC,qBAAqBF,WAAW,CAAC,EAAE;IACzC,MAAMG,kBAAkBF,QAAQ,CAAC,EAAE;IACnC,2FAA2F;IAC3F,4DAA4D;IAC5D,uIAAuI;IACvI,IAAIG,MAAMC,OAAO,CAACH,uBAAuBE,MAAMC,OAAO,CAACF,kBAAkB;QACvE,sHAAsH;QACtH,uGAAuG;QACvG,IACED,kBAAkB,CAAC,EAAE,KAAKC,eAAe,CAAC,EAAE,IAC5CD,kBAAkB,CAAC,EAAE,KAAKC,eAAe,CAAC,EAAE,EAC5C;YACA,OAAO;QACT;IACF,OAAO,IAAID,uBAAuBC,iBAAiB;QACjD,OAAO;IACT;IAEA,iCAAiC;IACjC,IAAIH,WAAW,CAAC,EAAE,EAAE;QAClB,4EAA4E;QAC5E,OAAO,CAACC,QAAQ,CAAC,EAAE;IACrB;IACA,qEAAqE;IACrE,IAAIA,QAAQ,CAAC,EAAE,EAAE;QACf,OAAO;IACT;IACA,4GAA4G;IAC5G,2FAA2F;IAC3F,mDAAmD;IACnD,MAAMK,mBAAmBC,OAAOC,MAAM,CAACR,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE;IACzD,MAAMS,gBAAgBF,OAAOC,MAAM,CAACP,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE;IACnD,IAAI,CAACK,oBAAoB,CAACG,eAAe,OAAO;IAChD,OAAOV,4BAA4BO,kBAAkBG;AACvD"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,4 @@
/**
* Read record value or throw Promise if it's not resolved yet.
*/
export declare function readRecordValue<T>(thenable: Promise<T>): T;

View File

@@ -0,0 +1,29 @@
/**
* Read record value or throw Promise if it's not resolved yet.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "readRecordValue", {
enumerable: true,
get: function() {
return readRecordValue;
}
});
function readRecordValue(thenable) {
// @ts-expect-error TODO: fix type
if (thenable.status === "fulfilled") {
// @ts-expect-error TODO: fix type
return thenable.value;
} else {
throw thenable;
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=read-record-value.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/router-reducer/read-record-value.ts"],"names":["readRecordValue","thenable","status","value"],"mappings":"AAAA;;CAEC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,gBAAmBC,QAAoB;IACrD,kCAAkC;IAClC,IAAIA,SAASC,MAAM,KAAK,aAAa;QACnC,kCAAkC;QAClC,OAAOD,SAASE,KAAK;IACvB,OAAO;QACL,MAAMF;IACR;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,4 @@
import { ReadonlyReducerState, ReducerState, FastRefreshAction } from '../router-reducer-types';
declare function fastRefreshReducerNoop(state: ReadonlyReducerState, _action: FastRefreshAction): ReducerState;
export declare const fastRefreshReducer: typeof fastRefreshReducerNoop;
export {};

View File

@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fastRefreshReducer", {
enumerable: true,
get: function() {
return fastRefreshReducer;
}
});
const _fetchserverresponse = require("../fetch-server-response");
const _createrecordfromthenable = require("../create-record-from-thenable");
const _readrecordvalue = require("../read-record-value");
const _createhreffromurl = require("../create-href-from-url");
const _applyrouterstatepatchtotree = require("../apply-router-state-patch-to-tree");
const _isnavigatingtonewrootlayout = require("../is-navigating-to-new-root-layout");
const _navigatereducer = require("./navigate-reducer");
const _handlemutable = require("../handle-mutable");
const _applyflightdata = require("../apply-flight-data");
// A version of refresh reducer that keeps the cache around instead of wiping all of it.
function fastRefreshReducerImpl(state, action) {
const { cache, mutable, origin } = action;
const href = state.canonicalUrl;
const isForCurrentTree = JSON.stringify(mutable.previousTree) === JSON.stringify(state.tree);
if (isForCurrentTree) {
return (0, _handlemutable.handleMutable)(state, mutable);
}
if (!cache.data) {
// TODO-APP: verify that `href` is not an external url.
// Fetch data from the root of the tree.
cache.data = (0, _createrecordfromthenable.createRecordFromThenable)((0, _fetchserverresponse.fetchServerResponse)(new URL(href, origin), [
state.tree[0],
state.tree[1],
state.tree[2],
"refetch"
], state.nextUrl, state.buildId));
}
const [flightData, canonicalUrlOverride] = (0, _readrecordvalue.readRecordValue)(cache.data);
// Handle case when navigating to page in `pages` from `app`
if (typeof flightData === "string") {
return (0, _navigatereducer.handleExternalUrl)(state, mutable, flightData, state.pushRef.pendingPush);
}
// Remove cache.data as it has been resolved at this point.
cache.data = null;
let currentTree = state.tree;
let currentCache = state.cache;
for (const flightDataPath of flightData){
// FlightDataPath with more than two items means unexpected Flight data was returned
if (flightDataPath.length !== 3) {
// TODO-APP: handle this case better
console.log("REFRESH FAILED");
return state;
}
// Given the path can only have two items the items are only the router state and subTreeData for the root.
const [treePatch] = flightDataPath;
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
[
""
], currentTree, treePatch);
if (newTree === null) {
throw new Error("SEGMENT MISMATCH");
}
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
return (0, _navigatereducer.handleExternalUrl)(state, mutable, href, state.pushRef.pendingPush);
}
const canonicalUrlOverrideHref = canonicalUrlOverride ? (0, _createhreffromurl.createHrefFromUrl)(canonicalUrlOverride) : undefined;
if (canonicalUrlOverride) {
mutable.canonicalUrl = canonicalUrlOverrideHref;
}
const applied = (0, _applyflightdata.applyFlightData)(currentCache, cache, flightDataPath);
if (applied) {
mutable.cache = cache;
currentCache = cache;
}
mutable.previousTree = currentTree;
mutable.patchedTree = newTree;
mutable.canonicalUrl = href;
currentTree = newTree;
}
return (0, _handlemutable.handleMutable)(state, mutable);
}
function fastRefreshReducerNoop(state, _action) {
return state;
}
const fastRefreshReducer = process.env.NODE_ENV === "production" ? fastRefreshReducerNoop : fastRefreshReducerImpl;
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=fast-refresh-reducer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/fast-refresh-reducer.ts"],"names":["fastRefreshReducer","fastRefreshReducerImpl","state","action","cache","mutable","origin","href","canonicalUrl","isForCurrentTree","JSON","stringify","previousTree","tree","handleMutable","data","createRecordFromThenable","fetchServerResponse","URL","nextUrl","buildId","flightData","canonicalUrlOverride","readRecordValue","handleExternalUrl","pushRef","pendingPush","currentTree","currentCache","flightDataPath","length","console","log","treePatch","newTree","applyRouterStatePatchToTree","Error","isNavigatingToNewRootLayout","canonicalUrlOverrideHref","createHrefFromUrl","undefined","applied","applyFlightData","patchedTree","fastRefreshReducerNoop","_action","process","env","NODE_ENV"],"mappings":";;;;+BAmHaA;;;eAAAA;;;qCAnHuB;0CACK;iCACT;mCACE;6CACU;6CACA;iCAMV;+BACJ;iCACE;AAEhC,wFAAwF;AACxF,SAASC,uBACPC,KAA2B,EAC3BC,MAAyB;IAEzB,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGH;IACnC,MAAMI,OAAOL,MAAMM,YAAY;IAE/B,MAAMC,mBACJC,KAAKC,SAAS,CAACN,QAAQO,YAAY,MAAMF,KAAKC,SAAS,CAACT,MAAMW,IAAI;IAEpE,IAAIJ,kBAAkB;QACpB,OAAOK,IAAAA,4BAAa,EAACZ,OAAOG;IAC9B;IAEA,IAAI,CAACD,MAAMW,IAAI,EAAE;QACf,uDAAuD;QACvD,wCAAwC;QACxCX,MAAMW,IAAI,GAAGC,IAAAA,kDAAwB,EACnCC,IAAAA,wCAAmB,EACjB,IAAIC,IAAIX,MAAMD,SACd;YAACJ,MAAMW,IAAI,CAAC,EAAE;YAAEX,MAAMW,IAAI,CAAC,EAAE;YAAEX,MAAMW,IAAI,CAAC,EAAE;YAAE;SAAU,EACxDX,MAAMiB,OAAO,EACbjB,MAAMkB,OAAO;IAGnB;IACA,MAAM,CAACC,YAAYC,qBAAqB,GAAGC,IAAAA,gCAAe,EAACnB,MAAMW,IAAI;IAErE,4DAA4D;IAC5D,IAAI,OAAOM,eAAe,UAAU;QAClC,OAAOG,IAAAA,kCAAiB,EACtBtB,OACAG,SACAgB,YACAnB,MAAMuB,OAAO,CAACC,WAAW;IAE7B;IAEA,2DAA2D;IAC3DtB,MAAMW,IAAI,GAAG;IAEb,IAAIY,cAAczB,MAAMW,IAAI;IAC5B,IAAIe,eAAe1B,MAAME,KAAK;IAE9B,KAAK,MAAMyB,kBAAkBR,WAAY;QACvC,oFAAoF;QACpF,IAAIQ,eAAeC,MAAM,KAAK,GAAG;YAC/B,oCAAoC;YACpCC,QAAQC,GAAG,CAAC;YACZ,OAAO9B;QACT;QAEA,2GAA2G;QAC3G,MAAM,CAAC+B,UAAU,GAAGJ;QACpB,MAAMK,UAAUC,IAAAA,wDAA2B,EACzC,sBAAsB;QACtB;YAAC;SAAG,EACJR,aACAM;QAGF,IAAIC,YAAY,MAAM;YACpB,MAAM,IAAIE,MAAM;QAClB;QAEA,IAAIC,IAAAA,wDAA2B,EAACV,aAAaO,UAAU;YACrD,OAAOV,IAAAA,kCAAiB,EAACtB,OAAOG,SAASE,MAAML,MAAMuB,OAAO,CAACC,WAAW;QAC1E;QAEA,MAAMY,2BAA2BhB,uBAC7BiB,IAAAA,oCAAiB,EAACjB,wBAClBkB;QAEJ,IAAIlB,sBAAsB;YACxBjB,QAAQG,YAAY,GAAG8B;QACzB;QACA,MAAMG,UAAUC,IAAAA,gCAAe,EAACd,cAAcxB,OAAOyB;QAErD,IAAIY,SAAS;YACXpC,QAAQD,KAAK,GAAGA;YAChBwB,eAAexB;QACjB;QAEAC,QAAQO,YAAY,GAAGe;QACvBtB,QAAQsC,WAAW,GAAGT;QACtB7B,QAAQG,YAAY,GAAGD;QAEvBoB,cAAcO;IAChB;IACA,OAAOpB,IAAAA,4BAAa,EAACZ,OAAOG;AAC9B;AAEA,SAASuC,uBACP1C,KAA2B,EAC3B2C,OAA0B;IAE1B,OAAO3C;AACT;AAEO,MAAMF,qBACX8C,QAAQC,GAAG,CAACC,QAAQ,KAAK,eACrBJ,yBACA3C"}

View File

@@ -0,0 +1,4 @@
/// <reference types="react" />
import type { FlightRouterState } from '../../../../server/app-render/types';
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime';
export declare function findHeadInCache(cache: CacheNode, parallelRoutes: FlightRouterState[1]): React.ReactNode;

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "findHeadInCache", {
enumerable: true,
get: function() {
return findHeadInCache;
}
});
const _createroutercachekey = require("../create-router-cache-key");
function findHeadInCache(cache, parallelRoutes) {
const isLastItem = Object.keys(parallelRoutes).length === 0;
if (isLastItem) {
return cache.head;
}
for(const key in parallelRoutes){
const [segment, childParallelRoutes] = parallelRoutes[key];
const childSegmentMap = cache.parallelRoutes.get(key);
if (!childSegmentMap) {
continue;
}
const cacheKey = (0, _createroutercachekey.createRouterCacheKey)(segment);
const cacheNode = childSegmentMap.get(cacheKey);
if (!cacheNode) {
continue;
}
const item = findHeadInCache(cacheNode, childParallelRoutes);
if (item) {
return item;
}
}
return undefined;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=find-head-in-cache.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/find-head-in-cache.ts"],"names":["findHeadInCache","cache","parallelRoutes","isLastItem","Object","keys","length","head","key","segment","childParallelRoutes","childSegmentMap","get","cacheKey","createRouterCacheKey","cacheNode","item","undefined"],"mappings":";;;;+BAIgBA;;;eAAAA;;;sCAFqB;AAE9B,SAASA,gBACdC,KAAgB,EAChBC,cAAoC;IAEpC,MAAMC,aAAaC,OAAOC,IAAI,CAACH,gBAAgBI,MAAM,KAAK;IAC1D,IAAIH,YAAY;QACd,OAAOF,MAAMM,IAAI;IACnB;IACA,IAAK,MAAMC,OAAON,eAAgB;QAChC,MAAM,CAACO,SAASC,oBAAoB,GAAGR,cAAc,CAACM,IAAI;QAC1D,MAAMG,kBAAkBV,MAAMC,cAAc,CAACU,GAAG,CAACJ;QACjD,IAAI,CAACG,iBAAiB;YACpB;QACF;QAEA,MAAME,WAAWC,IAAAA,0CAAoB,EAACL;QAEtC,MAAMM,YAAYJ,gBAAgBC,GAAG,CAACC;QACtC,IAAI,CAACE,WAAW;YACd;QACF;QAEA,MAAMC,OAAOhB,gBAAgBe,WAAWL;QACxC,IAAIM,MAAM;YACR,OAAOA;QACT;IACF;IAEA,OAAOC;AACT"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import { Segment } from '../../../../server/app-render/types';
export declare function getSegmentValue(segment: Segment): string;

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getSegmentValue", {
enumerable: true,
get: function() {
return getSegmentValue;
}
});
function getSegmentValue(segment) {
return Array.isArray(segment) ? segment[1] : segment;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=get-segment-value.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/get-segment-value.ts"],"names":["getSegmentValue","segment","Array","isArray"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,gBAAgBC,OAAgB;IAC9C,OAAOC,MAAMC,OAAO,CAACF,WAAWA,OAAO,CAAC,EAAE,GAAGA;AAC/C"}

View File

@@ -0,0 +1,3 @@
import { Mutable, NavigateAction, ReadonlyReducerState, ReducerState } from '../router-reducer-types';
export declare function handleExternalUrl(state: ReadonlyReducerState, mutable: Mutable, url: string, pendingPush: boolean): import("../router-reducer-types").AppRouterState;
export declare function navigateReducer(state: ReadonlyReducerState, action: NavigateAction): ReducerState;

View File

@@ -0,0 +1,265 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
handleExternalUrl: null,
navigateReducer: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
handleExternalUrl: function() {
return handleExternalUrl;
},
navigateReducer: function() {
return navigateReducer;
}
});
const _approutercontextsharedruntime = require("../../../../shared/lib/app-router-context.shared-runtime");
const _fetchserverresponse = require("../fetch-server-response");
const _createrecordfromthenable = require("../create-record-from-thenable");
const _readrecordvalue = require("../read-record-value");
const _createhreffromurl = require("../create-href-from-url");
const _invalidatecachebelowflightsegmentpath = require("../invalidate-cache-below-flight-segmentpath");
const _fillcachewithdataproperty = require("../fill-cache-with-data-property");
const _createoptimistictree = require("../create-optimistic-tree");
const _applyrouterstatepatchtotree = require("../apply-router-state-patch-to-tree");
const _shouldhardnavigate = require("../should-hard-navigate");
const _isnavigatingtonewrootlayout = require("../is-navigating-to-new-root-layout");
const _routerreducertypes = require("../router-reducer-types");
const _handlemutable = require("../handle-mutable");
const _applyflightdata = require("../apply-flight-data");
const _getprefetchcacheentrystatus = require("../get-prefetch-cache-entry-status");
const _pruneprefetchcache = require("./prune-prefetch-cache");
const _prefetchreducer = require("./prefetch-reducer");
function handleExternalUrl(state, mutable, url, pendingPush) {
mutable.previousTree = state.tree;
mutable.mpaNavigation = true;
mutable.canonicalUrl = url;
mutable.pendingPush = pendingPush;
mutable.scrollableSegments = undefined;
return (0, _handlemutable.handleMutable)(state, mutable);
}
function generateSegmentsFromPatch(flightRouterPatch) {
const segments = [];
const [segment, parallelRoutes] = flightRouterPatch;
if (Object.keys(parallelRoutes).length === 0) {
return [
[
segment
]
];
}
for (const [parallelRouteKey, parallelRoute] of Object.entries(parallelRoutes)){
for (const childSegment of generateSegmentsFromPatch(parallelRoute)){
// If the segment is empty, it means we are at the root of the tree
if (segment === "") {
segments.push([
parallelRouteKey,
...childSegment
]);
} else {
segments.push([
segment,
parallelRouteKey,
...childSegment
]);
}
}
}
return segments;
}
function addRefetchToLeafSegments(newCache, currentCache, flightSegmentPath, treePatch, data) {
let appliedPatch = false;
newCache.status = _approutercontextsharedruntime.CacheStates.READY;
newCache.subTreeData = currentCache.subTreeData;
newCache.parallelRoutes = new Map(currentCache.parallelRoutes);
const segmentPathsToFill = generateSegmentsFromPatch(treePatch).map((segment)=>[
...flightSegmentPath,
...segment
]);
for (const segmentPaths of segmentPathsToFill){
const res = (0, _fillcachewithdataproperty.fillCacheWithDataProperty)(newCache, currentCache, segmentPaths, data);
if (!(res == null ? void 0 : res.bailOptimistic)) {
appliedPatch = true;
}
}
return appliedPatch;
}
function navigateReducer(state, action) {
const { url, isExternalUrl, navigateType, cache, mutable, forceOptimisticNavigation, shouldScroll } = action;
const { pathname, hash } = url;
const href = (0, _createhreffromurl.createHrefFromUrl)(url);
const pendingPush = navigateType === "push";
// we want to prune the prefetch cache on every navigation to avoid it growing too large
(0, _pruneprefetchcache.prunePrefetchCache)(state.prefetchCache);
const isForCurrentTree = JSON.stringify(mutable.previousTree) === JSON.stringify(state.tree);
if (isForCurrentTree) {
return (0, _handlemutable.handleMutable)(state, mutable);
}
if (isExternalUrl) {
return handleExternalUrl(state, mutable, url.toString(), pendingPush);
}
let prefetchValues = state.prefetchCache.get((0, _createhreffromurl.createHrefFromUrl)(url, false));
if (forceOptimisticNavigation && (prefetchValues == null ? void 0 : prefetchValues.kind) !== _routerreducertypes.PrefetchKind.TEMPORARY) {
const segments = pathname.split("/");
// TODO-APP: figure out something better for index pages
segments.push("__PAGE__");
// Optimistic tree case.
// If the optimistic tree is deeper than the current state leave that deeper part out of the fetch
const optimisticTree = (0, _createoptimistictree.createOptimisticTree)(segments, state.tree, false);
// we need a copy of the cache in case we need to revert to it
const temporaryCacheNode = {
...cache
};
// Copy subTreeData for the root node of the cache.
// Note: didn't do it above because typescript doesn't like it.
temporaryCacheNode.status = _approutercontextsharedruntime.CacheStates.READY;
temporaryCacheNode.subTreeData = state.cache.subTreeData;
temporaryCacheNode.parallelRoutes = new Map(state.cache.parallelRoutes);
let data;
const fetchResponse = ()=>{
if (!data) {
data = (0, _createrecordfromthenable.createRecordFromThenable)((0, _fetchserverresponse.fetchServerResponse)(url, optimisticTree, state.nextUrl, state.buildId));
}
return data;
};
// TODO-APP: segments.slice(1) strips '', we can get rid of '' altogether.
// TODO-APP: re-evaluate if we need to strip the last segment
const optimisticFlightSegmentPath = segments.slice(1).map((segment)=>[
"children",
segment
]).flat();
// Copy existing cache nodes as far as possible and fill in `data` property with the started data fetch.
// The `data` property is used to suspend in layout-router during render if it hasn't resolved yet by the time it renders.
const res = (0, _fillcachewithdataproperty.fillCacheWithDataProperty)(temporaryCacheNode, state.cache, optimisticFlightSegmentPath, fetchResponse, true);
// If optimistic fetch couldn't happen it falls back to the non-optimistic case.
if (!(res == null ? void 0 : res.bailOptimistic)) {
mutable.previousTree = state.tree;
mutable.patchedTree = optimisticTree;
mutable.pendingPush = pendingPush;
mutable.hashFragment = hash;
mutable.shouldScroll = shouldScroll;
mutable.scrollableSegments = [];
mutable.cache = temporaryCacheNode;
mutable.canonicalUrl = href;
state.prefetchCache.set((0, _createhreffromurl.createHrefFromUrl)(url, false), {
data: (0, _createrecordfromthenable.createRecordFromThenable)(Promise.resolve(data)),
// this will make sure that the entry will be discarded after 30s
kind: _routerreducertypes.PrefetchKind.TEMPORARY,
prefetchTime: Date.now(),
treeAtTimeOfPrefetch: state.tree,
lastUsedTime: Date.now()
});
return (0, _handlemutable.handleMutable)(state, mutable);
}
}
// If we don't have a prefetch value, we need to create one
if (!prefetchValues) {
const data = (0, _createrecordfromthenable.createRecordFromThenable)((0, _fetchserverresponse.fetchServerResponse)(url, state.tree, state.nextUrl, state.buildId, // in dev, there's never gonna be a prefetch entry so we want to prefetch here
// in order to simulate the behavior of the prefetch cache
process.env.NODE_ENV === "development" ? _routerreducertypes.PrefetchKind.AUTO : undefined));
const newPrefetchValue = {
data: (0, _createrecordfromthenable.createRecordFromThenable)(Promise.resolve(data)),
// this will make sure that the entry will be discarded after 30s
kind: process.env.NODE_ENV === "development" ? _routerreducertypes.PrefetchKind.AUTO : _routerreducertypes.PrefetchKind.TEMPORARY,
prefetchTime: Date.now(),
treeAtTimeOfPrefetch: state.tree,
lastUsedTime: null
};
state.prefetchCache.set((0, _createhreffromurl.createHrefFromUrl)(url, false), newPrefetchValue);
prefetchValues = newPrefetchValue;
}
const prefetchEntryCacheStatus = (0, _getprefetchcacheentrystatus.getPrefetchEntryCacheStatus)(prefetchValues);
// The one before last item is the router state tree patch
const { treeAtTimeOfPrefetch, data } = prefetchValues;
_prefetchreducer.prefetchQueue.bump(data);
// Unwrap cache data with `use` to suspend here (in the reducer) until the fetch resolves.
const [flightData, canonicalUrlOverride] = (0, _readrecordvalue.readRecordValue)(data);
// we only want to mark this once
if (!prefetchValues.lastUsedTime) {
// important: we should only mark the cache node as dirty after we unsuspend from the call above
prefetchValues.lastUsedTime = Date.now();
}
// Handle case when navigating to page in `pages` from `app`
if (typeof flightData === "string") {
return handleExternalUrl(state, mutable, flightData, pendingPush);
}
let currentTree = state.tree;
let currentCache = state.cache;
let scrollableSegments = [];
for (const flightDataPath of flightData){
const flightSegmentPath = flightDataPath.slice(0, -4);
// The one before last item is the router state tree patch
const treePatch = flightDataPath.slice(-3)[0];
// TODO-APP: remove ''
const flightSegmentPathWithLeadingEmpty = [
"",
...flightSegmentPath
];
// Create new tree based on the flightSegmentPath and router state patch
let newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
flightSegmentPathWithLeadingEmpty, currentTree, treePatch);
// If the tree patch can't be applied to the current tree then we use the tree at time of prefetch
// TODO-APP: This should instead fill in the missing pieces in `currentTree` with the data from `treeAtTimeOfPrefetch`, then apply the patch.
if (newTree === null) {
newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
flightSegmentPathWithLeadingEmpty, treeAtTimeOfPrefetch, treePatch);
}
if (newTree !== null) {
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
return handleExternalUrl(state, mutable, href, pendingPush);
}
let applied = (0, _applyflightdata.applyFlightData)(currentCache, cache, flightDataPath, prefetchValues.kind === "auto" && prefetchEntryCacheStatus === _getprefetchcacheentrystatus.PrefetchCacheEntryStatus.reusable);
if (!applied && prefetchEntryCacheStatus === _getprefetchcacheentrystatus.PrefetchCacheEntryStatus.stale) {
applied = addRefetchToLeafSegments(cache, currentCache, flightSegmentPath, treePatch, // eslint-disable-next-line no-loop-func
()=>(0, _fetchserverresponse.fetchServerResponse)(url, currentTree, state.nextUrl, state.buildId));
}
const hardNavigate = (0, _shouldhardnavigate.shouldHardNavigate)(// TODO-APP: remove ''
flightSegmentPathWithLeadingEmpty, currentTree);
if (hardNavigate) {
cache.status = _approutercontextsharedruntime.CacheStates.READY;
// Copy subTreeData for the root node of the cache.
cache.subTreeData = currentCache.subTreeData;
(0, _invalidatecachebelowflightsegmentpath.invalidateCacheBelowFlightSegmentPath)(cache, currentCache, flightSegmentPath);
// Ensure the existing cache value is used when the cache was not invalidated.
mutable.cache = cache;
} else if (applied) {
mutable.cache = cache;
}
currentCache = cache;
currentTree = newTree;
for (const subSegment of generateSegmentsFromPatch(treePatch)){
const scrollableSegmentPath = [
...flightSegmentPath,
...subSegment
];
// Filter out the __DEFAULT__ paths as they shouldn't be scrolled to in this case.
if (scrollableSegmentPath[scrollableSegmentPath.length - 1] !== "__DEFAULT__") {
scrollableSegments.push(scrollableSegmentPath);
}
}
}
}
mutable.previousTree = state.tree;
mutable.patchedTree = currentTree;
mutable.canonicalUrl = canonicalUrlOverride ? (0, _createhreffromurl.createHrefFromUrl)(canonicalUrlOverride) : href;
mutable.pendingPush = pendingPush;
mutable.scrollableSegments = scrollableSegments;
mutable.hashFragment = hash;
mutable.shouldScroll = shouldScroll;
return (0, _handlemutable.handleMutable)(state, mutable);
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=navigate-reducer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,4 @@
import { PrefetchAction, ReducerState, ReadonlyReducerState } from '../router-reducer-types';
import { PromiseQueue } from '../../promise-queue';
export declare const prefetchQueue: PromiseQueue;
export declare function prefetchReducer(state: ReadonlyReducerState, action: PrefetchAction): ReducerState;

View File

@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
prefetchQueue: null,
prefetchReducer: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
prefetchQueue: function() {
return prefetchQueue;
},
prefetchReducer: function() {
return prefetchReducer;
}
});
const _createhreffromurl = require("../create-href-from-url");
const _fetchserverresponse = require("../fetch-server-response");
const _routerreducertypes = require("../router-reducer-types");
const _createrecordfromthenable = require("../create-record-from-thenable");
const _pruneprefetchcache = require("./prune-prefetch-cache");
const _approuterheaders = require("../../app-router-headers");
const _promisequeue = require("../../promise-queue");
const prefetchQueue = new _promisequeue.PromiseQueue(5);
function prefetchReducer(state, action) {
// let's prune the prefetch cache before we do anything else
(0, _pruneprefetchcache.prunePrefetchCache)(state.prefetchCache);
const { url } = action;
url.searchParams.delete(_approuterheaders.NEXT_RSC_UNION_QUERY);
const href = (0, _createhreffromurl.createHrefFromUrl)(url, // Ensures the hash is not part of the cache key as it does not affect fetching the server
false);
const cacheEntry = state.prefetchCache.get(href);
if (cacheEntry) {
/**
* If the cache entry present was marked as temporary, it means that we prefetched it from the navigate reducer,
* where we didn't have the prefetch intent. We want to update it to the new, more accurate, kind here.
*/ if (cacheEntry.kind === _routerreducertypes.PrefetchKind.TEMPORARY) {
state.prefetchCache.set(href, {
...cacheEntry,
kind: action.kind
});
}
/**
* if the prefetch action was a full prefetch and that the current cache entry wasn't one, we want to re-prefetch,
* otherwise we can re-use the current cache entry
**/ if (!(cacheEntry.kind === _routerreducertypes.PrefetchKind.AUTO && action.kind === _routerreducertypes.PrefetchKind.FULL)) {
return state;
}
}
// fetchServerResponse is intentionally not awaited so that it can be unwrapped in the navigate-reducer
const serverResponse = (0, _createrecordfromthenable.createRecordFromThenable)(prefetchQueue.enqueue(()=>(0, _fetchserverresponse.fetchServerResponse)(url, // initialTree is used when history.state.tree is missing because the history state is set in `useEffect` below, it being missing means this is the hydration case.
state.tree, state.nextUrl, state.buildId, action.kind)));
// Create new tree based on the flightSegmentPath and router state patch
state.prefetchCache.set(href, {
// Create new tree based on the flightSegmentPath and router state patch
treeAtTimeOfPrefetch: state.tree,
data: serverResponse,
kind: action.kind,
prefetchTime: Date.now(),
lastUsedTime: null
});
return state;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=prefetch-reducer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/prefetch-reducer.ts"],"names":["prefetchQueue","prefetchReducer","PromiseQueue","state","action","prunePrefetchCache","prefetchCache","url","searchParams","delete","NEXT_RSC_UNION_QUERY","href","createHrefFromUrl","cacheEntry","get","kind","PrefetchKind","TEMPORARY","set","AUTO","FULL","serverResponse","createRecordFromThenable","enqueue","fetchServerResponse","tree","nextUrl","buildId","treeAtTimeOfPrefetch","data","prefetchTime","Date","now","lastUsedTime"],"mappings":";;;;;;;;;;;;;;;IAaaA,aAAa;eAAbA;;IAEGC,eAAe;eAAfA;;;mCAfkB;qCACE;oCAM7B;0CACkC;oCACN;kCACE;8BACR;AAEtB,MAAMD,gBAAgB,IAAIE,0BAAY,CAAC;AAEvC,SAASD,gBACdE,KAA2B,EAC3BC,MAAsB;IAEtB,4DAA4D;IAC5DC,IAAAA,sCAAkB,EAACF,MAAMG,aAAa;IAEtC,MAAM,EAAEC,GAAG,EAAE,GAAGH;IAChBG,IAAIC,YAAY,CAACC,MAAM,CAACC,sCAAoB;IAE5C,MAAMC,OAAOC,IAAAA,oCAAiB,EAC5BL,KACA,0FAA0F;IAC1F;IAGF,MAAMM,aAAaV,MAAMG,aAAa,CAACQ,GAAG,CAACH;IAC3C,IAAIE,YAAY;QACd;;;KAGC,GACD,IAAIA,WAAWE,IAAI,KAAKC,gCAAY,CAACC,SAAS,EAAE;YAC9Cd,MAAMG,aAAa,CAACY,GAAG,CAACP,MAAM;gBAC5B,GAAGE,UAAU;gBACbE,MAAMX,OAAOW,IAAI;YACnB;QACF;QAEA;;;MAGE,GACF,IACE,CACEF,CAAAA,WAAWE,IAAI,KAAKC,gCAAY,CAACG,IAAI,IACrCf,OAAOW,IAAI,KAAKC,gCAAY,CAACI,IAAI,AAAD,GAElC;YACA,OAAOjB;QACT;IACF;IAEA,uGAAuG;IACvG,MAAMkB,iBAAiBC,IAAAA,kDAAwB,EAC7CtB,cAAcuB,OAAO,CAAC,IACpBC,IAAAA,wCAAmB,EACjBjB,KACA,mKAAmK;QACnKJ,MAAMsB,IAAI,EACVtB,MAAMuB,OAAO,EACbvB,MAAMwB,OAAO,EACbvB,OAAOW,IAAI;IAKjB,wEAAwE;IACxEZ,MAAMG,aAAa,CAACY,GAAG,CAACP,MAAM;QAC5B,wEAAwE;QACxEiB,sBAAsBzB,MAAMsB,IAAI;QAChCI,MAAMR;QACNN,MAAMX,OAAOW,IAAI;QACjBe,cAAcC,KAAKC,GAAG;QACtBC,cAAc;IAChB;IAEA,OAAO9B;AACT"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import type { ReducerState } from '../router-reducer-types';
export declare function prunePrefetchCache(prefetchCache: ReducerState['prefetchCache']): void;

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "prunePrefetchCache", {
enumerable: true,
get: function() {
return prunePrefetchCache;
}
});
const _getprefetchcacheentrystatus = require("../get-prefetch-cache-entry-status");
function prunePrefetchCache(prefetchCache) {
for (const [href, prefetchCacheEntry] of prefetchCache){
if ((0, _getprefetchcacheentrystatus.getPrefetchEntryCacheStatus)(prefetchCacheEntry) === _getprefetchcacheentrystatus.PrefetchCacheEntryStatus.expired) {
prefetchCache.delete(href);
}
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=prune-prefetch-cache.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/prune-prefetch-cache.ts"],"names":["prunePrefetchCache","prefetchCache","href","prefetchCacheEntry","getPrefetchEntryCacheStatus","PrefetchCacheEntryStatus","expired","delete"],"mappings":";;;;+BAMgBA;;;eAAAA;;;6CAFT;AAEA,SAASA,mBACdC,aAA4C;IAE5C,KAAK,MAAM,CAACC,MAAMC,mBAAmB,IAAIF,cAAe;QACtD,IACEG,IAAAA,wDAA2B,EAACD,wBAC5BE,qDAAwB,CAACC,OAAO,EAChC;YACAL,cAAcM,MAAM,CAACL;QACvB;IACF;AACF"}

View File

@@ -0,0 +1,2 @@
import { ReadonlyReducerState, ReducerState, RefreshAction } from '../router-reducer-types';
export declare function refreshReducer(state: ReadonlyReducerState, action: RefreshAction): ReducerState;

View File

@@ -0,0 +1,94 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "refreshReducer", {
enumerable: true,
get: function() {
return refreshReducer;
}
});
const _fetchserverresponse = require("../fetch-server-response");
const _createrecordfromthenable = require("../create-record-from-thenable");
const _readrecordvalue = require("../read-record-value");
const _createhreffromurl = require("../create-href-from-url");
const _applyrouterstatepatchtotree = require("../apply-router-state-patch-to-tree");
const _isnavigatingtonewrootlayout = require("../is-navigating-to-new-root-layout");
const _navigatereducer = require("./navigate-reducer");
const _handlemutable = require("../handle-mutable");
const _approutercontextsharedruntime = require("../../../../shared/lib/app-router-context.shared-runtime");
const _filllazyitemstillleafwithhead = require("../fill-lazy-items-till-leaf-with-head");
function refreshReducer(state, action) {
const { cache, mutable, origin } = action;
const href = state.canonicalUrl;
let currentTree = state.tree;
const isForCurrentTree = JSON.stringify(mutable.previousTree) === JSON.stringify(currentTree);
if (isForCurrentTree) {
return (0, _handlemutable.handleMutable)(state, mutable);
}
if (!cache.data) {
// TODO-APP: verify that `href` is not an external url.
// Fetch data from the root of the tree.
cache.data = (0, _createrecordfromthenable.createRecordFromThenable)((0, _fetchserverresponse.fetchServerResponse)(new URL(href, origin), [
currentTree[0],
currentTree[1],
currentTree[2],
"refetch"
], state.nextUrl, state.buildId));
}
const [flightData, canonicalUrlOverride] = (0, _readrecordvalue.readRecordValue)(cache.data);
// Handle case when navigating to page in `pages` from `app`
if (typeof flightData === "string") {
return (0, _navigatereducer.handleExternalUrl)(state, mutable, flightData, state.pushRef.pendingPush);
}
// Remove cache.data as it has been resolved at this point.
cache.data = null;
for (const flightDataPath of flightData){
// FlightDataPath with more than two items means unexpected Flight data was returned
if (flightDataPath.length !== 3) {
// TODO-APP: handle this case better
console.log("REFRESH FAILED");
return state;
}
// Given the path can only have two items the items are only the router state and subTreeData for the root.
const [treePatch] = flightDataPath;
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
[
""
], currentTree, treePatch);
if (newTree === null) {
throw new Error("SEGMENT MISMATCH");
}
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
return (0, _navigatereducer.handleExternalUrl)(state, mutable, href, state.pushRef.pendingPush);
}
const canonicalUrlOverrideHref = canonicalUrlOverride ? (0, _createhreffromurl.createHrefFromUrl)(canonicalUrlOverride) : undefined;
if (canonicalUrlOverride) {
mutable.canonicalUrl = canonicalUrlOverrideHref;
}
// The one before last item is the router state tree patch
const [subTreeData, head] = flightDataPath.slice(-2);
// Handles case where prefetch only returns the router tree patch without rendered components.
if (subTreeData !== null) {
cache.status = _approutercontextsharedruntime.CacheStates.READY;
cache.subTreeData = subTreeData;
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(cache, // Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache.
undefined, treePatch, head);
mutable.cache = cache;
mutable.prefetchCache = new Map();
}
mutable.previousTree = currentTree;
mutable.patchedTree = newTree;
mutable.canonicalUrl = href;
currentTree = newTree;
}
return (0, _handlemutable.handleMutable)(state, mutable);
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=refresh-reducer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/refresh-reducer.ts"],"names":["refreshReducer","state","action","cache","mutable","origin","href","canonicalUrl","currentTree","tree","isForCurrentTree","JSON","stringify","previousTree","handleMutable","data","createRecordFromThenable","fetchServerResponse","URL","nextUrl","buildId","flightData","canonicalUrlOverride","readRecordValue","handleExternalUrl","pushRef","pendingPush","flightDataPath","length","console","log","treePatch","newTree","applyRouterStatePatchToTree","Error","isNavigatingToNewRootLayout","canonicalUrlOverrideHref","createHrefFromUrl","undefined","subTreeData","head","slice","status","CacheStates","READY","fillLazyItemsTillLeafWithHead","prefetchCache","Map","patchedTree"],"mappings":";;;;+BAgBgBA;;;eAAAA;;;qCAhBoB;0CACK;iCACT;mCACE;6CACU;6CACA;iCAMV;+BACJ;+CACF;+CACkB;AAEvC,SAASA,eACdC,KAA2B,EAC3BC,MAAqB;IAErB,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGH;IACnC,MAAMI,OAAOL,MAAMM,YAAY;IAE/B,IAAIC,cAAcP,MAAMQ,IAAI;IAE5B,MAAMC,mBACJC,KAAKC,SAAS,CAACR,QAAQS,YAAY,MAAMF,KAAKC,SAAS,CAACJ;IAE1D,IAAIE,kBAAkB;QACpB,OAAOI,IAAAA,4BAAa,EAACb,OAAOG;IAC9B;IAEA,IAAI,CAACD,MAAMY,IAAI,EAAE;QACf,uDAAuD;QACvD,wCAAwC;QACxCZ,MAAMY,IAAI,GAAGC,IAAAA,kDAAwB,EACnCC,IAAAA,wCAAmB,EACjB,IAAIC,IAAIZ,MAAMD,SACd;YAACG,WAAW,CAAC,EAAE;YAAEA,WAAW,CAAC,EAAE;YAAEA,WAAW,CAAC,EAAE;YAAE;SAAU,EAC3DP,MAAMkB,OAAO,EACblB,MAAMmB,OAAO;IAGnB;IACA,MAAM,CAACC,YAAYC,qBAAqB,GAAGC,IAAAA,gCAAe,EAACpB,MAAMY,IAAI;IAErE,4DAA4D;IAC5D,IAAI,OAAOM,eAAe,UAAU;QAClC,OAAOG,IAAAA,kCAAiB,EACtBvB,OACAG,SACAiB,YACApB,MAAMwB,OAAO,CAACC,WAAW;IAE7B;IAEA,2DAA2D;IAC3DvB,MAAMY,IAAI,GAAG;IAEb,KAAK,MAAMY,kBAAkBN,WAAY;QACvC,oFAAoF;QACpF,IAAIM,eAAeC,MAAM,KAAK,GAAG;YAC/B,oCAAoC;YACpCC,QAAQC,GAAG,CAAC;YACZ,OAAO7B;QACT;QAEA,2GAA2G;QAC3G,MAAM,CAAC8B,UAAU,GAAGJ;QACpB,MAAMK,UAAUC,IAAAA,wDAA2B,EACzC,sBAAsB;QACtB;YAAC;SAAG,EACJzB,aACAuB;QAGF,IAAIC,YAAY,MAAM;YACpB,MAAM,IAAIE,MAAM;QAClB;QAEA,IAAIC,IAAAA,wDAA2B,EAAC3B,aAAawB,UAAU;YACrD,OAAOR,IAAAA,kCAAiB,EAACvB,OAAOG,SAASE,MAAML,MAAMwB,OAAO,CAACC,WAAW;QAC1E;QAEA,MAAMU,2BAA2Bd,uBAC7Be,IAAAA,oCAAiB,EAACf,wBAClBgB;QAEJ,IAAIhB,sBAAsB;YACxBlB,QAAQG,YAAY,GAAG6B;QACzB;QAEA,0DAA0D;QAC1D,MAAM,CAACG,aAAaC,KAAK,GAAGb,eAAec,KAAK,CAAC,CAAC;QAElD,8FAA8F;QAC9F,IAAIF,gBAAgB,MAAM;YACxBpC,MAAMuC,MAAM,GAAGC,0CAAW,CAACC,KAAK;YAChCzC,MAAMoC,WAAW,GAAGA;YACpBM,IAAAA,4DAA6B,EAC3B1C,OACA,4FAA4F;YAC5FmC,WACAP,WACAS;YAEFpC,QAAQD,KAAK,GAAGA;YAChBC,QAAQ0C,aAAa,GAAG,IAAIC;QAC9B;QAEA3C,QAAQS,YAAY,GAAGL;QACvBJ,QAAQ4C,WAAW,GAAGhB;QACtB5B,QAAQG,YAAY,GAAGD;QAEvBE,cAAcwB;IAChB;IAEA,OAAOlB,IAAAA,4BAAa,EAACb,OAAOG;AAC9B"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import { ReadonlyReducerState, ReducerState, RestoreAction } from '../router-reducer-types';
export declare function restoreReducer(state: ReadonlyReducerState, action: RestoreAction): ReducerState;

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "restoreReducer", {
enumerable: true,
get: function() {
return restoreReducer;
}
});
const _createhreffromurl = require("../create-href-from-url");
function restoreReducer(state, action) {
const { url, tree } = action;
const href = (0, _createhreffromurl.createHrefFromUrl)(url);
return {
buildId: state.buildId,
// Set canonical url
canonicalUrl: href,
pushRef: state.pushRef,
focusAndScrollRef: state.focusAndScrollRef,
cache: state.cache,
prefetchCache: state.prefetchCache,
// Restore provided tree
tree: tree,
nextUrl: url.pathname
};
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=restore-reducer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/restore-reducer.ts"],"names":["restoreReducer","state","action","url","tree","href","createHrefFromUrl","buildId","canonicalUrl","pushRef","focusAndScrollRef","cache","prefetchCache","nextUrl","pathname"],"mappings":";;;;+BAOgBA;;;eAAAA;;;mCAPkB;AAO3B,SAASA,eACdC,KAA2B,EAC3BC,MAAqB;IAErB,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAE,GAAGF;IACtB,MAAMG,OAAOC,IAAAA,oCAAiB,EAACH;IAE/B,OAAO;QACLI,SAASN,MAAMM,OAAO;QACtB,oBAAoB;QACpBC,cAAcH;QACdI,SAASR,MAAMQ,OAAO;QACtBC,mBAAmBT,MAAMS,iBAAiB;QAC1CC,OAAOV,MAAMU,KAAK;QAClBC,eAAeX,MAAMW,aAAa;QAClC,wBAAwB;QACxBR,MAAMA;QACNS,SAASV,IAAIW,QAAQ;IACvB;AACF"}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,2 @@
import { ReadonlyReducerState, ReducerState, ServerActionAction } from '../router-reducer-types';
export declare function serverActionReducer(state: ReadonlyReducerState, action: ServerActionAction): ReducerState;

View File

@@ -0,0 +1,209 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "serverActionReducer", {
enumerable: true,
get: function() {
return serverActionReducer;
}
});
const _appcallserver = require("../../../app-call-server");
const _approuterheaders = require("../../app-router-headers");
const _createrecordfromthenable = require("../create-record-from-thenable");
const _readrecordvalue = require("../read-record-value");
const _addbasepath = require("../../../add-base-path");
const _createhreffromurl = require("../create-href-from-url");
const _navigatereducer = require("./navigate-reducer");
const _applyrouterstatepatchtotree = require("../apply-router-state-patch-to-tree");
const _isnavigatingtonewrootlayout = require("../is-navigating-to-new-root-layout");
const _approutercontextsharedruntime = require("../../../../shared/lib/app-router-context.shared-runtime");
const _handlemutable = require("../handle-mutable");
const _filllazyitemstillleafwithhead = require("../fill-lazy-items-till-leaf-with-head");
// // eslint-disable-next-line import/no-extraneous-dependencies
// import { createFromFetch } from 'react-server-dom-webpack/client'
// // eslint-disable-next-line import/no-extraneous-dependencies
// import { encodeReply } from 'react-server-dom-webpack/client'
const { createFromFetch, encodeReply } = !!process.env.NEXT_RUNTIME ? require("react-server-dom-webpack/client.edge") : require("react-server-dom-webpack/client");
async function fetchServerAction(state, param) {
let { actionId, actionArgs } = param;
const body = await encodeReply(actionArgs);
const res = await fetch("", {
method: "POST",
headers: {
Accept: _approuterheaders.RSC_CONTENT_TYPE_HEADER,
[_approuterheaders.ACTION]: actionId,
[_approuterheaders.NEXT_ROUTER_STATE_TREE]: encodeURIComponent(JSON.stringify(state.tree)),
...process.env.__NEXT_ACTIONS_DEPLOYMENT_ID && process.env.NEXT_DEPLOYMENT_ID ? {
"x-deployment-id": process.env.NEXT_DEPLOYMENT_ID
} : {},
...state.nextUrl ? {
[_approuterheaders.NEXT_URL]: state.nextUrl
} : {}
},
body
});
const location = res.headers.get("x-action-redirect");
let revalidatedParts;
try {
const revalidatedHeader = JSON.parse(res.headers.get("x-action-revalidated") || "[[],0,0]");
revalidatedParts = {
paths: revalidatedHeader[0] || [],
tag: !!revalidatedHeader[1],
cookie: revalidatedHeader[2]
};
} catch (e) {
revalidatedParts = {
paths: [],
tag: false,
cookie: false
};
}
const redirectLocation = location ? new URL((0, _addbasepath.addBasePath)(location), // Ensure relative redirects in Server Actions work, e.g. redirect('./somewhere-else')
new URL(state.canonicalUrl, window.location.href)) : undefined;
let isFlightResponse = res.headers.get("content-type") === _approuterheaders.RSC_CONTENT_TYPE_HEADER;
if (isFlightResponse) {
const response = await createFromFetch(Promise.resolve(res), {
callServer: _appcallserver.callServer
});
if (location) {
// if it was a redirection, then result is just a regular RSC payload
const [, actionFlightData] = response != null ? response : [];
return {
actionFlightData: actionFlightData,
redirectLocation,
revalidatedParts
};
}
// otherwise it's a tuple of [actionResult, actionFlightData]
const [actionResult, [, actionFlightData]] = response != null ? response : [];
return {
actionResult,
actionFlightData,
redirectLocation,
revalidatedParts
};
}
return {
redirectLocation,
revalidatedParts
};
}
function serverActionReducer(state, action) {
const { mutable, cache, resolve, reject } = action;
const href = state.canonicalUrl;
let currentTree = state.tree;
const isForCurrentTree = JSON.stringify(mutable.previousTree) === JSON.stringify(currentTree);
if (isForCurrentTree) {
return (0, _handlemutable.handleMutable)(state, mutable);
}
if (mutable.inFlightServerAction) {
// unblock if a navigation event comes through
// while we've suspended on an action
if (mutable.globalMutable.pendingNavigatePath && mutable.globalMutable.pendingNavigatePath !== href) {
mutable.inFlightServerAction.then(()=>{
if (mutable.actionResultResolved) return;
// if the server action resolves after a navigation took place,
// reset ServerActionMutable values & trigger a refresh so that any stale data gets updated
mutable.inFlightServerAction = null;
mutable.globalMutable.pendingNavigatePath = undefined;
mutable.globalMutable.refresh();
mutable.actionResultResolved = true;
});
return state;
}
} else {
mutable.inFlightServerAction = (0, _createrecordfromthenable.createRecordFromThenable)(fetchServerAction(state, action));
}
// TODO-APP: Make try/catch wrap only readRecordValue so that other errors bubble up through the reducer instead.
try {
// suspends until the server action is resolved.
const { actionResult, actionFlightData: flightData, redirectLocation } = (0, _readrecordvalue.readRecordValue)(mutable.inFlightServerAction);
// Make sure the redirection is a push instead of a replace.
// Issue: https://github.com/vercel/next.js/issues/53911
if (redirectLocation) {
state.pushRef.pendingPush = true;
mutable.pendingPush = true;
}
mutable.previousTree = state.tree;
if (!flightData) {
if (!mutable.actionResultResolved) {
resolve(actionResult);
mutable.actionResultResolved = true;
}
// If there is a redirect but no flight data we need to do a mpaNavigation.
if (redirectLocation) {
return (0, _navigatereducer.handleExternalUrl)(state, mutable, redirectLocation.href, state.pushRef.pendingPush);
}
return state;
}
if (typeof flightData === "string") {
// Handle case when navigating to page in `pages` from `app`
return (0, _navigatereducer.handleExternalUrl)(state, mutable, flightData, state.pushRef.pendingPush);
}
// Remove cache.data as it has been resolved at this point.
mutable.inFlightServerAction = null;
for (const flightDataPath of flightData){
// FlightDataPath with more than two items means unexpected Flight data was returned
if (flightDataPath.length !== 3) {
// TODO-APP: handle this case better
console.log("SERVER ACTION APPLY FAILED");
return state;
}
// Given the path can only have two items the items are only the router state and subTreeData for the root.
const [treePatch] = flightDataPath;
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
[
""
], currentTree, treePatch);
if (newTree === null) {
throw new Error("SEGMENT MISMATCH");
}
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
return (0, _navigatereducer.handleExternalUrl)(state, mutable, href, state.pushRef.pendingPush);
}
// The one before last item is the router state tree patch
const [subTreeData, head] = flightDataPath.slice(-2);
// Handles case where prefetch only returns the router tree patch without rendered components.
if (subTreeData !== null) {
cache.status = _approutercontextsharedruntime.CacheStates.READY;
cache.subTreeData = subTreeData;
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(cache, // Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache.
undefined, treePatch, head);
mutable.cache = cache;
mutable.prefetchCache = new Map();
}
mutable.previousTree = currentTree;
mutable.patchedTree = newTree;
mutable.canonicalUrl = href;
currentTree = newTree;
}
if (redirectLocation) {
const newHref = (0, _createhreffromurl.createHrefFromUrl)(redirectLocation, false);
mutable.canonicalUrl = newHref;
}
if (!mutable.actionResultResolved) {
resolve(actionResult);
mutable.actionResultResolved = true;
}
return (0, _handlemutable.handleMutable)(state, mutable);
} catch (e) {
if (e.status === "rejected") {
if (!mutable.actionResultResolved) {
reject(e.value);
mutable.actionResultResolved = true;
}
// When the server action is rejected we don't update the state and instead call the reject handler of the promise.
return state;
}
throw e;
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=server-action-reducer.js.map

Some files were not shown because too many files have changed in this diff Show More