Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
3
node_modules/next/dist/client/components/router-reducer/reducers/find-head-in-cache.d.ts
generated
vendored
Normal file
3
node_modules/next/dist/client/components/router-reducer/reducers/find-head-in-cache.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
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]): [CacheNode, string] | null;
|
||||
65
node_modules/next/dist/client/components/router-reducer/reducers/find-head-in-cache.js
generated
vendored
Normal file
65
node_modules/next/dist/client/components/router-reducer/reducers/find-head-in-cache.js
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
"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) {
|
||||
return findHeadInCacheImpl(cache, parallelRoutes, '');
|
||||
}
|
||||
function findHeadInCacheImpl(cache, parallelRoutes, keyPrefix) {
|
||||
const isLastItem = Object.keys(parallelRoutes).length === 0;
|
||||
if (isLastItem) {
|
||||
// Returns the entire Cache Node of the segment whose head we will render.
|
||||
return [
|
||||
cache,
|
||||
keyPrefix
|
||||
];
|
||||
}
|
||||
// First try the 'children' parallel route if it exists
|
||||
// when starting from the "root", this corresponds with the main page component
|
||||
if (parallelRoutes.children) {
|
||||
const [segment, childParallelRoutes] = parallelRoutes.children;
|
||||
const childSegmentMap = cache.parallelRoutes.get('children');
|
||||
if (childSegmentMap) {
|
||||
const cacheKey = (0, _createroutercachekey.createRouterCacheKey)(segment);
|
||||
const cacheNode = childSegmentMap.get(cacheKey);
|
||||
if (cacheNode) {
|
||||
const item = findHeadInCacheImpl(cacheNode, childParallelRoutes, keyPrefix + '/' + cacheKey);
|
||||
if (item) return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we didn't find metadata in the page slot, check the other parallel routes
|
||||
for(const key in parallelRoutes){
|
||||
if (key === 'children') continue; // already checked above
|
||||
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 = findHeadInCacheImpl(cacheNode, childParallelRoutes, keyPrefix + '/' + cacheKey);
|
||||
if (item) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return 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=find-head-in-cache.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/find-head-in-cache.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/find-head-in-cache.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/find-head-in-cache.ts"],"sourcesContent":["import type { FlightRouterState } from '../../../../server/app-render/types'\nimport type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'\nimport { createRouterCacheKey } from '../create-router-cache-key'\n\nexport function findHeadInCache(\n cache: CacheNode,\n parallelRoutes: FlightRouterState[1]\n): [CacheNode, string] | null {\n return findHeadInCacheImpl(cache, parallelRoutes, '')\n}\n\nfunction findHeadInCacheImpl(\n cache: CacheNode,\n parallelRoutes: FlightRouterState[1],\n keyPrefix: string\n): [CacheNode, string] | null {\n const isLastItem = Object.keys(parallelRoutes).length === 0\n if (isLastItem) {\n // Returns the entire Cache Node of the segment whose head we will render.\n return [cache, keyPrefix]\n }\n\n // First try the 'children' parallel route if it exists\n // when starting from the \"root\", this corresponds with the main page component\n if (parallelRoutes.children) {\n const [segment, childParallelRoutes] = parallelRoutes.children\n const childSegmentMap = cache.parallelRoutes.get('children')\n if (childSegmentMap) {\n const cacheKey = createRouterCacheKey(segment)\n const cacheNode = childSegmentMap.get(cacheKey)\n if (cacheNode) {\n const item = findHeadInCacheImpl(\n cacheNode,\n childParallelRoutes,\n keyPrefix + '/' + cacheKey\n )\n if (item) return item\n }\n }\n }\n\n // if we didn't find metadata in the page slot, check the other parallel routes\n for (const key in parallelRoutes) {\n if (key === 'children') continue // already checked above\n\n const [segment, childParallelRoutes] = parallelRoutes[key]\n const childSegmentMap = cache.parallelRoutes.get(key)\n if (!childSegmentMap) {\n continue\n }\n\n const cacheKey = createRouterCacheKey(segment)\n\n const cacheNode = childSegmentMap.get(cacheKey)\n if (!cacheNode) {\n continue\n }\n\n const item = findHeadInCacheImpl(\n cacheNode,\n childParallelRoutes,\n keyPrefix + '/' + cacheKey\n )\n if (item) {\n return item\n }\n }\n\n return null\n}\n"],"names":["findHeadInCache","cache","parallelRoutes","findHeadInCacheImpl","keyPrefix","isLastItem","Object","keys","length","children","segment","childParallelRoutes","childSegmentMap","get","cacheKey","createRouterCacheKey","cacheNode","item","key"],"mappings":";;;;+BAIgBA;;;eAAAA;;;sCAFqB;AAE9B,SAASA,gBACdC,KAAgB,EAChBC,cAAoC;IAEpC,OAAOC,oBAAoBF,OAAOC,gBAAgB;AACpD;AAEA,SAASC,oBACPF,KAAgB,EAChBC,cAAoC,EACpCE,SAAiB;IAEjB,MAAMC,aAAaC,OAAOC,IAAI,CAACL,gBAAgBM,MAAM,KAAK;IAC1D,IAAIH,YAAY;QACd,0EAA0E;QAC1E,OAAO;YAACJ;YAAOG;SAAU;IAC3B;IAEA,uDAAuD;IACvD,+EAA+E;IAC/E,IAAIF,eAAeO,QAAQ,EAAE;QAC3B,MAAM,CAACC,SAASC,oBAAoB,GAAGT,eAAeO,QAAQ;QAC9D,MAAMG,kBAAkBX,MAAMC,cAAc,CAACW,GAAG,CAAC;QACjD,IAAID,iBAAiB;YACnB,MAAME,WAAWC,IAAAA,0CAAoB,EAACL;YACtC,MAAMM,YAAYJ,gBAAgBC,GAAG,CAACC;YACtC,IAAIE,WAAW;gBACb,MAAMC,OAAOd,oBACXa,WACAL,qBACAP,YAAY,MAAMU;gBAEpB,IAAIG,MAAM,OAAOA;YACnB;QACF;IACF;IAEA,+EAA+E;IAC/E,IAAK,MAAMC,OAAOhB,eAAgB;QAChC,IAAIgB,QAAQ,YAAY,UAAS,wBAAwB;QAEzD,MAAM,CAACR,SAASC,oBAAoB,GAAGT,cAAc,CAACgB,IAAI;QAC1D,MAAMN,kBAAkBX,MAAMC,cAAc,CAACW,GAAG,CAACK;QACjD,IAAI,CAACN,iBAAiB;YACpB;QACF;QAEA,MAAME,WAAWC,IAAAA,0CAAoB,EAACL;QAEtC,MAAMM,YAAYJ,gBAAgBC,GAAG,CAACC;QACtC,IAAI,CAACE,WAAW;YACd;QACF;QAEA,MAAMC,OAAOd,oBACXa,WACAL,qBACAP,YAAY,MAAMU;QAEpB,IAAIG,MAAM;YACR,OAAOA;QACT;IACF;IAEA,OAAO;AACT"}
|
||||
2
node_modules/next/dist/client/components/router-reducer/reducers/get-segment-value.d.ts
generated
vendored
Normal file
2
node_modules/next/dist/client/components/router-reducer/reducers/get-segment-value.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { Segment } from '../../../../server/app-render/types';
|
||||
export declare function getSegmentValue(segment: Segment): string;
|
||||
21
node_modules/next/dist/client/components/router-reducer/reducers/get-segment-value.js
generated
vendored
Normal file
21
node_modules/next/dist/client/components/router-reducer/reducers/get-segment-value.js
generated
vendored
Normal 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
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/get-segment-value.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/get-segment-value.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/get-segment-value.ts"],"sourcesContent":["import type { Segment } from '../../../../server/app-render/types'\n\nexport function getSegmentValue(segment: Segment) {\n return Array.isArray(segment) ? segment[1] : segment\n}\n"],"names":["getSegmentValue","segment","Array","isArray"],"mappings":";;;;+BAEgBA;;;eAAAA;;;AAAT,SAASA,gBAAgBC,OAAgB;IAC9C,OAAOC,MAAMC,OAAO,CAACF,WAAWA,OAAO,CAAC,EAAE,GAAGA;AAC/C"}
|
||||
2
node_modules/next/dist/client/components/router-reducer/reducers/has-interception-route-in-current-tree.d.ts
generated
vendored
Normal file
2
node_modules/next/dist/client/components/router-reducer/reducers/has-interception-route-in-current-tree.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { FlightRouterState } from '../../../../server/app-render/types';
|
||||
export declare function hasInterceptionRouteInCurrentTree([segment, parallelRoutes,]: FlightRouterState): boolean;
|
||||
39
node_modules/next/dist/client/components/router-reducer/reducers/has-interception-route-in-current-tree.js
generated
vendored
Normal file
39
node_modules/next/dist/client/components/router-reducer/reducers/has-interception-route-in-current-tree.js
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "hasInterceptionRouteInCurrentTree", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return hasInterceptionRouteInCurrentTree;
|
||||
}
|
||||
});
|
||||
const _interceptionroutes = require("../../../../shared/lib/router/utils/interception-routes");
|
||||
function hasInterceptionRouteInCurrentTree(param) {
|
||||
let [segment, parallelRoutes] = param;
|
||||
// If we have a dynamic segment, it's marked as an interception route by the presence of the `i` suffix.
|
||||
if (Array.isArray(segment) && (segment[2] === 'di' || segment[2] === 'ci')) {
|
||||
return true;
|
||||
}
|
||||
// If segment is not an array, apply the existing string-based check
|
||||
if (typeof segment === 'string' && (0, _interceptionroutes.isInterceptionRouteAppPath)(segment)) {
|
||||
return true;
|
||||
}
|
||||
// Iterate through parallelRoutes if they exist
|
||||
if (parallelRoutes) {
|
||||
for(const key in parallelRoutes){
|
||||
if (hasInterceptionRouteInCurrentTree(parallelRoutes[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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=has-interception-route-in-current-tree.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/has-interception-route-in-current-tree.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/has-interception-route-in-current-tree.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/has-interception-route-in-current-tree.ts"],"sourcesContent":["import type { FlightRouterState } from '../../../../server/app-render/types'\nimport { isInterceptionRouteAppPath } from '../../../../shared/lib/router/utils/interception-routes'\n\nexport function hasInterceptionRouteInCurrentTree([\n segment,\n parallelRoutes,\n]: FlightRouterState): boolean {\n // If we have a dynamic segment, it's marked as an interception route by the presence of the `i` suffix.\n if (Array.isArray(segment) && (segment[2] === 'di' || segment[2] === 'ci')) {\n return true\n }\n\n // If segment is not an array, apply the existing string-based check\n if (typeof segment === 'string' && isInterceptionRouteAppPath(segment)) {\n return true\n }\n\n // Iterate through parallelRoutes if they exist\n if (parallelRoutes) {\n for (const key in parallelRoutes) {\n if (hasInterceptionRouteInCurrentTree(parallelRoutes[key])) {\n return true\n }\n }\n }\n\n return false\n}\n"],"names":["hasInterceptionRouteInCurrentTree","segment","parallelRoutes","Array","isArray","isInterceptionRouteAppPath","key"],"mappings":";;;;+BAGgBA;;;eAAAA;;;oCAF2B;AAEpC,SAASA,kCAAkC,KAG9B;IAH8B,IAAA,CAChDC,SACAC,eACkB,GAH8B;IAIhD,wGAAwG;IACxG,IAAIC,MAAMC,OAAO,CAACH,YAAaA,CAAAA,OAAO,CAAC,EAAE,KAAK,QAAQA,OAAO,CAAC,EAAE,KAAK,IAAG,GAAI;QAC1E,OAAO;IACT;IAEA,oEAAoE;IACpE,IAAI,OAAOA,YAAY,YAAYI,IAAAA,8CAA0B,EAACJ,UAAU;QACtE,OAAO;IACT;IAEA,+CAA+C;IAC/C,IAAIC,gBAAgB;QAClB,IAAK,MAAMI,OAAOJ,eAAgB;YAChC,IAAIF,kCAAkCE,cAAc,CAACI,IAAI,GAAG;gBAC1D,OAAO;YACT;QACF;IACF;IAEA,OAAO;AACT"}
|
||||
4
node_modules/next/dist/client/components/router-reducer/reducers/hmr-refresh-reducer.d.ts
generated
vendored
Normal file
4
node_modules/next/dist/client/components/router-reducer/reducers/hmr-refresh-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import type { ReadonlyReducerState, ReducerState, HmrRefreshAction } from '../router-reducer-types';
|
||||
declare function hmrRefreshReducerNoop(state: ReadonlyReducerState, _action: HmrRefreshAction): ReducerState;
|
||||
export declare const hmrRefreshReducer: typeof hmrRefreshReducerNoop;
|
||||
export {};
|
||||
98
node_modules/next/dist/client/components/router-reducer/reducers/hmr-refresh-reducer.js
generated
vendored
Normal file
98
node_modules/next/dist/client/components/router-reducer/reducers/hmr-refresh-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "hmrRefreshReducer", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return hmrRefreshReducer;
|
||||
}
|
||||
});
|
||||
const _fetchserverresponse = require("../fetch-server-response");
|
||||
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");
|
||||
const _approuter = require("../../app-router");
|
||||
const _handlesegmentmismatch = require("../handle-segment-mismatch");
|
||||
const _hasinterceptionrouteincurrenttree = require("./has-interception-route-in-current-tree");
|
||||
// A version of refresh reducer that keeps the cache around instead of wiping all of it.
|
||||
function hmrRefreshReducerImpl(state, action) {
|
||||
const { origin } = action;
|
||||
const mutable = {};
|
||||
const href = state.canonicalUrl;
|
||||
mutable.preserveCustomHistoryState = false;
|
||||
const cache = (0, _approuter.createEmptyCacheNode)();
|
||||
// If the current tree was intercepted, the nextUrl should be included in the request.
|
||||
// This is to ensure that the refresh request doesn't get intercepted, accidentally triggering the interception route.
|
||||
const includeNextUrl = (0, _hasinterceptionrouteincurrenttree.hasInterceptionRouteInCurrentTree)(state.tree);
|
||||
// TODO-APP: verify that `href` is not an external url.
|
||||
// Fetch data from the root of the tree.
|
||||
const navigatedAt = Date.now();
|
||||
cache.lazyData = (0, _fetchserverresponse.fetchServerResponse)(new URL(href, origin), {
|
||||
flightRouterState: [
|
||||
state.tree[0],
|
||||
state.tree[1],
|
||||
state.tree[2],
|
||||
'refetch'
|
||||
],
|
||||
nextUrl: includeNextUrl ? state.nextUrl : null,
|
||||
isHmrRefresh: true
|
||||
});
|
||||
return cache.lazyData.then((param)=>{
|
||||
let { flightData, canonicalUrl: canonicalUrlOverride } = param;
|
||||
// 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.lazyData as it has been resolved at this point.
|
||||
cache.lazyData = null;
|
||||
let currentTree = state.tree;
|
||||
let currentCache = state.cache;
|
||||
for (const normalizedFlightData of flightData){
|
||||
const { tree: treePatch, isRootRender } = normalizedFlightData;
|
||||
if (!isRootRender) {
|
||||
// TODO-APP: handle this case better
|
||||
console.log('REFRESH FAILED');
|
||||
return state;
|
||||
}
|
||||
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
|
||||
[
|
||||
''
|
||||
], currentTree, treePatch, state.canonicalUrl);
|
||||
if (newTree === null) {
|
||||
return (0, _handlesegmentmismatch.handleSegmentMismatch)(state, action, treePatch);
|
||||
}
|
||||
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)(navigatedAt, currentCache, cache, normalizedFlightData);
|
||||
if (applied) {
|
||||
mutable.cache = cache;
|
||||
currentCache = cache;
|
||||
}
|
||||
mutable.patchedTree = newTree;
|
||||
mutable.canonicalUrl = href;
|
||||
currentTree = newTree;
|
||||
}
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}, ()=>state);
|
||||
}
|
||||
function hmrRefreshReducerNoop(state, _action) {
|
||||
return state;
|
||||
}
|
||||
const hmrRefreshReducer = process.env.NODE_ENV === 'production' ? hmrRefreshReducerNoop : hmrRefreshReducerImpl;
|
||||
|
||||
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=hmr-refresh-reducer.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/hmr-refresh-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/hmr-refresh-reducer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
3
node_modules/next/dist/client/components/router-reducer/reducers/navigate-reducer.d.ts
generated
vendored
Normal file
3
node_modules/next/dist/client/components/router-reducer/reducers/navigate-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { type Mutable, type NavigateAction, type ReadonlyReducerState, type ReducerState } from '../router-reducer-types';
|
||||
export declare function handleExternalUrl(state: ReadonlyReducerState, mutable: Mutable, url: string, pendingPush: boolean): ReducerState;
|
||||
export declare function navigateReducer(state: ReadonlyReducerState, action: NavigateAction): ReducerState;
|
||||
380
node_modules/next/dist/client/components/router-reducer/reducers/navigate-reducer.js
generated
vendored
Normal file
380
node_modules/next/dist/client/components/router-reducer/reducers/navigate-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,380 @@
|
|||
"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 _fetchserverresponse = require("../fetch-server-response");
|
||||
const _createhreffromurl = require("../create-href-from-url");
|
||||
const _invalidatecachebelowflightsegmentpath = require("../invalidate-cache-below-flight-segmentpath");
|
||||
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 _prefetchreducer = require("./prefetch-reducer");
|
||||
const _approuter = require("../../app-router");
|
||||
const _segment = require("../../../../shared/lib/segment");
|
||||
const _pprnavigations = require("../ppr-navigations");
|
||||
const _prefetchcacheutils = require("../prefetch-cache-utils");
|
||||
const _clearcachenodedataforsegmentpath = require("../clear-cache-node-data-for-segment-path");
|
||||
const _aliasedprefetchnavigations = require("../aliased-prefetch-navigations");
|
||||
const _segmentcache = require("../../segment-cache");
|
||||
function handleExternalUrl(state, mutable, url, pendingPush) {
|
||||
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 triggerLazyFetchForLeafSegments(newCache, currentCache, flightSegmentPath, treePatch) {
|
||||
let appliedPatch = false;
|
||||
newCache.rsc = currentCache.rsc;
|
||||
newCache.prefetchRsc = currentCache.prefetchRsc;
|
||||
newCache.loading = currentCache.loading;
|
||||
newCache.parallelRoutes = new Map(currentCache.parallelRoutes);
|
||||
const segmentPathsToFill = generateSegmentsFromPatch(treePatch).map((segment)=>[
|
||||
...flightSegmentPath,
|
||||
...segment
|
||||
]);
|
||||
for (const segmentPaths of segmentPathsToFill){
|
||||
(0, _clearcachenodedataforsegmentpath.clearCacheNodeDataForSegmentPath)(newCache, currentCache, segmentPaths);
|
||||
appliedPatch = true;
|
||||
}
|
||||
return appliedPatch;
|
||||
}
|
||||
function handleNavigationResult(url, state, mutable, pendingPush, result) {
|
||||
switch(result.tag){
|
||||
case _segmentcache.NavigationResultTag.MPA:
|
||||
{
|
||||
// Perform an MPA navigation.
|
||||
const newUrl = result.data;
|
||||
return handleExternalUrl(state, mutable, newUrl, pendingPush);
|
||||
}
|
||||
case _segmentcache.NavigationResultTag.NoOp:
|
||||
{
|
||||
// The server responded with no change to the current page. However, if
|
||||
// the URL changed, we still need to update that.
|
||||
const newCanonicalUrl = result.data.canonicalUrl;
|
||||
mutable.canonicalUrl = newCanonicalUrl;
|
||||
// Check if the only thing that changed was the hash fragment.
|
||||
const oldUrl = new URL(state.canonicalUrl, url);
|
||||
const onlyHashChange = // We don't need to compare the origins, because client-driven
|
||||
// navigations are always same-origin.
|
||||
url.pathname === oldUrl.pathname && url.search === oldUrl.search && url.hash !== oldUrl.hash;
|
||||
if (onlyHashChange) {
|
||||
// The only updated part of the URL is the hash.
|
||||
mutable.onlyHashChange = true;
|
||||
mutable.shouldScroll = result.data.shouldScroll;
|
||||
mutable.hashFragment = url.hash;
|
||||
// Setting this to an empty array triggers a scroll for all new and
|
||||
// updated segments. See `ScrollAndFocusHandler` for more details.
|
||||
mutable.scrollableSegments = [];
|
||||
}
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}
|
||||
case _segmentcache.NavigationResultTag.Success:
|
||||
{
|
||||
// Received a new result.
|
||||
mutable.cache = result.data.cacheNode;
|
||||
mutable.patchedTree = result.data.flightRouterState;
|
||||
mutable.canonicalUrl = result.data.canonicalUrl;
|
||||
mutable.scrollableSegments = result.data.scrollableSegments;
|
||||
mutable.shouldScroll = result.data.shouldScroll;
|
||||
mutable.hashFragment = result.data.hash;
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}
|
||||
case _segmentcache.NavigationResultTag.Async:
|
||||
{
|
||||
return result.data.then((asyncResult)=>handleNavigationResult(url, state, mutable, pendingPush, asyncResult), // If the navigation failed, return the current state.
|
||||
// TODO: This matches the current behavior but we need to do something
|
||||
// better here if the network fails.
|
||||
()=>{
|
||||
return state;
|
||||
});
|
||||
}
|
||||
default:
|
||||
{
|
||||
result;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
function navigateReducer(state, action) {
|
||||
const { url, isExternalUrl, navigateType, shouldScroll, allowAliasing } = action;
|
||||
const mutable = {};
|
||||
const { 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, _prefetchcacheutils.prunePrefetchCache)(state.prefetchCache);
|
||||
mutable.preserveCustomHistoryState = false;
|
||||
mutable.pendingPush = pendingPush;
|
||||
if (isExternalUrl) {
|
||||
return handleExternalUrl(state, mutable, url.toString(), pendingPush);
|
||||
}
|
||||
// Handles case where `<meta http-equiv="refresh">` tag is present,
|
||||
// which will trigger an MPA navigation.
|
||||
if (document.getElementById('__next-page-redirect')) {
|
||||
return handleExternalUrl(state, mutable, href, pendingPush);
|
||||
}
|
||||
if (process.env.__NEXT_CLIENT_SEGMENT_CACHE) {
|
||||
// (Very Early Experimental Feature) Segment Cache
|
||||
//
|
||||
// Bypass the normal prefetch cache and use the new per-segment cache
|
||||
// implementation instead. This is only supported if PPR is enabled, too.
|
||||
//
|
||||
// Temporary glue code between the router reducer and the new navigation
|
||||
// implementation. Eventually we'll rewrite the router reducer to a
|
||||
// state machine.
|
||||
const result = (0, _segmentcache.navigate)(url, state.cache, state.tree, state.nextUrl, shouldScroll);
|
||||
return handleNavigationResult(url, state, mutable, pendingPush, result);
|
||||
}
|
||||
const prefetchValues = (0, _prefetchcacheutils.getOrCreatePrefetchCacheEntry)({
|
||||
url,
|
||||
nextUrl: state.nextUrl,
|
||||
tree: state.tree,
|
||||
prefetchCache: state.prefetchCache,
|
||||
allowAliasing
|
||||
});
|
||||
const { treeAtTimeOfPrefetch, data } = prefetchValues;
|
||||
_prefetchreducer.prefetchQueue.bump(data);
|
||||
return data.then((param)=>{
|
||||
let { flightData, canonicalUrl: canonicalUrlOverride, postponed } = param;
|
||||
const navigatedAt = Date.now();
|
||||
let isFirstRead = false;
|
||||
// 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 = navigatedAt;
|
||||
isFirstRead = true;
|
||||
}
|
||||
if (prefetchValues.aliased) {
|
||||
const result = (0, _aliasedprefetchnavigations.handleAliasedPrefetchEntry)(navigatedAt, state, flightData, url, mutable);
|
||||
// We didn't return new router state because we didn't apply the aliased entry for some reason.
|
||||
// We'll re-invoke the navigation handler but ensure that we don't attempt to use the aliased entry. This
|
||||
// will create an on-demand prefetch entry.
|
||||
if (result === false) {
|
||||
return navigateReducer(state, {
|
||||
...action,
|
||||
allowAliasing: false
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Handle case when navigating to page in `pages` from `app`
|
||||
if (typeof flightData === 'string') {
|
||||
return handleExternalUrl(state, mutable, flightData, pendingPush);
|
||||
}
|
||||
const updatedCanonicalUrl = canonicalUrlOverride ? (0, _createhreffromurl.createHrefFromUrl)(canonicalUrlOverride) : href;
|
||||
const onlyHashChange = !!hash && state.canonicalUrl.split('#', 1)[0] === updatedCanonicalUrl.split('#', 1)[0];
|
||||
// If only the hash has changed, the server hasn't sent us any new data. We can just update
|
||||
// the mutable properties responsible for URL and scroll handling and return early.
|
||||
if (onlyHashChange) {
|
||||
mutable.onlyHashChange = true;
|
||||
mutable.canonicalUrl = updatedCanonicalUrl;
|
||||
mutable.shouldScroll = shouldScroll;
|
||||
mutable.hashFragment = hash;
|
||||
mutable.scrollableSegments = [];
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}
|
||||
let currentTree = state.tree;
|
||||
let currentCache = state.cache;
|
||||
let scrollableSegments = [];
|
||||
for (const normalizedFlightData of flightData){
|
||||
const { pathToSegment: flightSegmentPath, seedData, head, isHeadPartial, isRootRender } = normalizedFlightData;
|
||||
let treePatch = normalizedFlightData.tree;
|
||||
// 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, href);
|
||||
// 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, href);
|
||||
}
|
||||
if (newTree !== null) {
|
||||
if (// This is just a paranoid check. When a route is PPRed, the server
|
||||
// will send back a static response that's rendered from
|
||||
// the root. If for some reason it doesn't, we fall back to the
|
||||
// non-PPR implementation.
|
||||
// TODO: We should get rid of the else branch and do all navigations
|
||||
// via startPPRNavigation. The current structure is just
|
||||
// an incremental step.
|
||||
seedData && isRootRender && postponed) {
|
||||
const task = (0, _pprnavigations.startPPRNavigation)(navigatedAt, currentCache, currentTree, treePatch, seedData, head, isHeadPartial, false, scrollableSegments);
|
||||
if (task !== null) {
|
||||
if (task.route === null) {
|
||||
// Detected a change to the root layout. Perform an full-
|
||||
// page navigation.
|
||||
return handleExternalUrl(state, mutable, href, pendingPush);
|
||||
}
|
||||
// Use the tree computed by startPPRNavigation instead
|
||||
// of the one computed by applyRouterStatePatchToTree.
|
||||
// TODO: We should remove applyRouterStatePatchToTree
|
||||
// from the PPR path entirely.
|
||||
const patchedRouterState = task.route;
|
||||
newTree = patchedRouterState;
|
||||
const newCache = task.node;
|
||||
if (newCache !== null) {
|
||||
// We've created a new Cache Node tree that contains a prefetched
|
||||
// version of the next page. This can be rendered instantly.
|
||||
mutable.cache = newCache;
|
||||
}
|
||||
const dynamicRequestTree = task.dynamicRequestTree;
|
||||
if (dynamicRequestTree !== null) {
|
||||
// The prefetched tree has dynamic holes in it. We initiate a
|
||||
// dynamic request to fill them in.
|
||||
//
|
||||
// Do not block on the result. We'll immediately render the Cache
|
||||
// Node tree and suspend on the dynamic parts. When the request
|
||||
// comes in, we'll fill in missing data and ping React to
|
||||
// re-render. Unlike the lazy fetching model in the non-PPR
|
||||
// implementation, this is modeled as a single React update +
|
||||
// streaming, rather than multiple top-level updates. (However,
|
||||
// even in the new model, we'll still need to sometimes update the
|
||||
// root multiple times per navigation, like if the server sends us
|
||||
// a different response than we expected. For now, we revert back
|
||||
// to the lazy fetching mechanism in that case.)
|
||||
const dynamicRequest = (0, _fetchserverresponse.fetchServerResponse)(url, {
|
||||
flightRouterState: dynamicRequestTree,
|
||||
nextUrl: state.nextUrl
|
||||
});
|
||||
(0, _pprnavigations.listenForDynamicRequest)(task, dynamicRequest);
|
||||
// We store the dynamic request on the `lazyData` property of the CacheNode
|
||||
// because we're not going to await the dynamic request here. Since we're not blocking
|
||||
// on the dynamic request, `layout-router` will
|
||||
// task.node.lazyData = dynamicRequest
|
||||
} else {
|
||||
// The prefetched tree does not contain dynamic holes — it's
|
||||
// fully static. We can skip the dynamic request.
|
||||
}
|
||||
} else {
|
||||
// Nothing changed, so reuse the old cache.
|
||||
// TODO: What if the head changed but not any of the segment data?
|
||||
// Is that possible? If so, we should clone the whole tree and
|
||||
// update the head.
|
||||
newTree = treePatch;
|
||||
}
|
||||
} else {
|
||||
// The static response does not include any dynamic holes, so
|
||||
// there's no need to do a second request.
|
||||
// TODO: As an incremental step this just reverts back to the
|
||||
// non-PPR implementation. We can simplify this branch further,
|
||||
// given that PPR prefetches are always static and return the whole
|
||||
// tree. Or in the meantime we could factor it out into a
|
||||
// separate function.
|
||||
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
|
||||
return handleExternalUrl(state, mutable, href, pendingPush);
|
||||
}
|
||||
const cache = (0, _approuter.createEmptyCacheNode)();
|
||||
let applied = false;
|
||||
if (prefetchValues.status === _routerreducertypes.PrefetchCacheEntryStatus.stale && !isFirstRead) {
|
||||
// When we have a stale prefetch entry, we only want to re-use the loading state of the route we're navigating to, to support instant loading navigations
|
||||
// this will trigger a lazy fetch for the actual page data by nulling the `rsc` and `prefetchRsc` values for page data,
|
||||
// while copying over the `loading` for the segment that contains the page data.
|
||||
// We only do this on subsequent reads, as otherwise there'd be no loading data to re-use.
|
||||
// We skip this branch if only the hash fragment has changed, as we don't want to trigger a lazy fetch in that case
|
||||
applied = triggerLazyFetchForLeafSegments(cache, currentCache, flightSegmentPath, treePatch);
|
||||
// since we re-used the stale cache's loading state & refreshed the data,
|
||||
// update the `lastUsedTime` so that it can continue to be re-used for the next 30s
|
||||
prefetchValues.lastUsedTime = navigatedAt;
|
||||
} else {
|
||||
applied = (0, _applyflightdata.applyFlightData)(navigatedAt, currentCache, cache, normalizedFlightData, prefetchValues);
|
||||
}
|
||||
const hardNavigate = (0, _shouldhardnavigate.shouldHardNavigate)(// TODO-APP: remove ''
|
||||
flightSegmentPathWithLeadingEmpty, currentTree);
|
||||
if (hardNavigate) {
|
||||
// Copy rsc for the root node of the cache.
|
||||
cache.rsc = currentCache.rsc;
|
||||
cache.prefetchRsc = currentCache.prefetchRsc;
|
||||
(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;
|
||||
// If we applied the cache, we update the "current cache" value so any other
|
||||
// segments in the FlightDataPath will be able to reference the updated cache.
|
||||
currentCache = cache;
|
||||
}
|
||||
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] !== _segment.DEFAULT_SEGMENT_KEY) {
|
||||
scrollableSegments.push(scrollableSegmentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
currentTree = newTree;
|
||||
}
|
||||
}
|
||||
mutable.patchedTree = currentTree;
|
||||
mutable.canonicalUrl = updatedCanonicalUrl;
|
||||
mutable.scrollableSegments = scrollableSegments;
|
||||
mutable.hashFragment = hash;
|
||||
mutable.shouldScroll = shouldScroll;
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}, ()=>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=navigate-reducer.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/navigate-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/navigate-reducer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
7
node_modules/next/dist/client/components/router-reducer/reducers/prefetch-reducer.d.ts
generated
vendored
Normal file
7
node_modules/next/dist/client/components/router-reducer/reducers/prefetch-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import type { PrefetchAction, ReducerState, ReadonlyReducerState } from '../router-reducer-types';
|
||||
import { PromiseQueue } from '../../promise-queue';
|
||||
export declare const prefetchQueue: PromiseQueue;
|
||||
export declare const prefetchReducer: typeof identityReducerWhenSegmentCacheIsEnabled | typeof prefetchReducerImpl;
|
||||
declare function identityReducerWhenSegmentCacheIsEnabled<T>(state: T): T;
|
||||
declare function prefetchReducerImpl(state: ReadonlyReducerState, action: PrefetchAction): ReducerState;
|
||||
export {};
|
||||
57
node_modules/next/dist/client/components/router-reducer/reducers/prefetch-reducer.js
generated
vendored
Normal file
57
node_modules/next/dist/client/components/router-reducer/reducers/prefetch-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"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 _promisequeue = require("../../promise-queue");
|
||||
const _prefetchcacheutils = require("../prefetch-cache-utils");
|
||||
const prefetchQueue = new _promisequeue.PromiseQueue(5);
|
||||
const prefetchReducer = process.env.__NEXT_CLIENT_SEGMENT_CACHE ? identityReducerWhenSegmentCacheIsEnabled : prefetchReducerImpl;
|
||||
function identityReducerWhenSegmentCacheIsEnabled(state) {
|
||||
// Unlike the old implementation, the Segment Cache doesn't store its data in
|
||||
// the router reducer state.
|
||||
//
|
||||
// This shouldn't be reachable because we wrap the prefetch API in a check,
|
||||
// too, which prevents the action from being dispatched. But it's here for
|
||||
// clarity + code elimination.
|
||||
return state;
|
||||
}
|
||||
function prefetchReducerImpl(state, action) {
|
||||
// let's prune the prefetch cache before we do anything else
|
||||
(0, _prefetchcacheutils.prunePrefetchCache)(state.prefetchCache);
|
||||
const { url } = action;
|
||||
(0, _prefetchcacheutils.getOrCreatePrefetchCacheEntry)({
|
||||
url,
|
||||
nextUrl: state.nextUrl,
|
||||
prefetchCache: state.prefetchCache,
|
||||
kind: action.kind,
|
||||
tree: state.tree,
|
||||
allowAliasing: true
|
||||
});
|
||||
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
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/prefetch-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/prefetch-reducer.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/prefetch-reducer.ts"],"sourcesContent":["import type {\n PrefetchAction,\n ReducerState,\n ReadonlyReducerState,\n} from '../router-reducer-types'\nimport { PromiseQueue } from '../../promise-queue'\nimport {\n getOrCreatePrefetchCacheEntry,\n prunePrefetchCache,\n} from '../prefetch-cache-utils'\nexport const prefetchQueue = new PromiseQueue(5)\n\nexport const prefetchReducer = process.env.__NEXT_CLIENT_SEGMENT_CACHE\n ? identityReducerWhenSegmentCacheIsEnabled\n : prefetchReducerImpl\n\nfunction identityReducerWhenSegmentCacheIsEnabled<T>(state: T): T {\n // Unlike the old implementation, the Segment Cache doesn't store its data in\n // the router reducer state.\n //\n // This shouldn't be reachable because we wrap the prefetch API in a check,\n // too, which prevents the action from being dispatched. But it's here for\n // clarity + code elimination.\n return state\n}\n\nfunction prefetchReducerImpl(\n state: ReadonlyReducerState,\n action: PrefetchAction\n): ReducerState {\n // let's prune the prefetch cache before we do anything else\n prunePrefetchCache(state.prefetchCache)\n\n const { url } = action\n\n getOrCreatePrefetchCacheEntry({\n url,\n nextUrl: state.nextUrl,\n prefetchCache: state.prefetchCache,\n kind: action.kind,\n tree: state.tree,\n allowAliasing: true,\n })\n\n return state\n}\n"],"names":["prefetchQueue","prefetchReducer","PromiseQueue","process","env","__NEXT_CLIENT_SEGMENT_CACHE","identityReducerWhenSegmentCacheIsEnabled","prefetchReducerImpl","state","action","prunePrefetchCache","prefetchCache","url","getOrCreatePrefetchCacheEntry","nextUrl","kind","tree","allowAliasing"],"mappings":";;;;;;;;;;;;;;;IAUaA,aAAa;eAAbA;;IAEAC,eAAe;eAAfA;;;8BAPgB;oCAItB;AACA,MAAMD,gBAAgB,IAAIE,0BAAY,CAAC;AAEvC,MAAMD,kBAAkBE,QAAQC,GAAG,CAACC,2BAA2B,GAClEC,2CACAC;AAEJ,SAASD,yCAA4CE,KAAQ;IAC3D,6EAA6E;IAC7E,4BAA4B;IAC5B,EAAE;IACF,2EAA2E;IAC3E,0EAA0E;IAC1E,8BAA8B;IAC9B,OAAOA;AACT;AAEA,SAASD,oBACPC,KAA2B,EAC3BC,MAAsB;IAEtB,4DAA4D;IAC5DC,IAAAA,sCAAkB,EAACF,MAAMG,aAAa;IAEtC,MAAM,EAAEC,GAAG,EAAE,GAAGH;IAEhBI,IAAAA,iDAA6B,EAAC;QAC5BD;QACAE,SAASN,MAAMM,OAAO;QACtBH,eAAeH,MAAMG,aAAa;QAClCI,MAAMN,OAAOM,IAAI;QACjBC,MAAMR,MAAMQ,IAAI;QAChBC,eAAe;IACjB;IAEA,OAAOT;AACT"}
|
||||
2
node_modules/next/dist/client/components/router-reducer/reducers/refresh-reducer.d.ts
generated
vendored
Normal file
2
node_modules/next/dist/client/components/router-reducer/reducers/refresh-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { ReadonlyReducerState, ReducerState, RefreshAction } from '../router-reducer-types';
|
||||
export declare function refreshReducer(state: ReadonlyReducerState, action: RefreshAction): ReducerState;
|
||||
111
node_modules/next/dist/client/components/router-reducer/reducers/refresh-reducer.js
generated
vendored
Normal file
111
node_modules/next/dist/client/components/router-reducer/reducers/refresh-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
"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 _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 _filllazyitemstillleafwithhead = require("../fill-lazy-items-till-leaf-with-head");
|
||||
const _approuter = require("../../app-router");
|
||||
const _handlesegmentmismatch = require("../handle-segment-mismatch");
|
||||
const _hasinterceptionrouteincurrenttree = require("./has-interception-route-in-current-tree");
|
||||
const _refetchinactiveparallelsegments = require("../refetch-inactive-parallel-segments");
|
||||
const _segmentcache = require("../../segment-cache");
|
||||
function refreshReducer(state, action) {
|
||||
const { origin } = action;
|
||||
const mutable = {};
|
||||
const href = state.canonicalUrl;
|
||||
let currentTree = state.tree;
|
||||
mutable.preserveCustomHistoryState = false;
|
||||
const cache = (0, _approuter.createEmptyCacheNode)();
|
||||
// If the current tree was intercepted, the nextUrl should be included in the request.
|
||||
// This is to ensure that the refresh request doesn't get intercepted, accidentally triggering the interception route.
|
||||
const includeNextUrl = (0, _hasinterceptionrouteincurrenttree.hasInterceptionRouteInCurrentTree)(state.tree);
|
||||
// TODO-APP: verify that `href` is not an external url.
|
||||
// Fetch data from the root of the tree.
|
||||
cache.lazyData = (0, _fetchserverresponse.fetchServerResponse)(new URL(href, origin), {
|
||||
flightRouterState: [
|
||||
currentTree[0],
|
||||
currentTree[1],
|
||||
currentTree[2],
|
||||
'refetch'
|
||||
],
|
||||
nextUrl: includeNextUrl ? state.nextUrl : null
|
||||
});
|
||||
const navigatedAt = Date.now();
|
||||
return cache.lazyData.then(async (param)=>{
|
||||
let { flightData, canonicalUrl: canonicalUrlOverride } = param;
|
||||
// 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.lazyData as it has been resolved at this point.
|
||||
cache.lazyData = null;
|
||||
for (const normalizedFlightData of flightData){
|
||||
const { tree: treePatch, seedData: cacheNodeSeedData, head, isRootRender } = normalizedFlightData;
|
||||
if (!isRootRender) {
|
||||
// TODO-APP: handle this case better
|
||||
console.log('REFRESH FAILED');
|
||||
return state;
|
||||
}
|
||||
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
|
||||
[
|
||||
''
|
||||
], currentTree, treePatch, state.canonicalUrl);
|
||||
if (newTree === null) {
|
||||
return (0, _handlesegmentmismatch.handleSegmentMismatch)(state, action, treePatch);
|
||||
}
|
||||
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;
|
||||
}
|
||||
// Handles case where prefetch only returns the router tree patch without rendered components.
|
||||
if (cacheNodeSeedData !== null) {
|
||||
const rsc = cacheNodeSeedData[1];
|
||||
const loading = cacheNodeSeedData[3];
|
||||
cache.rsc = rsc;
|
||||
cache.prefetchRsc = null;
|
||||
cache.loading = loading;
|
||||
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(navigatedAt, cache, // Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache.
|
||||
undefined, treePatch, cacheNodeSeedData, head, undefined);
|
||||
if (process.env.__NEXT_CLIENT_SEGMENT_CACHE) {
|
||||
(0, _segmentcache.revalidateEntireCache)(state.nextUrl, newTree);
|
||||
} else {
|
||||
mutable.prefetchCache = new Map();
|
||||
}
|
||||
}
|
||||
await (0, _refetchinactiveparallelsegments.refreshInactiveParallelSegments)({
|
||||
navigatedAt,
|
||||
state,
|
||||
updatedTree: newTree,
|
||||
updatedCache: cache,
|
||||
includeNextUrl,
|
||||
canonicalUrl: mutable.canonicalUrl || state.canonicalUrl
|
||||
});
|
||||
mutable.cache = cache;
|
||||
mutable.patchedTree = newTree;
|
||||
currentTree = newTree;
|
||||
}
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}, ()=>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=refresh-reducer.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/refresh-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/refresh-reducer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/next/dist/client/components/router-reducer/reducers/restore-reducer.d.ts
generated
vendored
Normal file
2
node_modules/next/dist/client/components/router-reducer/reducers/restore-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { ReadonlyReducerState, ReducerState, RestoreAction } from '../router-reducer-types';
|
||||
export declare function restoreReducer(state: ReadonlyReducerState, action: RestoreAction): ReducerState;
|
||||
54
node_modules/next/dist/client/components/router-reducer/reducers/restore-reducer.js
generated
vendored
Normal file
54
node_modules/next/dist/client/components/router-reducer/reducers/restore-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
"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");
|
||||
const _computechangedpath = require("../compute-changed-path");
|
||||
const _pprnavigations = require("../ppr-navigations");
|
||||
function restoreReducer(state, action) {
|
||||
const { url, tree } = action;
|
||||
const href = (0, _createhreffromurl.createHrefFromUrl)(url);
|
||||
// This action is used to restore the router state from the history state.
|
||||
// However, it's possible that the history state no longer contains the `FlightRouterState`.
|
||||
// We will copy over the internal state on pushState/replaceState events, but if a history entry
|
||||
// occurred before hydration, or if the user navigated to a hash using a regular anchor link,
|
||||
// the history state will not contain the `FlightRouterState`.
|
||||
// In this case, we'll continue to use the existing tree so the router doesn't get into an invalid state.
|
||||
const treeToRestore = tree || state.tree;
|
||||
const oldCache = state.cache;
|
||||
const newCache = process.env.__NEXT_PPR ? // data for any segment whose dynamic data was already received. This
|
||||
// prevents an unnecessary flash back to PPR state during a
|
||||
// back/forward navigation.
|
||||
(0, _pprnavigations.updateCacheNodeOnPopstateRestoration)(oldCache, treeToRestore) : oldCache;
|
||||
var _extractPathFromFlightRouterState;
|
||||
return {
|
||||
// Set canonical url
|
||||
canonicalUrl: href,
|
||||
pushRef: {
|
||||
pendingPush: false,
|
||||
mpaNavigation: false,
|
||||
// Ensures that the custom history state that was set is preserved when applying this update.
|
||||
preserveCustomHistoryState: true
|
||||
},
|
||||
focusAndScrollRef: state.focusAndScrollRef,
|
||||
cache: newCache,
|
||||
prefetchCache: state.prefetchCache,
|
||||
// Restore provided tree
|
||||
tree: treeToRestore,
|
||||
nextUrl: (_extractPathFromFlightRouterState = (0, _computechangedpath.extractPathFromFlightRouterState)(treeToRestore)) != null ? _extractPathFromFlightRouterState : 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
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/restore-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/restore-reducer.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/restore-reducer.ts"],"sourcesContent":["import { createHrefFromUrl } from '../create-href-from-url'\nimport type {\n ReadonlyReducerState,\n ReducerState,\n RestoreAction,\n} from '../router-reducer-types'\nimport { extractPathFromFlightRouterState } from '../compute-changed-path'\nimport { updateCacheNodeOnPopstateRestoration } from '../ppr-navigations'\n\nexport function restoreReducer(\n state: ReadonlyReducerState,\n action: RestoreAction\n): ReducerState {\n const { url, tree } = action\n const href = createHrefFromUrl(url)\n // This action is used to restore the router state from the history state.\n // However, it's possible that the history state no longer contains the `FlightRouterState`.\n // We will copy over the internal state on pushState/replaceState events, but if a history entry\n // occurred before hydration, or if the user navigated to a hash using a regular anchor link,\n // the history state will not contain the `FlightRouterState`.\n // In this case, we'll continue to use the existing tree so the router doesn't get into an invalid state.\n const treeToRestore = tree || state.tree\n\n const oldCache = state.cache\n const newCache = process.env.__NEXT_PPR\n ? // When PPR is enabled, we update the cache to drop the prefetch\n // data for any segment whose dynamic data was already received. This\n // prevents an unnecessary flash back to PPR state during a\n // back/forward navigation.\n updateCacheNodeOnPopstateRestoration(oldCache, treeToRestore)\n : oldCache\n\n return {\n // Set canonical url\n canonicalUrl: href,\n pushRef: {\n pendingPush: false,\n mpaNavigation: false,\n // Ensures that the custom history state that was set is preserved when applying this update.\n preserveCustomHistoryState: true,\n },\n focusAndScrollRef: state.focusAndScrollRef,\n cache: newCache,\n prefetchCache: state.prefetchCache,\n // Restore provided tree\n tree: treeToRestore,\n nextUrl: extractPathFromFlightRouterState(treeToRestore) ?? url.pathname,\n }\n}\n"],"names":["restoreReducer","state","action","url","tree","href","createHrefFromUrl","treeToRestore","oldCache","cache","newCache","process","env","__NEXT_PPR","updateCacheNodeOnPopstateRestoration","extractPathFromFlightRouterState","canonicalUrl","pushRef","pendingPush","mpaNavigation","preserveCustomHistoryState","focusAndScrollRef","prefetchCache","nextUrl","pathname"],"mappings":";;;;+BASgBA;;;eAAAA;;;mCATkB;oCAMe;gCACI;AAE9C,SAASA,eACdC,KAA2B,EAC3BC,MAAqB;IAErB,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAE,GAAGF;IACtB,MAAMG,OAAOC,IAAAA,oCAAiB,EAACH;IAC/B,0EAA0E;IAC1E,4FAA4F;IAC5F,gGAAgG;IAChG,6FAA6F;IAC7F,8DAA8D;IAC9D,yGAAyG;IACzG,MAAMI,gBAAgBH,QAAQH,MAAMG,IAAI;IAExC,MAAMI,WAAWP,MAAMQ,KAAK;IAC5B,MAAMC,WAAWC,QAAQC,GAAG,CAACC,UAAU,GAEnC,qEAAqE;IACrE,2DAA2D;IAC3D,2BAA2B;IAC3BC,IAAAA,oDAAoC,EAACN,UAAUD,iBAC/CC;QAgBOO;IAdX,OAAO;QACL,oBAAoB;QACpBC,cAAcX;QACdY,SAAS;YACPC,aAAa;YACbC,eAAe;YACf,6FAA6F;YAC7FC,4BAA4B;QAC9B;QACAC,mBAAmBpB,MAAMoB,iBAAiB;QAC1CZ,OAAOC;QACPY,eAAerB,MAAMqB,aAAa;QAClC,wBAAwB;QACxBlB,MAAMG;QACNgB,SAASR,CAAAA,oCAAAA,IAAAA,oDAAgC,EAACR,0BAAjCQ,oCAAmDZ,IAAIqB,QAAQ;IAC1E;AACF"}
|
||||
2
node_modules/next/dist/client/components/router-reducer/reducers/server-action-reducer.d.ts
generated
vendored
Normal file
2
node_modules/next/dist/client/components/router-reducer/reducers/server-action-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import { type ReadonlyReducerState, type ReducerState, type ServerActionAction } from '../router-reducer-types';
|
||||
export declare function serverActionReducer(state: ReadonlyReducerState, action: ServerActionAction): ReducerState;
|
||||
284
node_modules/next/dist/client/components/router-reducer/reducers/server-action-reducer.js
generated
vendored
Normal file
284
node_modules/next/dist/client/components/router-reducer/reducers/server-action-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
"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 _appfindsourcemapurl = require("../../../app-find-source-map-url");
|
||||
const _approuterheaders = require("../../app-router-headers");
|
||||
const _routerreducertypes = require("../router-reducer-types");
|
||||
const _assignlocation = require("../../../assign-location");
|
||||
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 _handlemutable = require("../handle-mutable");
|
||||
const _filllazyitemstillleafwithhead = require("../fill-lazy-items-till-leaf-with-head");
|
||||
const _approuter = require("../../app-router");
|
||||
const _hasinterceptionrouteincurrenttree = require("./has-interception-route-in-current-tree");
|
||||
const _handlesegmentmismatch = require("../handle-segment-mismatch");
|
||||
const _refetchinactiveparallelsegments = require("../refetch-inactive-parallel-segments");
|
||||
const _flightdatahelpers = require("../../../flight-data-helpers");
|
||||
const _redirect = require("../../redirect");
|
||||
const _redirecterror = require("../../redirect-error");
|
||||
const _prefetchcacheutils = require("../prefetch-cache-utils");
|
||||
const _removebasepath = require("../../../remove-base-path");
|
||||
const _hasbasepath = require("../../../has-base-path");
|
||||
const _serverreferenceinfo = require("../../../../shared/lib/server-reference-info");
|
||||
const _segmentcache = require("../../segment-cache");
|
||||
// // 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, createTemporaryReferenceSet, encodeReply } = !!process.env.NEXT_RUNTIME ? require('react-server-dom-webpack/client.edge') : require('react-server-dom-webpack/client');
|
||||
async function fetchServerAction(state, nextUrl, param) {
|
||||
let { actionId, actionArgs } = param;
|
||||
const temporaryReferences = createTemporaryReferenceSet();
|
||||
const info = (0, _serverreferenceinfo.extractInfoFromServerReferenceId)(actionId);
|
||||
// TODO: Currently, we're only omitting unused args for the experimental "use
|
||||
// cache" functions. Once the server reference info byte feature is stable, we
|
||||
// should apply this to server actions as well.
|
||||
const usedArgs = info.type === 'use-cache' ? (0, _serverreferenceinfo.omitUnusedArgs)(actionArgs, info) : actionArgs;
|
||||
const body = await encodeReply(usedArgs, {
|
||||
temporaryReferences
|
||||
});
|
||||
const res = await fetch('', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: _approuterheaders.RSC_CONTENT_TYPE_HEADER,
|
||||
[_approuterheaders.ACTION_HEADER]: actionId,
|
||||
[_approuterheaders.NEXT_ROUTER_STATE_TREE_HEADER]: encodeURIComponent(JSON.stringify(state.tree)),
|
||||
...process.env.NEXT_DEPLOYMENT_ID ? {
|
||||
'x-deployment-id': process.env.NEXT_DEPLOYMENT_ID
|
||||
} : {},
|
||||
...nextUrl ? {
|
||||
[_approuterheaders.NEXT_URL]: nextUrl
|
||||
} : {}
|
||||
},
|
||||
body
|
||||
});
|
||||
const redirectHeader = res.headers.get('x-action-redirect');
|
||||
const [location, _redirectType] = (redirectHeader == null ? void 0 : redirectHeader.split(';')) || [];
|
||||
let redirectType;
|
||||
switch(_redirectType){
|
||||
case 'push':
|
||||
redirectType = _redirecterror.RedirectType.push;
|
||||
break;
|
||||
case 'replace':
|
||||
redirectType = _redirecterror.RedirectType.replace;
|
||||
break;
|
||||
default:
|
||||
redirectType = undefined;
|
||||
}
|
||||
const isPrerender = !!res.headers.get(_approuterheaders.NEXT_IS_PRERENDER_HEADER);
|
||||
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 ? (0, _assignlocation.assignLocation)(location, new URL(state.canonicalUrl, window.location.href)) : undefined;
|
||||
const contentType = res.headers.get('content-type');
|
||||
if (contentType == null ? void 0 : contentType.startsWith(_approuterheaders.RSC_CONTENT_TYPE_HEADER)) {
|
||||
const response = await createFromFetch(Promise.resolve(res), {
|
||||
callServer: _appcallserver.callServer,
|
||||
findSourceMapURL: _appfindsourcemapurl.findSourceMapURL,
|
||||
temporaryReferences
|
||||
});
|
||||
if (location) {
|
||||
// if it was a redirection, then result is just a regular RSC payload
|
||||
return {
|
||||
actionFlightData: (0, _flightdatahelpers.normalizeFlightData)(response.f),
|
||||
redirectLocation,
|
||||
redirectType,
|
||||
revalidatedParts,
|
||||
isPrerender
|
||||
};
|
||||
}
|
||||
return {
|
||||
actionResult: response.a,
|
||||
actionFlightData: (0, _flightdatahelpers.normalizeFlightData)(response.f),
|
||||
redirectLocation,
|
||||
redirectType,
|
||||
revalidatedParts,
|
||||
isPrerender
|
||||
};
|
||||
}
|
||||
// Handle invalid server action responses
|
||||
if (res.status >= 400) {
|
||||
// The server can respond with a text/plain error message, but we'll fallback to something generic
|
||||
// if there isn't one.
|
||||
const error = contentType === 'text/plain' ? await res.text() : 'An unexpected response was received from the server.';
|
||||
throw Object.defineProperty(new Error(error), "__NEXT_ERROR_CODE", {
|
||||
value: "E394",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
return {
|
||||
redirectLocation,
|
||||
redirectType,
|
||||
revalidatedParts,
|
||||
isPrerender
|
||||
};
|
||||
}
|
||||
function serverActionReducer(state, action) {
|
||||
const { resolve, reject } = action;
|
||||
const mutable = {};
|
||||
let currentTree = state.tree;
|
||||
mutable.preserveCustomHistoryState = false;
|
||||
// only pass along the `nextUrl` param (used for interception routes) if the current route was intercepted.
|
||||
// If the route has been intercepted, the action should be as well.
|
||||
// Otherwise the server action might be intercepted with the wrong action id
|
||||
// (ie, one that corresponds with the intercepted route)
|
||||
const nextUrl = state.nextUrl && (0, _hasinterceptionrouteincurrenttree.hasInterceptionRouteInCurrentTree)(state.tree) ? state.nextUrl : null;
|
||||
const navigatedAt = Date.now();
|
||||
return fetchServerAction(state, nextUrl, action).then(async (param)=>{
|
||||
let { actionResult, actionFlightData: flightData, redirectLocation, redirectType, isPrerender, revalidatedParts } = param;
|
||||
let redirectHref;
|
||||
// honor the redirect type instead of defaulting to push in case of server actions.
|
||||
if (redirectLocation) {
|
||||
if (redirectType === _redirecterror.RedirectType.replace) {
|
||||
state.pushRef.pendingPush = false;
|
||||
mutable.pendingPush = false;
|
||||
} else {
|
||||
state.pushRef.pendingPush = true;
|
||||
mutable.pendingPush = true;
|
||||
}
|
||||
redirectHref = (0, _createhreffromurl.createHrefFromUrl)(redirectLocation, false);
|
||||
mutable.canonicalUrl = redirectHref;
|
||||
}
|
||||
if (!flightData) {
|
||||
resolve(actionResult);
|
||||
// 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`
|
||||
resolve(actionResult);
|
||||
return (0, _navigatereducer.handleExternalUrl)(state, mutable, flightData, state.pushRef.pendingPush);
|
||||
}
|
||||
const actionRevalidated = revalidatedParts.paths.length > 0 || revalidatedParts.tag || revalidatedParts.cookie;
|
||||
for (const normalizedFlightData of flightData){
|
||||
const { tree: treePatch, seedData: cacheNodeSeedData, head, isRootRender } = normalizedFlightData;
|
||||
if (!isRootRender) {
|
||||
// TODO-APP: handle this case better
|
||||
console.log('SERVER ACTION APPLY FAILED');
|
||||
resolve(actionResult);
|
||||
return state;
|
||||
}
|
||||
// Given the path can only have two items the items are only the router state and rsc for the root.
|
||||
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
|
||||
[
|
||||
''
|
||||
], currentTree, treePatch, redirectHref ? redirectHref : state.canonicalUrl);
|
||||
if (newTree === null) {
|
||||
resolve(actionResult);
|
||||
return (0, _handlesegmentmismatch.handleSegmentMismatch)(state, action, treePatch);
|
||||
}
|
||||
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
|
||||
resolve(actionResult);
|
||||
return (0, _navigatereducer.handleExternalUrl)(state, mutable, redirectHref || state.canonicalUrl, state.pushRef.pendingPush);
|
||||
}
|
||||
// The server sent back RSC data for the server action, so we need to apply it to the cache.
|
||||
if (cacheNodeSeedData !== null) {
|
||||
const rsc = cacheNodeSeedData[1];
|
||||
const cache = (0, _approuter.createEmptyCacheNode)();
|
||||
cache.rsc = rsc;
|
||||
cache.prefetchRsc = null;
|
||||
cache.loading = cacheNodeSeedData[3];
|
||||
(0, _filllazyitemstillleafwithhead.fillLazyItemsTillLeafWithHead)(navigatedAt, cache, // Existing cache is not passed in as server actions have to invalidate the entire cache.
|
||||
undefined, treePatch, cacheNodeSeedData, head, undefined);
|
||||
mutable.cache = cache;
|
||||
if (process.env.__NEXT_CLIENT_SEGMENT_CACHE) {
|
||||
(0, _segmentcache.revalidateEntireCache)(state.nextUrl, newTree);
|
||||
} else {
|
||||
mutable.prefetchCache = new Map();
|
||||
}
|
||||
if (actionRevalidated) {
|
||||
await (0, _refetchinactiveparallelsegments.refreshInactiveParallelSegments)({
|
||||
navigatedAt,
|
||||
state,
|
||||
updatedTree: newTree,
|
||||
updatedCache: cache,
|
||||
includeNextUrl: Boolean(nextUrl),
|
||||
canonicalUrl: mutable.canonicalUrl || state.canonicalUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
mutable.patchedTree = newTree;
|
||||
currentTree = newTree;
|
||||
}
|
||||
if (redirectLocation && redirectHref) {
|
||||
if (!process.env.__NEXT_CLIENT_SEGMENT_CACHE && !actionRevalidated) {
|
||||
// Because the RedirectBoundary will trigger a navigation, we need to seed the prefetch cache
|
||||
// with the FlightData that we got from the server action for the target page, so that it's
|
||||
// available when the page is navigated to and doesn't need to be re-fetched.
|
||||
// We only do this if the server action didn't revalidate any data, as in that case the
|
||||
// client cache will be cleared and the data will be re-fetched anyway.
|
||||
// NOTE: We don't do this in the Segment Cache implementation.
|
||||
// Dynamic data should never be placed into the cache, unless it's
|
||||
// "converted" to static data using <Link prefetch={true}>. What we
|
||||
// do instead is re-prefetch links and forms whenever the cache is
|
||||
// invalidated.
|
||||
(0, _prefetchcacheutils.createSeededPrefetchCacheEntry)({
|
||||
url: redirectLocation,
|
||||
data: {
|
||||
flightData,
|
||||
canonicalUrl: undefined,
|
||||
couldBeIntercepted: false,
|
||||
prerendered: false,
|
||||
postponed: false,
|
||||
// TODO: We should be able to set this if the server action
|
||||
// returned a fully static response.
|
||||
staleTime: -1
|
||||
},
|
||||
tree: state.tree,
|
||||
prefetchCache: state.prefetchCache,
|
||||
nextUrl: state.nextUrl,
|
||||
kind: isPrerender ? _routerreducertypes.PrefetchKind.FULL : _routerreducertypes.PrefetchKind.AUTO
|
||||
});
|
||||
mutable.prefetchCache = state.prefetchCache;
|
||||
}
|
||||
// If the action triggered a redirect, the action promise will be rejected with
|
||||
// a redirect so that it's handled by RedirectBoundary as we won't have a valid
|
||||
// action result to resolve the promise with. This will effectively reset the state of
|
||||
// the component that called the action as the error boundary will remount the tree.
|
||||
// The status code doesn't matter here as the action handler will have already sent
|
||||
// a response with the correct status code.
|
||||
reject((0, _redirect.getRedirectError)((0, _hasbasepath.hasBasePath)(redirectHref) ? (0, _removebasepath.removeBasePath)(redirectHref) : redirectHref, redirectType || _redirecterror.RedirectType.push));
|
||||
} else {
|
||||
resolve(actionResult);
|
||||
}
|
||||
return (0, _handlemutable.handleMutable)(state, mutable);
|
||||
}, (e)=>{
|
||||
// When the server action is rejected we don't update the state and instead call the reject handler of the promise.
|
||||
reject(e);
|
||||
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=server-action-reducer.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/server-action-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/server-action-reducer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/next/dist/client/components/router-reducer/reducers/server-patch-reducer.d.ts
generated
vendored
Normal file
2
node_modules/next/dist/client/components/router-reducer/reducers/server-patch-reducer.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { ServerPatchAction, ReducerState, ReadonlyReducerState } from '../router-reducer-types';
|
||||
export declare function serverPatchReducer(state: ReadonlyReducerState, action: ServerPatchAction): ReducerState;
|
||||
66
node_modules/next/dist/client/components/router-reducer/reducers/server-patch-reducer.js
generated
vendored
Normal file
66
node_modules/next/dist/client/components/router-reducer/reducers/server-patch-reducer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "serverPatchReducer", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return serverPatchReducer;
|
||||
}
|
||||
});
|
||||
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 _applyflightdata = require("../apply-flight-data");
|
||||
const _handlemutable = require("../handle-mutable");
|
||||
const _approuter = require("../../app-router");
|
||||
function serverPatchReducer(state, action) {
|
||||
const { serverResponse: { flightData, canonicalUrl: canonicalUrlOverride }, navigatedAt } = action;
|
||||
const mutable = {};
|
||||
mutable.preserveCustomHistoryState = false;
|
||||
// Handle case when navigating to page in `pages` from `app`
|
||||
if (typeof flightData === 'string') {
|
||||
return (0, _navigatereducer.handleExternalUrl)(state, mutable, flightData, state.pushRef.pendingPush);
|
||||
}
|
||||
let currentTree = state.tree;
|
||||
let currentCache = state.cache;
|
||||
for (const normalizedFlightData of flightData){
|
||||
const { segmentPath: flightSegmentPath, tree: treePatch } = normalizedFlightData;
|
||||
const newTree = (0, _applyrouterstatepatchtotree.applyRouterStatePatchToTree)(// TODO-APP: remove ''
|
||||
[
|
||||
'',
|
||||
...flightSegmentPath
|
||||
], currentTree, treePatch, state.canonicalUrl);
|
||||
// `applyRouterStatePatchToTree` returns `null` when it determined that the server response is not applicable to the current tree.
|
||||
// In other words, the server responded with a tree that doesn't match what the client is currently rendering.
|
||||
// This can happen if the server patch action took longer to resolve than a subsequent navigation which would have changed the tree.
|
||||
// Previously this case triggered an MPA navigation but it should be safe to simply discard the server response rather than forcing
|
||||
// the entire page to reload.
|
||||
if (newTree === null) {
|
||||
return state;
|
||||
}
|
||||
if ((0, _isnavigatingtonewrootlayout.isNavigatingToNewRootLayout)(currentTree, newTree)) {
|
||||
return (0, _navigatereducer.handleExternalUrl)(state, mutable, state.canonicalUrl, state.pushRef.pendingPush);
|
||||
}
|
||||
const canonicalUrlOverrideHref = canonicalUrlOverride ? (0, _createhreffromurl.createHrefFromUrl)(canonicalUrlOverride) : undefined;
|
||||
if (canonicalUrlOverrideHref) {
|
||||
mutable.canonicalUrl = canonicalUrlOverrideHref;
|
||||
}
|
||||
const cache = (0, _approuter.createEmptyCacheNode)();
|
||||
(0, _applyflightdata.applyFlightData)(navigatedAt, currentCache, cache, normalizedFlightData);
|
||||
mutable.patchedTree = newTree;
|
||||
mutable.cache = cache;
|
||||
currentCache = cache;
|
||||
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=server-patch-reducer.js.map
|
||||
1
node_modules/next/dist/client/components/router-reducer/reducers/server-patch-reducer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/client/components/router-reducer/reducers/server-patch-reducer.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/server-patch-reducer.ts"],"sourcesContent":["import { createHrefFromUrl } from '../create-href-from-url'\nimport { applyRouterStatePatchToTree } from '../apply-router-state-patch-to-tree'\nimport { isNavigatingToNewRootLayout } from '../is-navigating-to-new-root-layout'\nimport type {\n ServerPatchAction,\n ReducerState,\n ReadonlyReducerState,\n Mutable,\n} from '../router-reducer-types'\nimport { handleExternalUrl } from './navigate-reducer'\nimport { applyFlightData } from '../apply-flight-data'\nimport { handleMutable } from '../handle-mutable'\nimport type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'\nimport { createEmptyCacheNode } from '../../app-router'\n\nexport function serverPatchReducer(\n state: ReadonlyReducerState,\n action: ServerPatchAction\n): ReducerState {\n const {\n serverResponse: { flightData, canonicalUrl: canonicalUrlOverride },\n navigatedAt,\n } = action\n\n const mutable: Mutable = {}\n\n mutable.preserveCustomHistoryState = false\n\n // Handle case when navigating to page in `pages` from `app`\n if (typeof flightData === 'string') {\n return handleExternalUrl(\n state,\n mutable,\n flightData,\n state.pushRef.pendingPush\n )\n }\n\n let currentTree = state.tree\n let currentCache = state.cache\n\n for (const normalizedFlightData of flightData) {\n const { segmentPath: flightSegmentPath, tree: treePatch } =\n normalizedFlightData\n\n const newTree = applyRouterStatePatchToTree(\n // TODO-APP: remove ''\n ['', ...flightSegmentPath],\n currentTree,\n treePatch,\n state.canonicalUrl\n )\n\n // `applyRouterStatePatchToTree` returns `null` when it determined that the server response is not applicable to the current tree.\n // In other words, the server responded with a tree that doesn't match what the client is currently rendering.\n // This can happen if the server patch action took longer to resolve than a subsequent navigation which would have changed the tree.\n // Previously this case triggered an MPA navigation but it should be safe to simply discard the server response rather than forcing\n // the entire page to reload.\n if (newTree === null) {\n return state\n }\n\n if (isNavigatingToNewRootLayout(currentTree, newTree)) {\n return handleExternalUrl(\n state,\n mutable,\n state.canonicalUrl,\n state.pushRef.pendingPush\n )\n }\n\n const canonicalUrlOverrideHref = canonicalUrlOverride\n ? createHrefFromUrl(canonicalUrlOverride)\n : undefined\n\n if (canonicalUrlOverrideHref) {\n mutable.canonicalUrl = canonicalUrlOverrideHref\n }\n\n const cache: CacheNode = createEmptyCacheNode()\n applyFlightData(navigatedAt, currentCache, cache, normalizedFlightData)\n\n mutable.patchedTree = newTree\n mutable.cache = cache\n\n currentCache = cache\n currentTree = newTree\n }\n\n return handleMutable(state, mutable)\n}\n"],"names":["serverPatchReducer","state","action","serverResponse","flightData","canonicalUrl","canonicalUrlOverride","navigatedAt","mutable","preserveCustomHistoryState","handleExternalUrl","pushRef","pendingPush","currentTree","tree","currentCache","cache","normalizedFlightData","segmentPath","flightSegmentPath","treePatch","newTree","applyRouterStatePatchToTree","isNavigatingToNewRootLayout","canonicalUrlOverrideHref","createHrefFromUrl","undefined","createEmptyCacheNode","applyFlightData","patchedTree","handleMutable"],"mappings":";;;;+BAegBA;;;eAAAA;;;mCAfkB;6CACU;6CACA;iCAOV;iCACF;+BACF;2BAEO;AAE9B,SAASA,mBACdC,KAA2B,EAC3BC,MAAyB;IAEzB,MAAM,EACJC,gBAAgB,EAAEC,UAAU,EAAEC,cAAcC,oBAAoB,EAAE,EAClEC,WAAW,EACZ,GAAGL;IAEJ,MAAMM,UAAmB,CAAC;IAE1BA,QAAQC,0BAA0B,GAAG;IAErC,4DAA4D;IAC5D,IAAI,OAAOL,eAAe,UAAU;QAClC,OAAOM,IAAAA,kCAAiB,EACtBT,OACAO,SACAJ,YACAH,MAAMU,OAAO,CAACC,WAAW;IAE7B;IAEA,IAAIC,cAAcZ,MAAMa,IAAI;IAC5B,IAAIC,eAAed,MAAMe,KAAK;IAE9B,KAAK,MAAMC,wBAAwBb,WAAY;QAC7C,MAAM,EAAEc,aAAaC,iBAAiB,EAAEL,MAAMM,SAAS,EAAE,GACvDH;QAEF,MAAMI,UAAUC,IAAAA,wDAA2B,EACzC,sBAAsB;QACtB;YAAC;eAAOH;SAAkB,EAC1BN,aACAO,WACAnB,MAAMI,YAAY;QAGpB,kIAAkI;QAClI,8GAA8G;QAC9G,oIAAoI;QACpI,mIAAmI;QACnI,6BAA6B;QAC7B,IAAIgB,YAAY,MAAM;YACpB,OAAOpB;QACT;QAEA,IAAIsB,IAAAA,wDAA2B,EAACV,aAAaQ,UAAU;YACrD,OAAOX,IAAAA,kCAAiB,EACtBT,OACAO,SACAP,MAAMI,YAAY,EAClBJ,MAAMU,OAAO,CAACC,WAAW;QAE7B;QAEA,MAAMY,2BAA2BlB,uBAC7BmB,IAAAA,oCAAiB,EAACnB,wBAClBoB;QAEJ,IAAIF,0BAA0B;YAC5BhB,QAAQH,YAAY,GAAGmB;QACzB;QAEA,MAAMR,QAAmBW,IAAAA,+BAAoB;QAC7CC,IAAAA,gCAAe,EAACrB,aAAaQ,cAAcC,OAAOC;QAElDT,QAAQqB,WAAW,GAAGR;QACtBb,QAAQQ,KAAK,GAAGA;QAEhBD,eAAeC;QACfH,cAAcQ;IAChB;IAEA,OAAOS,IAAAA,4BAAa,EAAC7B,OAAOO;AAC9B"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue