@modern-js/runtime 2.68.0 → 2.68.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/code.js +6 -3
- package/dist/cjs/cli/template.js +72 -21
- package/dist/cjs/cli/template.server.js +62 -13
- package/dist/cjs/core/context/index.js +19 -2
- package/dist/cjs/core/context/serverPayload.server.js +40 -0
- package/dist/cjs/core/server/requestHandler.js +47 -11
- package/dist/cjs/router/cli/code/index.js +13 -6
- package/dist/cjs/router/cli/code/templates.js +44 -20
- package/dist/cjs/router/cli/handler.js +17 -2
- package/dist/cjs/router/cli/index.js +6 -5
- package/dist/cjs/router/index.js +0 -21
- package/dist/cjs/router/internal.js +30 -0
- package/dist/cjs/router/runtime/PrefetchLink.js +3 -4
- package/dist/cjs/router/runtime/constants.js +2 -2
- package/dist/cjs/router/runtime/index.js +1 -12
- package/dist/cjs/router/runtime/internal.js +36 -0
- package/dist/cjs/router/runtime/plugin.js +134 -76
- package/dist/cjs/router/runtime/plugin.node.js +73 -32
- package/dist/cjs/router/runtime/rsc-router.js +322 -0
- package/dist/cjs/router/runtime/utils.js +76 -1
- package/dist/cjs/rsc/client.js +11 -0
- package/dist/cjs/rsc/server.js +40 -0
- package/dist/esm/cli/code.js +6 -3
- package/dist/esm/cli/template.js +25 -6
- package/dist/esm/cli/template.server.js +3 -3
- package/dist/esm/core/context/index.js +14 -1
- package/dist/esm/core/context/serverPayload.server.js +15 -0
- package/dist/esm/core/server/requestHandler.js +102 -9
- package/dist/esm/router/cli/code/index.js +12 -6
- package/dist/esm/router/cli/code/templates.js +29 -13
- package/dist/esm/router/cli/handler.js +33 -6
- package/dist/esm/router/cli/index.js +6 -5
- package/dist/esm/router/index.js +0 -6
- package/dist/esm/router/internal.js +5 -0
- package/dist/esm/router/runtime/PrefetchLink.js +2 -2
- package/dist/esm/router/runtime/constants.js +2 -2
- package/dist/esm/router/runtime/index.js +1 -9
- package/dist/esm/router/runtime/internal.js +10 -0
- package/dist/esm/router/runtime/plugin.js +134 -85
- package/dist/esm/router/runtime/plugin.node.js +110 -40
- package/dist/esm/router/runtime/rsc-router.js +437 -0
- package/dist/esm/router/runtime/utils.js +95 -1
- package/dist/esm/rsc/client.js +6 -0
- package/dist/esm/rsc/server.js +86 -0
- package/dist/esm-node/cli/code.js +6 -3
- package/dist/esm-node/cli/template.js +72 -21
- package/dist/esm-node/cli/template.server.js +62 -13
- package/dist/esm-node/core/context/index.js +14 -1
- package/dist/esm-node/core/context/serverPayload.server.js +15 -0
- package/dist/esm-node/core/server/requestHandler.js +45 -9
- package/dist/esm-node/router/cli/code/index.js +12 -6
- package/dist/esm-node/router/cli/code/templates.js +44 -20
- package/dist/esm-node/router/cli/handler.js +17 -2
- package/dist/esm-node/router/cli/index.js +6 -5
- package/dist/esm-node/router/index.js +0 -6
- package/dist/esm-node/router/internal.js +5 -0
- package/dist/esm-node/router/runtime/PrefetchLink.js +2 -2
- package/dist/esm-node/router/runtime/constants.js +2 -2
- package/dist/esm-node/router/runtime/index.js +1 -9
- package/dist/esm-node/router/runtime/internal.js +10 -0
- package/dist/esm-node/router/runtime/plugin.js +126 -78
- package/dist/esm-node/router/runtime/plugin.node.js +75 -34
- package/dist/esm-node/router/runtime/rsc-router.js +284 -0
- package/dist/esm-node/router/runtime/utils.js +74 -1
- package/dist/esm-node/rsc/client.js +6 -0
- package/dist/esm-node/rsc/server.js +35 -0
- package/dist/types/cli/template.d.ts +4 -2
- package/dist/types/cli/template.server.d.ts +2 -1
- package/dist/types/common.d.ts +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/core/context/index.d.ts +38 -3
- package/dist/types/core/context/serverPayload.server.d.ts +3 -0
- package/dist/types/core/server/requestHandler.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/router/cli/code/index.d.ts +1 -0
- package/dist/types/router/cli/code/templates.d.ts +4 -2
- package/dist/types/router/index.d.ts +0 -2
- package/dist/types/router/internal.d.ts +2 -0
- package/dist/types/router/runtime/PrefetchLink.d.ts +0 -1
- package/dist/types/router/runtime/constants.d.ts +3 -3
- package/dist/types/router/runtime/index.d.ts +1 -9
- package/dist/types/router/runtime/internal.d.ts +8 -0
- package/dist/types/router/runtime/rsc-router.d.ts +14 -0
- package/dist/types/router/runtime/utils.d.ts +26 -5
- package/dist/types/rsc/client.d.ts +1 -0
- package/dist/types/rsc/server.d.ts +1 -0
- package/package.json +21 -12
- package/static/modern-inline.js +1 -1
|
@@ -43,11 +43,13 @@ async function handleModifyEntrypoints(isRouterV5, entrypoints) {
|
|
|
43
43
|
return (0, import_entry.modifyEntrypoints)(entrypoints, isRouterV5);
|
|
44
44
|
}
|
|
45
45
|
async function handleGeneratorEntryCode(api, entrypoints, isRouterV5) {
|
|
46
|
+
var _resolvedConfig_server;
|
|
46
47
|
const appContext = api.getAppContext();
|
|
47
48
|
const { internalDirectory } = appContext;
|
|
48
49
|
const resolvedConfig = api.getNormalizedConfig();
|
|
49
|
-
const { generatorRegisterCode, generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
|
|
50
|
+
const { generatorRegisterCode, generateCode, generatorServerRegisterCode } = await Promise.resolve().then(() => __toESM(require("./code")));
|
|
50
51
|
originEntrypoints = (0, import_lodash.cloneDeep)(entrypoints);
|
|
52
|
+
const enableRsc = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_server = resolvedConfig.server) === null || _resolvedConfig_server === void 0 ? void 0 : _resolvedConfig_server.rsc;
|
|
51
53
|
await generateCode(appContext, resolvedConfig, entrypoints, api, isRouterV5);
|
|
52
54
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
53
55
|
if (entrypoint.nestedRoutesEntry || entrypoint.pageRoutesEntry) {
|
|
@@ -58,8 +60,21 @@ async function handleGeneratorEntryCode(api, entrypoints, isRouterV5) {
|
|
|
58
60
|
srcDirectory: appContext.srcDirectory,
|
|
59
61
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
60
62
|
internalSrcAlias: appContext.internalSrcAlias,
|
|
61
|
-
globalApp: (_entrypoint_fileSystemRoutes = entrypoint.fileSystemRoutes) === null || _entrypoint_fileSystemRoutes === void 0 ? void 0 : _entrypoint_fileSystemRoutes.globalApp
|
|
63
|
+
globalApp: (_entrypoint_fileSystemRoutes = entrypoint.fileSystemRoutes) === null || _entrypoint_fileSystemRoutes === void 0 ? void 0 : _entrypoint_fileSystemRoutes.globalApp,
|
|
64
|
+
rscType: enableRsc ? "client" : void 0
|
|
62
65
|
}));
|
|
66
|
+
if (enableRsc) {
|
|
67
|
+
var _entrypoint_fileSystemRoutes1;
|
|
68
|
+
generatorServerRegisterCode(internalDirectory, entrypoint.entryName, await templates.runtimeGlobalContext({
|
|
69
|
+
entryName: entrypoint.entryName,
|
|
70
|
+
metaName: appContext.metaName,
|
|
71
|
+
srcDirectory: appContext.srcDirectory,
|
|
72
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
73
|
+
internalSrcAlias: appContext.internalSrcAlias,
|
|
74
|
+
globalApp: (_entrypoint_fileSystemRoutes1 = entrypoint.fileSystemRoutes) === null || _entrypoint_fileSystemRoutes1 === void 0 ? void 0 : _entrypoint_fileSystemRoutes1.globalApp,
|
|
75
|
+
rscType: "server"
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
63
78
|
}
|
|
64
79
|
}));
|
|
65
80
|
return entrypoints;
|
|
@@ -62,7 +62,7 @@ const routerPlugin = () => ({
|
|
|
62
62
|
if ((nestedRoutesEntry || pageRoutesEntry) && !isRouterV5) {
|
|
63
63
|
plugins.push({
|
|
64
64
|
name: "router",
|
|
65
|
-
path: `@${metaName2}/runtime/router`,
|
|
65
|
+
path: `@${metaName2}/runtime/router/internal`,
|
|
66
66
|
config: typeof routerConfig === "boolean" ? {
|
|
67
67
|
serverBase
|
|
68
68
|
} : {
|
|
@@ -89,9 +89,10 @@ const routerPlugin = () => ({
|
|
|
89
89
|
// react-router v6 is no longer support ie 11
|
|
90
90
|
// so we need to compile these packages to ensure the compatibility
|
|
91
91
|
// https://github.com/remix-run/react-router/commit/f6df0697e1b2064a2b3a12e8b39577326fdd945b
|
|
92
|
-
/node_modules
|
|
93
|
-
/node_modules
|
|
94
|
-
/node_modules
|
|
92
|
+
/[\\/]node_modules[\\/]react-router[\\/]/,
|
|
93
|
+
/[\\/]node_modules[\\/]react-router-dom[\\/]/,
|
|
94
|
+
/[\\/]node_modules[\\/]@remix-run[\\/]router[\\/]/,
|
|
95
|
+
import_node_path.default.resolve(__dirname, "../runtime").replace("cjs", "esm")
|
|
95
96
|
],
|
|
96
97
|
globalVars: {
|
|
97
98
|
"process.env._MODERN_ROUTER_VERSION": "v6"
|
|
@@ -112,7 +113,7 @@ const routerPlugin = () => ({
|
|
|
112
113
|
const { internalDirectory, metaName: metaName2 } = api.useAppContext();
|
|
113
114
|
const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
|
|
114
115
|
if (!isRouterV5) {
|
|
115
|
-
pluginsExportsUtils.addExport(`export { default as router } from '@${metaName2}/runtime/router'`);
|
|
116
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@${metaName2}/runtime/router/internal'`);
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
119
|
api.onFileChanged(async (e) => {
|
package/dist/cjs/router/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
6
|
var __copyProps = (to, from, except, desc) => {
|
|
13
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -18,26 +12,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
12
|
return to;
|
|
19
13
|
};
|
|
20
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
16
|
var router_exports = {};
|
|
31
|
-
__export(router_exports, {
|
|
32
|
-
default: () => import_runtime2.default,
|
|
33
|
-
router: () => import_runtime.default
|
|
34
|
-
});
|
|
35
17
|
module.exports = __toCommonJS(router_exports);
|
|
36
|
-
var import_runtime = __toESM(require("./runtime"));
|
|
37
|
-
var import_runtime2 = __toESM(require("./runtime"));
|
|
38
18
|
__reExport(router_exports, require("./runtime"), module.exports);
|
|
39
19
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
20
|
0 && (module.exports = {
|
|
41
|
-
router,
|
|
42
21
|
...require("./runtime")
|
|
43
22
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var internal_exports = {};
|
|
21
|
+
__export(internal_exports, {
|
|
22
|
+
default: () => import_internal.routerPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(internal_exports);
|
|
25
|
+
__reExport(internal_exports, require("./runtime/internal"), module.exports);
|
|
26
|
+
var import_internal = require("./runtime/internal");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./runtime/internal")
|
|
30
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -29,8 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
30
|
var PrefetchLink_exports = {};
|
|
30
31
|
__export(PrefetchLink_exports, {
|
|
31
32
|
Link: () => Link,
|
|
32
|
-
NavLink: () => NavLink
|
|
33
|
-
composeEventHandlers: () => composeEventHandlers
|
|
33
|
+
NavLink: () => NavLink
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(PrefetchLink_exports);
|
|
36
36
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -223,6 +223,5 @@ NavLink.displayName = "NavLink";
|
|
|
223
223
|
// Annotate the CommonJS export names for ESM import in node:
|
|
224
224
|
0 && (module.exports = {
|
|
225
225
|
Link,
|
|
226
|
-
NavLink
|
|
227
|
-
composeEventHandlers
|
|
226
|
+
NavLink
|
|
228
227
|
});
|
|
@@ -32,9 +32,9 @@ var import_constants = require("../../core/constants");
|
|
|
32
32
|
const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
|
|
33
33
|
const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
|
|
34
34
|
const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};`;
|
|
35
|
-
const mergeLoaderDataStr = `function mergeLoaderData(e,n){
|
|
35
|
+
const mergeLoaderDataStr = `function mergeLoaderData(e,n){var r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){var t=a.map((e=>{if("undefined"!==e&&null!==e)return JSON.parse(e)}));return console.info("args",t),{...e,[n]:_ROUTER_DATA[r](...t)}}),{});Object.assign(_ROUTER_DATA.loaderData[e],r)}`;
|
|
36
36
|
const initRouterDataAttrs = `_ROUTER_DATA.s = ${setupFnStr}_ROUTER_DATA.r = ${resolveFnStr}_ROUTER_DATA.p = ${preResolvedFnStr}${mergeLoaderDataStr}`;
|
|
37
|
-
const modernInline = `function runWindowFn(){window[document.currentScript.getAttribute("data-fn-name")](
|
|
37
|
+
const modernInline = `function runWindowFn(){window[document.currentScript.getAttribute("data-fn-name")].apply(window,JSON.parse(document.currentScript.getAttribute("data-fn-args")))}function runRouterDataFn(){_ROUTER_DATA[document.currentScript.getAttribute("data-fn-name")].apply(_ROUTER_DATA,JSON.parse(document.currentScript.getAttribute("data-fn-args")))}function initRouterData(e){var r=document.getElementById(e);if(r)try{_ROUTER_DATA=JSON.parse(r.textContent)}catch(r){console.error("parse ".concat(e," error"),t),_ROUTER_DATA={}}};initRouterData('${import_constants.ROUTER_DATA_JSON_ID}');${initRouterDataAttrs}`;
|
|
38
38
|
const runRouterDataFnStr = `runRouterDataFn();`;
|
|
39
39
|
const runWindowFnStr = `runWindowFn();`;
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -22,24 +22,16 @@ __export(runtime_exports, {
|
|
|
22
22
|
Link: () => import_PrefetchLink.Link,
|
|
23
23
|
NavLink: () => import_PrefetchLink.NavLink,
|
|
24
24
|
createShouldRevalidate: () => import_routeModule.createShouldRevalidate,
|
|
25
|
-
default: () => runtime_default,
|
|
26
25
|
handleRouteModule: () => import_routeModule.handleRouteModule,
|
|
27
26
|
handleRouteModuleError: () => import_routeModule.handleRouteModuleError,
|
|
28
|
-
modifyRoutes: () => import_plugin2.modifyRoutes,
|
|
29
|
-
renderRoutes: () => import_utils.renderRoutes,
|
|
30
|
-
routerPlugin: () => import_plugin.routerPlugin,
|
|
31
27
|
useRouteLoaderData: () => useRouteLoaderData
|
|
32
28
|
});
|
|
33
29
|
module.exports = __toCommonJS(runtime_exports);
|
|
34
30
|
var import_router = require("@modern-js/runtime-utils/router");
|
|
35
|
-
var import_plugin = require("./plugin");
|
|
36
31
|
__reExport(runtime_exports, require("@modern-js/runtime-utils/router"), module.exports);
|
|
37
|
-
var import_utils = require("./utils");
|
|
38
|
-
var import_plugin2 = require("./plugin");
|
|
39
|
-
__reExport(runtime_exports, require("./withRouter"), module.exports);
|
|
40
32
|
var import_PrefetchLink = require("./PrefetchLink");
|
|
41
33
|
var import_routeModule = require("./routeModule");
|
|
42
|
-
|
|
34
|
+
__reExport(runtime_exports, require("./withRouter"), module.exports);
|
|
43
35
|
const useRouteLoaderData = (routeId) => {
|
|
44
36
|
const realRouteId = routeId.replace(/\[(.*?)\]/g, "($1)");
|
|
45
37
|
return (0, import_router.useRouteLoaderData)(realRouteId);
|
|
@@ -51,9 +43,6 @@ const useRouteLoaderData = (routeId) => {
|
|
|
51
43
|
createShouldRevalidate,
|
|
52
44
|
handleRouteModule,
|
|
53
45
|
handleRouteModuleError,
|
|
54
|
-
modifyRoutes,
|
|
55
|
-
renderRoutes,
|
|
56
|
-
routerPlugin,
|
|
57
46
|
useRouteLoaderData,
|
|
58
47
|
...require("@modern-js/runtime-utils/router"),
|
|
59
48
|
...require("./withRouter")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var internal_exports = {};
|
|
20
|
+
__export(internal_exports, {
|
|
21
|
+
default: () => internal_default,
|
|
22
|
+
modifyRoutes: () => import_plugin2.modifyRoutes,
|
|
23
|
+
renderRoutes: () => import_utils.renderRoutes,
|
|
24
|
+
routerPlugin: () => import_plugin.routerPlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(internal_exports);
|
|
27
|
+
var import_plugin = require("./plugin");
|
|
28
|
+
var import_utils = require("./utils");
|
|
29
|
+
var import_plugin2 = require("./plugin");
|
|
30
|
+
var internal_default = import_plugin.routerPlugin;
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
modifyRoutes,
|
|
34
|
+
renderRoutes,
|
|
35
|
+
routerPlugin
|
|
36
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var plugin_exports = {};
|
|
20
30
|
__export(plugin_exports, {
|
|
@@ -28,10 +38,13 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
28
38
|
var import_merge = require("@modern-js/runtime-utils/merge");
|
|
29
39
|
var import_router = require("@modern-js/runtime-utils/router");
|
|
30
40
|
var import_url = require("@modern-js/runtime-utils/url");
|
|
41
|
+
var React = __toESM(require("react"));
|
|
31
42
|
var import_react = require("react");
|
|
32
43
|
var import_core = require("../../core");
|
|
33
44
|
var import_context = require("../../core/context");
|
|
45
|
+
var import_context2 = require("../../core/context");
|
|
34
46
|
var import_hooks = require("./hooks");
|
|
47
|
+
var import_rsc_router = require("./rsc-router");
|
|
35
48
|
var import_utils = require("./utils");
|
|
36
49
|
let finalRouteConfig = {
|
|
37
50
|
routes: []
|
|
@@ -54,7 +67,9 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
54
67
|
onBeforeCreateRoutes: import_hooks.onBeforeCreateRoutes
|
|
55
68
|
},
|
|
56
69
|
setup: (api) => {
|
|
57
|
-
|
|
70
|
+
const routesContainer = {
|
|
71
|
+
current: []
|
|
72
|
+
};
|
|
58
73
|
api.onBeforeRender((context) => {
|
|
59
74
|
if (window._SSR_DATA && userConfig.unstable_reloadOnURLMismatch) {
|
|
60
75
|
var _ssrContext_request;
|
|
@@ -74,15 +89,14 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
74
89
|
};
|
|
75
90
|
Object.defineProperty(context, "routes", {
|
|
76
91
|
get() {
|
|
77
|
-
return
|
|
92
|
+
return routesContainer.current;
|
|
78
93
|
},
|
|
79
94
|
enumerable: true
|
|
80
95
|
});
|
|
81
96
|
});
|
|
82
97
|
api.wrapRoot((App) => {
|
|
83
|
-
const
|
|
84
|
-
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes, future } =
|
|
85
|
-
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
98
|
+
const mergedConfig = (0, import_merge.merge)(api.getRuntimeConfig().router || {}, userConfig);
|
|
99
|
+
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes, future } = mergedConfig;
|
|
86
100
|
finalRouteConfig = {
|
|
87
101
|
routes: (0, import_context.getGlobalRoutes)(),
|
|
88
102
|
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
@@ -91,82 +105,126 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
91
105
|
if (!finalRouteConfig.routes && !createRoutes) {
|
|
92
106
|
return App;
|
|
93
107
|
}
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
return listener(...args);
|
|
129
|
-
};
|
|
130
|
-
return originSubscribe(wrapedListener);
|
|
131
|
-
};
|
|
132
|
-
return router;
|
|
133
|
-
}, [
|
|
134
|
-
finalRouteConfig,
|
|
135
|
-
props,
|
|
136
|
-
_basename,
|
|
137
|
-
hydrationData,
|
|
138
|
-
getBlockNavState
|
|
139
|
-
]);
|
|
140
|
-
};
|
|
141
|
-
const Null = () => null;
|
|
142
|
-
return (props) => {
|
|
143
|
-
beforeCreateRouter = false;
|
|
144
|
-
const router = useCreateRouter(props);
|
|
145
|
-
const routerWrapper = (
|
|
146
|
-
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
147
|
-
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
148
|
-
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
149
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
150
|
-
children: [
|
|
151
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_router.RouterProvider, {
|
|
152
|
-
router,
|
|
153
|
-
future
|
|
154
|
-
}),
|
|
155
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Null, {}),
|
|
156
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Null, {})
|
|
157
|
-
]
|
|
158
|
-
})
|
|
159
|
-
);
|
|
160
|
-
return App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
161
|
-
children: routerWrapper
|
|
162
|
-
}) : routerWrapper;
|
|
163
|
-
};
|
|
108
|
+
const selectBasePath = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
109
|
+
const RouterWrapper = (props) => {
|
|
110
|
+
const { router, routes } = useRouterCreation({
|
|
111
|
+
...props,
|
|
112
|
+
rscPayload: props === null || props === void 0 ? void 0 : props.rscPayload
|
|
113
|
+
}, {
|
|
114
|
+
api,
|
|
115
|
+
createRoutes,
|
|
116
|
+
supportHtml5History,
|
|
117
|
+
selectBasePath,
|
|
118
|
+
basename,
|
|
119
|
+
future
|
|
120
|
+
});
|
|
121
|
+
(0, import_react.useEffect)(() => {
|
|
122
|
+
routesContainer.current = routes;
|
|
123
|
+
}, [
|
|
124
|
+
routes
|
|
125
|
+
]);
|
|
126
|
+
beforeCreateRouter = false;
|
|
127
|
+
const RouterContent = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
128
|
+
children: [
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_router.RouterProvider, {
|
|
130
|
+
router,
|
|
131
|
+
future
|
|
132
|
+
}),
|
|
133
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyComponent, {}),
|
|
134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyComponent, {})
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
return App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
138
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterContent, {})
|
|
139
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterContent, {});
|
|
164
140
|
};
|
|
165
|
-
return
|
|
141
|
+
return RouterWrapper;
|
|
166
142
|
});
|
|
167
143
|
}
|
|
168
144
|
};
|
|
169
145
|
};
|
|
146
|
+
const EmptyComponent = () => null;
|
|
147
|
+
const safeUse = (promise) => {
|
|
148
|
+
const useProp = "use";
|
|
149
|
+
const useHook = React && React[useProp];
|
|
150
|
+
if (typeof useHook === "function") {
|
|
151
|
+
return useHook(promise);
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
};
|
|
155
|
+
function useRouterCreation(props, options) {
|
|
156
|
+
const { api, createRoutes, supportHtml5History, selectBasePath, basename } = options;
|
|
157
|
+
const runtimeContext = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
158
|
+
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, "/");
|
|
159
|
+
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
|
|
160
|
+
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
161
|
+
const rscPayload = (props === null || props === void 0 ? void 0 : props.rscPayload) ? safeUse(props.rscPayload) : null;
|
|
162
|
+
let hydrationData = window._ROUTER_DATA || rscPayload;
|
|
163
|
+
return (0, import_react.useMemo)(() => {
|
|
164
|
+
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
165
|
+
hydrationData = {
|
|
166
|
+
...hydrationData,
|
|
167
|
+
errors: (0, import_utils.deserializeErrors)(hydrationData.errors)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const isRscClient = (0, import_context2.getGlobalIsRscClient)();
|
|
171
|
+
let routes = null;
|
|
172
|
+
if (isRscClient) {
|
|
173
|
+
routes = createRoutes ? createRoutes() : (0, import_utils.createRouteObjectsFromConfig)({
|
|
174
|
+
routesConfig: finalRouteConfig
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
routes = createRoutes ? createRoutes() : (0, import_router.createRoutesFromElements)((0, import_utils.renderRoutes)({
|
|
178
|
+
routesConfig: finalRouteConfig,
|
|
179
|
+
props
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
if (!routes) {
|
|
183
|
+
routes = [];
|
|
184
|
+
}
|
|
185
|
+
const hooks = api.getHooks();
|
|
186
|
+
if (rscPayload) {
|
|
187
|
+
try {
|
|
188
|
+
const router2 = (0, import_rsc_router.createClientRouterFromPayload)(rscPayload, routes, _basename);
|
|
189
|
+
return {
|
|
190
|
+
router: router2,
|
|
191
|
+
routes: router2.routes || []
|
|
192
|
+
};
|
|
193
|
+
} catch (e) {
|
|
194
|
+
console.error("Failed to create router from RSC payload:", e);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const modifiedRoutes = hooks.modifyRoutes.call(routes);
|
|
198
|
+
const router = supportHtml5History ? (0, import_router.createBrowserRouter)(modifiedRoutes, {
|
|
199
|
+
basename: _basename,
|
|
200
|
+
hydrationData
|
|
201
|
+
}) : (0, import_router.createHashRouter)(modifiedRoutes, {
|
|
202
|
+
basename: _basename,
|
|
203
|
+
hydrationData
|
|
204
|
+
});
|
|
205
|
+
const originSubscribe = router.subscribe;
|
|
206
|
+
router.subscribe = (listener) => {
|
|
207
|
+
const wrappedListener = (...args) => {
|
|
208
|
+
const blockRoute = getBlockNavState ? getBlockNavState() : false;
|
|
209
|
+
if (blockRoute) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
return listener(...args);
|
|
213
|
+
};
|
|
214
|
+
return originSubscribe(wrappedListener);
|
|
215
|
+
};
|
|
216
|
+
return {
|
|
217
|
+
router,
|
|
218
|
+
routes: modifiedRoutes
|
|
219
|
+
};
|
|
220
|
+
}, [
|
|
221
|
+
finalRouteConfig,
|
|
222
|
+
props,
|
|
223
|
+
_basename,
|
|
224
|
+
hydrationData,
|
|
225
|
+
getBlockNavState
|
|
226
|
+
]);
|
|
227
|
+
}
|
|
170
228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
171
229
|
0 && (module.exports = {
|
|
172
230
|
beforeCreateRouter,
|