@modern-js/runtime 2.55.0 → 2.56.1
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/index.js +2 -3
- package/dist/cjs/cli/ssr/index.js +30 -14
- package/dist/cjs/core/browser/index.js +21 -1
- package/dist/cjs/core/plugin/index.js +2 -2
- package/dist/cjs/core/server/stream/createReadableStream.js +3 -3
- package/dist/cjs/core/server/string/index.js +2 -2
- package/dist/cjs/core/server/string/loadable.js +1 -1
- package/dist/cjs/core/server/string/prefetch.js +3 -3
- package/dist/cjs/core/utils/merge.js +53 -0
- package/dist/cjs/router/cli/code/index.js +2 -2
- package/dist/cjs/router/cli/entry.js +16 -15
- package/dist/cjs/router/runtime/PrefetchLink.js +1 -1
- package/dist/cjs/router/runtime/plugin.node.js +10 -17
- package/dist/esm/cli/index.js +1 -2
- package/dist/esm/cli/ssr/index.js +33 -16
- package/dist/esm/core/browser/index.js +19 -1
- package/dist/esm/core/plugin/index.js +1 -1
- package/dist/esm/core/server/stream/createReadableStream.js +99 -78
- package/dist/esm/core/server/string/index.js +3 -3
- package/dist/esm/core/server/string/loadable.js +1 -1
- package/dist/esm/core/server/string/prefetch.js +5 -5
- package/dist/esm/core/utils/merge.js +32 -0
- package/dist/esm/router/cli/code/index.js +3 -3
- package/dist/esm/router/cli/entry.js +19 -17
- package/dist/esm/router/runtime/PrefetchLink.js +1 -1
- package/dist/esm/router/runtime/plugin.node.js +10 -51
- package/dist/esm-node/cli/index.js +1 -2
- package/dist/esm-node/cli/ssr/index.js +30 -14
- package/dist/esm-node/core/browser/index.js +21 -1
- package/dist/esm-node/core/plugin/index.js +1 -1
- package/dist/esm-node/core/server/stream/createReadableStream.js +2 -2
- package/dist/esm-node/core/server/string/index.js +2 -2
- package/dist/esm-node/core/server/string/loadable.js +1 -1
- package/dist/esm-node/core/server/string/prefetch.js +3 -3
- package/dist/esm-node/core/utils/merge.js +29 -0
- package/dist/esm-node/router/cli/code/index.js +2 -2
- package/dist/esm-node/router/cli/entry.js +16 -15
- package/dist/esm-node/router/runtime/PrefetchLink.js +1 -1
- package/dist/esm-node/router/runtime/plugin.node.js +10 -16
- package/dist/types/core/browser/index.d.ts +1 -0
- package/dist/types/core/plugin/index.d.ts +1 -1
- package/dist/types/core/server/string/prefetch.d.ts +2 -1
- package/dist/types/core/utils/merge.d.ts +6 -0
- package/dist/types/router/runtime/plugin.node.d.ts +0 -2
- package/package.json +14 -15
package/dist/cjs/cli/index.js
CHANGED
|
@@ -39,7 +39,6 @@ __export(cli_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(cli_exports);
|
|
40
40
|
var import_path = __toESM(require("path"));
|
|
41
41
|
var import_utils = require("@modern-js/utils");
|
|
42
|
-
var import_core = require("@rsbuild/core");
|
|
43
42
|
var import_cli = require("../state/cli");
|
|
44
43
|
var import_cli2 = require("../router/cli");
|
|
45
44
|
var import_cli3 = require("../document/cli");
|
|
@@ -151,10 +150,10 @@ const runtimePlugin = (params) => ({
|
|
|
151
150
|
]);
|
|
152
151
|
}
|
|
153
152
|
},
|
|
154
|
-
rspack: (_config, { appendPlugins }) => {
|
|
153
|
+
rspack: (_config, { appendPlugins, rspack }) => {
|
|
155
154
|
if (!isReact18) {
|
|
156
155
|
appendPlugins([
|
|
157
|
-
new
|
|
156
|
+
new rspack.IgnorePlugin({
|
|
158
157
|
resourceRegExp: /^react-dom\/client$/,
|
|
159
158
|
contextRegExp: /./
|
|
160
159
|
})
|
|
@@ -53,6 +53,33 @@ const checkUseStringSSR = (config) => {
|
|
|
53
53
|
const { output } = config;
|
|
54
54
|
return Boolean(output === null || output === void 0 ? void 0 : output.ssg) || hasStringSSREntry(config);
|
|
55
55
|
};
|
|
56
|
+
const ssrBuilderPlugin = (modernAPI) => ({
|
|
57
|
+
name: "@modern-js/builder-plugin-ssr",
|
|
58
|
+
setup(api) {
|
|
59
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => {
|
|
60
|
+
const isServerEnvironment = config.output.target === "node" || name === "serviceWorker";
|
|
61
|
+
const userConfig = modernAPI.useResolvedConfigContext();
|
|
62
|
+
const useLoadablePlugin = (0, import_utils.isUseSSRBundle)(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
63
|
+
return mergeEnvironmentConfig(config, {
|
|
64
|
+
source: {
|
|
65
|
+
define: {
|
|
66
|
+
"process.env.MODERN_TARGET": isServerEnvironment ? JSON.stringify("node") : JSON.stringify("browser")
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
tools: {
|
|
70
|
+
bundlerChain: useLoadablePlugin ? (chain) => {
|
|
71
|
+
const LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
72
|
+
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
73
|
+
{
|
|
74
|
+
filename: import_utils.LOADABLE_STATS_FILE
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
} : void 0
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
56
83
|
const ssrPlugin = () => ({
|
|
57
84
|
name: "@modern-js/plugin-ssr",
|
|
58
85
|
required: [
|
|
@@ -86,27 +113,16 @@ const ssrPlugin = () => ({
|
|
|
86
113
|
}
|
|
87
114
|
})();
|
|
88
115
|
return {
|
|
116
|
+
builderPlugins: [
|
|
117
|
+
ssrBuilderPlugin(api)
|
|
118
|
+
],
|
|
89
119
|
source: {
|
|
90
120
|
alias: {
|
|
91
121
|
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
92
122
|
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
|
|
93
|
-
},
|
|
94
|
-
globalVars: (values, { target }) => {
|
|
95
|
-
values["process.env.MODERN_TARGET"] = target === "node" || target === "service-worker" ? "node" : "browser";
|
|
96
123
|
}
|
|
97
124
|
},
|
|
98
125
|
tools: {
|
|
99
|
-
bundlerChain(chain, { isServer, isServiceWorker }) {
|
|
100
|
-
const userConfig = api.useResolvedConfigContext();
|
|
101
|
-
if ((0, import_utils.isUseSSRBundle)(userConfig) && !isServer && !isServiceWorker && checkUseStringSSR(userConfig)) {
|
|
102
|
-
const LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
103
|
-
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
104
|
-
{
|
|
105
|
-
filename: import_utils.LOADABLE_STATS_FILE
|
|
106
|
-
}
|
|
107
|
-
]);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
126
|
babel: babelHandler
|
|
111
127
|
}
|
|
112
128
|
};
|
|
@@ -32,12 +32,32 @@ __export(browser_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(browser_exports);
|
|
34
34
|
var import_react = __toESM(require("react"));
|
|
35
|
+
var import_cookie = __toESM(require("cookie"));
|
|
35
36
|
var import_context = require("../context");
|
|
36
37
|
var import_runtime = require("../context/runtime");
|
|
37
38
|
var import_loaderManager = require("../loader/loaderManager");
|
|
38
39
|
var import_runner = require("../plugin/runner");
|
|
39
40
|
var import_hydrate = require("./hydrate");
|
|
40
41
|
const IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
42
|
+
function getSSRData() {
|
|
43
|
+
const ssrData = window._SSR_DATA;
|
|
44
|
+
if (ssrData) {
|
|
45
|
+
const finalSSRData = {
|
|
46
|
+
...ssrData,
|
|
47
|
+
context: {
|
|
48
|
+
...ssrData.context,
|
|
49
|
+
request: {
|
|
50
|
+
...ssrData.context.request,
|
|
51
|
+
cookieMap: import_cookie.default.parse(document.cookie || "") || {},
|
|
52
|
+
cookie: document.cookie || "",
|
|
53
|
+
userAgent: navigator.userAgent,
|
|
54
|
+
referer: document.referrer
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return finalSSRData;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
41
61
|
function isClientArgs(id) {
|
|
42
62
|
return typeof id === "undefined" || typeof id === "string" || typeof HTMLElement !== "undefined" && id instanceof HTMLElement;
|
|
43
63
|
}
|
|
@@ -54,7 +74,7 @@ async function render(App, id) {
|
|
|
54
74
|
});
|
|
55
75
|
if (isClientArgs(id)) {
|
|
56
76
|
var _ssrData_data, _ssrData_data1;
|
|
57
|
-
const ssrData =
|
|
77
|
+
const ssrData = getSSRData();
|
|
58
78
|
const loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
59
79
|
const initialLoadersState = Object.keys(loadersData).reduce((res, key) => {
|
|
60
80
|
const loaderData = loadersData[key];
|
|
@@ -23,7 +23,7 @@ __export(plugin_exports, {
|
|
|
23
23
|
registerPlugin: () => registerPlugin
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(plugin_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_merge = require("../utils/merge");
|
|
27
27
|
var import_base = require("./base");
|
|
28
28
|
var import_runner = require("./runner");
|
|
29
29
|
__reExport(plugin_exports, require("./base"), module.exports);
|
|
@@ -35,7 +35,7 @@ function registerPlugin(internalPlugins, runtimeConfig, customRuntime) {
|
|
|
35
35
|
return runner;
|
|
36
36
|
}
|
|
37
37
|
function mergeConfig(config, ...otherConfig) {
|
|
38
|
-
return (0,
|
|
38
|
+
return (0, import_merge.merge)(config, ...otherConfig);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
41
|
0 && (module.exports = {
|
|
@@ -32,7 +32,6 @@ __export(createReadableStream_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(createReadableStream_exports);
|
|
34
34
|
var import_stream = require("stream");
|
|
35
|
-
var import_server = require("react-dom/server");
|
|
36
35
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
37
36
|
var import_styled_components = require("styled-components");
|
|
38
37
|
var import_isbot = __toESM(require("isbot"));
|
|
@@ -40,7 +39,8 @@ var import_common = require("../../../common");
|
|
|
40
39
|
var import_constants = require("../../constants");
|
|
41
40
|
var import_template = require("./template");
|
|
42
41
|
var import_shared = require("./shared");
|
|
43
|
-
const createReadableStreamFromElement = (request, rootElement, options) => {
|
|
42
|
+
const createReadableStreamFromElement = async (request, rootElement, options) => {
|
|
43
|
+
const { renderToPipeableStream } = await Promise.resolve().then(() => __toESM(require("react-dom/server")));
|
|
44
44
|
const { runtimeContext, htmlTemplate, config, ssrConfig } = options;
|
|
45
45
|
let shellChunkStatus = import_shared.ShellChunkStatus.START;
|
|
46
46
|
let renderLevel = import_constants.RenderLevel.SERVER_RENDER;
|
|
@@ -51,7 +51,7 @@ const createReadableStreamFromElement = (request, rootElement, options) => {
|
|
|
51
51
|
const chunkVec = [];
|
|
52
52
|
const root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
|
|
53
53
|
return new Promise((resolve) => {
|
|
54
|
-
const { pipe } =
|
|
54
|
+
const { pipe } = renderToPipeableStream(root, {
|
|
55
55
|
nonce: config.nonce,
|
|
56
56
|
[onReady]() {
|
|
57
57
|
var _options_onReady;
|
|
@@ -58,6 +58,7 @@ const renderString = async (request, serverRoot, options) => {
|
|
|
58
58
|
};
|
|
59
59
|
const routerContext = runtimeContext.routerContext;
|
|
60
60
|
const { htmlTemplate, entryName, loadableStats, routeManifest } = resource;
|
|
61
|
+
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries, staticGenerate);
|
|
61
62
|
const chunkSet = {
|
|
62
63
|
renderLevel: import_constants2.RenderLevel.CLIENT_RENDER,
|
|
63
64
|
ssrScripts: "",
|
|
@@ -66,12 +67,11 @@ const renderString = async (request, serverRoot, options) => {
|
|
|
66
67
|
};
|
|
67
68
|
let prefetchData = {};
|
|
68
69
|
try {
|
|
69
|
-
prefetchData = await (0, import_prefetch.prefetch)(serverRoot, request, options, tracer);
|
|
70
|
+
prefetchData = await (0, import_prefetch.prefetch)(serverRoot, request, options, ssrConfig, tracer);
|
|
70
71
|
chunkSet.renderLevel = import_constants2.RenderLevel.SERVER_PREFETCH;
|
|
71
72
|
} catch (e) {
|
|
72
73
|
chunkSet.renderLevel = import_constants2.RenderLevel.CLIENT_RENDER;
|
|
73
74
|
}
|
|
74
|
-
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries, staticGenerate);
|
|
75
75
|
const collectors = [
|
|
76
76
|
new import_styledComponent.StyledCollector(chunkSet),
|
|
77
77
|
new import_loadable.LoadableCollector({
|
|
@@ -144,7 +144,7 @@ class LoadableCollector {
|
|
|
144
144
|
return link;
|
|
145
145
|
}
|
|
146
146
|
}));
|
|
147
|
-
chunkSet.
|
|
147
|
+
chunkSet.cssChunk += css.filter((css2) => Boolean(css2)).join("");
|
|
148
148
|
}
|
|
149
149
|
generateAttributes(extraAtr = {}) {
|
|
150
150
|
const { config } = this.options;
|
|
@@ -38,13 +38,13 @@ var import_time = require("@modern-js/runtime-utils/time");
|
|
|
38
38
|
var import_request = require("@modern-js/runtime-utils/universal/request");
|
|
39
39
|
var import_react = __toESM(require("react"));
|
|
40
40
|
var import_tracer = require("../tracer");
|
|
41
|
-
const prefetch = async (App, request, options, { onError, onTiming }) => {
|
|
41
|
+
const prefetch = async (App, request, options, ssrConfig, { onError, onTiming }) => {
|
|
42
42
|
const headersData = (0, import_request.parseHeaders)(request);
|
|
43
|
-
const { runtimeContext: context, resource
|
|
43
|
+
const { runtimeContext: context, resource } = options;
|
|
44
44
|
const { entryName, loadableStats } = resource;
|
|
45
45
|
return (0, import_node.run)(headersData, async () => {
|
|
46
46
|
var _context_store;
|
|
47
|
-
if (!
|
|
47
|
+
if (typeof ssrConfig === "boolean" || !ssrConfig.disablePrerender) {
|
|
48
48
|
try {
|
|
49
49
|
const end = (0, import_time.time)();
|
|
50
50
|
if (loadableStats) {
|
|
@@ -0,0 +1,53 @@
|
|
|
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 merge_exports = {};
|
|
20
|
+
__export(merge_exports, {
|
|
21
|
+
merge: () => merge
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(merge_exports);
|
|
24
|
+
function isObject(obj) {
|
|
25
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
26
|
+
}
|
|
27
|
+
function merge(target, ...sources) {
|
|
28
|
+
if (!sources.length) {
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
const source = sources.shift();
|
|
32
|
+
if (isObject(target) && isObject(source)) {
|
|
33
|
+
for (const key in source) {
|
|
34
|
+
if (isObject(source[key])) {
|
|
35
|
+
if (!target[key]) {
|
|
36
|
+
Object.assign(target, {
|
|
37
|
+
[key]: {}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
merge(target[key], source[key]);
|
|
41
|
+
} else {
|
|
42
|
+
Object.assign(target, {
|
|
43
|
+
[key]: source[key]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return merge(target, ...sources);
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
merge
|
|
53
|
+
});
|
|
@@ -48,10 +48,10 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
48
48
|
const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
|
49
49
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
50
50
|
async function generateEntryCode(entrypoint) {
|
|
51
|
-
const { entryName, isMainEntry, isAutoMount,
|
|
51
|
+
const { entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry } = entrypoint;
|
|
52
52
|
const { metaName } = api.useAppContext();
|
|
53
53
|
if (isAutoMount) {
|
|
54
|
-
if (
|
|
54
|
+
if (pageRoutesEntry || nestedRoutesEntry) {
|
|
55
55
|
var _config_output;
|
|
56
56
|
let initialRoutes = [];
|
|
57
57
|
let nestedRoutes = null;
|
|
@@ -54,29 +54,30 @@ const modifyEntrypoints = (entrypoints, config = {}) => {
|
|
|
54
54
|
if (!entrypoint.isAutoMount) {
|
|
55
55
|
return entrypoint;
|
|
56
56
|
}
|
|
57
|
+
if (entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.isCustomSourceEntry) {
|
|
58
|
+
if (entrypoint.fileSystemRoutes) {
|
|
59
|
+
if ((0, import_utils.isRouterV5)(config)) {
|
|
60
|
+
throw Error("Custom entries with conventional routing not support use react router v5!");
|
|
61
|
+
}
|
|
62
|
+
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
63
|
+
}
|
|
64
|
+
return entrypoint;
|
|
65
|
+
}
|
|
57
66
|
const isHasApp = (0, import_entry.hasApp)(entrypoint.absoluteEntryDir);
|
|
58
67
|
if (isHasApp) {
|
|
59
68
|
return entrypoint;
|
|
60
69
|
}
|
|
61
|
-
const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir);
|
|
62
70
|
const isHasPages = hasPages(entrypoint.absoluteEntryDir);
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
if (entrypoint.fileSystemRoutes && !(0, import_utils.isRouterV5)(config)) {
|
|
67
|
-
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
68
|
-
} else if (!entrypoint.fileSystemRoutes) {
|
|
71
|
+
if (isHasPages) {
|
|
72
|
+
entrypoint.pageRoutesEntry = import_path.default.join(entrypoint.absoluteEntryDir, import_constants.PAGES_DIR_NAME);
|
|
69
73
|
entrypoint.fileSystemRoutes = {
|
|
74
|
+
...entrypoint.fileSystemRoutes,
|
|
70
75
|
globalApp: (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(entrypoint.absoluteEntryDir, `./${import_constants.PAGES_DIR_NAME}/${import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
|
|
71
76
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
entrypoint.nestedRoutesEntry = import_path.default.join(entrypoint.absoluteEntryDir, import_constants.NESTED_ROUTES_DIR);
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
throw Error("Custom entries with conventional routing not support use react router v5!");
|
|
77
|
+
}
|
|
78
|
+
const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir);
|
|
79
|
+
if (isHasNestedRoutes) {
|
|
80
|
+
entrypoint.nestedRoutesEntry = import_path.default.join(entrypoint.absoluteEntryDir, import_constants.NESTED_ROUTES_DIR);
|
|
80
81
|
}
|
|
81
82
|
return entrypoint;
|
|
82
83
|
});
|
|
@@ -105,7 +105,7 @@ async function loadRouteModule(route, routeAssets) {
|
|
|
105
105
|
}
|
|
106
106
|
try {
|
|
107
107
|
await Promise.all(chunkIds.map((chunkId) => {
|
|
108
|
-
return __webpack_chunk_load__ === null || __webpack_chunk_load__ === void 0 ? void 0 : __webpack_chunk_load__(
|
|
108
|
+
return __webpack_chunk_load__ === null || __webpack_chunk_load__ === void 0 ? void 0 : __webpack_chunk_load__(chunkId);
|
|
109
109
|
}));
|
|
110
110
|
} catch (error) {
|
|
111
111
|
console.error(error);
|
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var plugin_node_exports = {};
|
|
30
30
|
__export(plugin_node_exports, {
|
|
31
|
-
createFetchHeaders: () => createFetchHeaders,
|
|
32
31
|
modifyRoutes: () => modifyRoutes,
|
|
33
32
|
routerPlugin: () => routerPlugin
|
|
34
33
|
});
|
|
@@ -47,20 +46,15 @@ var import_context = require("../../core/context");
|
|
|
47
46
|
var import_utils = require("./utils");
|
|
48
47
|
var import_hooks = require("./hooks");
|
|
49
48
|
var import_DeferredDataScripts = __toESM(require("./DeferredDataScripts.node"));
|
|
50
|
-
function
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
headers.set(key, values);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return headers;
|
|
49
|
+
function createRemixReuqest(request) {
|
|
50
|
+
const method = "GET";
|
|
51
|
+
const { headers } = request;
|
|
52
|
+
const controller = new AbortController();
|
|
53
|
+
return new Request(request.url, {
|
|
54
|
+
method,
|
|
55
|
+
headers,
|
|
56
|
+
signal: controller.signal
|
|
57
|
+
});
|
|
64
58
|
}
|
|
65
59
|
const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
66
60
|
return {
|
|
@@ -101,7 +95,7 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
101
95
|
const { query } = (0, import_remix_router.createStaticHandler)(routes, {
|
|
102
96
|
basename: _basename
|
|
103
97
|
});
|
|
104
|
-
const remixRequest = context.ssrContext.request.raw;
|
|
98
|
+
const remixRequest = createRemixReuqest(context.ssrContext.request.raw);
|
|
105
99
|
const end = (0, import_time.time)();
|
|
106
100
|
const routerContext = await query(remixRequest, {
|
|
107
101
|
requestContext
|
|
@@ -186,7 +180,6 @@ const modifyRoutes = () => {
|
|
|
186
180
|
};
|
|
187
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
188
182
|
0 && (module.exports = {
|
|
189
|
-
createFetchHeaders,
|
|
190
183
|
modifyRoutes,
|
|
191
184
|
routerPlugin
|
|
192
185
|
});
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { isReact18 as checkIsReact18, cleanRequireCache, createRuntimeExportsUtils } from "@modern-js/utils";
|
|
6
|
-
import { rspack } from "@rsbuild/core";
|
|
7
6
|
import { statePlugin } from "../state/cli";
|
|
8
7
|
import { routerPlugin } from "../router/cli";
|
|
9
8
|
import { documentPlugin } from "../document/cli";
|
|
@@ -138,7 +137,7 @@ var runtimePlugin = function(params) {
|
|
|
138
137
|
}
|
|
139
138
|
},
|
|
140
139
|
rspack: function(_config, param) {
|
|
141
|
-
var appendPlugins = param.appendPlugins;
|
|
140
|
+
var appendPlugins = param.appendPlugins, rspack = param.rspack;
|
|
142
141
|
if (!isReact18) {
|
|
143
142
|
appendPlugins([
|
|
144
143
|
new rspack.IgnorePlugin({
|
|
@@ -38,6 +38,36 @@ var checkUseStringSSR = function(config) {
|
|
|
38
38
|
var output = config.output;
|
|
39
39
|
return Boolean(output === null || output === void 0 ? void 0 : output.ssg) || hasStringSSREntry(config);
|
|
40
40
|
};
|
|
41
|
+
var ssrBuilderPlugin = function(modernAPI) {
|
|
42
|
+
return {
|
|
43
|
+
name: "@modern-js/builder-plugin-ssr",
|
|
44
|
+
setup: function setup(api) {
|
|
45
|
+
api.modifyEnvironmentConfig(function(config, param) {
|
|
46
|
+
var name = param.name, mergeEnvironmentConfig = param.mergeEnvironmentConfig;
|
|
47
|
+
var isServerEnvironment = config.output.target === "node" || name === "serviceWorker";
|
|
48
|
+
var userConfig = modernAPI.useResolvedConfigContext();
|
|
49
|
+
var useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
50
|
+
return mergeEnvironmentConfig(config, {
|
|
51
|
+
source: {
|
|
52
|
+
define: {
|
|
53
|
+
"process.env.MODERN_TARGET": isServerEnvironment ? JSON.stringify("node") : JSON.stringify("browser")
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
tools: {
|
|
57
|
+
bundlerChain: useLoadablePlugin ? function(chain) {
|
|
58
|
+
var LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
59
|
+
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
60
|
+
{
|
|
61
|
+
filename: LOADABLE_STATS_FILE
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
64
|
+
} : void 0
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
41
71
|
var ssrPlugin = function() {
|
|
42
72
|
return {
|
|
43
73
|
name: "@modern-js/plugin-ssr",
|
|
@@ -72,29 +102,16 @@ var ssrPlugin = function() {
|
|
|
72
102
|
}
|
|
73
103
|
}();
|
|
74
104
|
return {
|
|
105
|
+
builderPlugins: [
|
|
106
|
+
ssrBuilderPlugin(api)
|
|
107
|
+
],
|
|
75
108
|
source: {
|
|
76
109
|
alias: {
|
|
77
110
|
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
78
111
|
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
|
|
79
|
-
},
|
|
80
|
-
globalVars: function(values, param) {
|
|
81
|
-
var target = param.target;
|
|
82
|
-
values["process.env.MODERN_TARGET"] = target === "node" || target === "service-worker" ? "node" : "browser";
|
|
83
112
|
}
|
|
84
113
|
},
|
|
85
114
|
tools: {
|
|
86
|
-
bundlerChain: function bundlerChain(chain, param) {
|
|
87
|
-
var isServer = param.isServer, isServiceWorker = param.isServiceWorker;
|
|
88
|
-
var userConfig = api.useResolvedConfigContext();
|
|
89
|
-
if (isUseSSRBundle(userConfig) && !isServer && !isServiceWorker && checkUseStringSSR(userConfig)) {
|
|
90
|
-
var LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
91
|
-
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
92
|
-
{
|
|
93
|
-
filename: LOADABLE_STATS_FILE
|
|
94
|
-
}
|
|
95
|
-
]);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
115
|
babel: babelHandler
|
|
99
116
|
}
|
|
100
117
|
};
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
6
|
import React from "react";
|
|
7
|
+
import cookieTool from "cookie";
|
|
6
8
|
import { getGlobalAppInit } from "../context";
|
|
7
9
|
import { getInitialContext } from "../context/runtime";
|
|
8
10
|
import { createLoaderManager } from "../loader/loaderManager";
|
|
9
11
|
import { getGlobalRunner } from "../plugin/runner";
|
|
10
12
|
import { hydrateRoot } from "./hydrate";
|
|
11
13
|
var IS_REACT18 = process.env.IS_REACT18 === "true";
|
|
14
|
+
function getSSRData() {
|
|
15
|
+
var ssrData = window._SSR_DATA;
|
|
16
|
+
if (ssrData) {
|
|
17
|
+
var finalSSRData = _object_spread_props(_object_spread({}, ssrData), {
|
|
18
|
+
context: _object_spread_props(_object_spread({}, ssrData.context), {
|
|
19
|
+
request: _object_spread_props(_object_spread({}, ssrData.context.request), {
|
|
20
|
+
cookieMap: cookieTool.parse(document.cookie || "") || {},
|
|
21
|
+
cookie: document.cookie || "",
|
|
22
|
+
userAgent: navigator.userAgent,
|
|
23
|
+
referer: document.referrer
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
return finalSSRData;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
12
30
|
function isClientArgs(id) {
|
|
13
31
|
return typeof id === "undefined" || typeof id === "string" || typeof HTMLElement !== "undefined" && _instanceof(id, HTMLElement);
|
|
14
32
|
}
|
|
@@ -73,7 +91,7 @@ function _render() {
|
|
|
73
91
|
ModernHydrate = function ModernHydrate2(App2, callback) {
|
|
74
92
|
return _ModernHydrate.apply(this, arguments);
|
|
75
93
|
};
|
|
76
|
-
ssrData =
|
|
94
|
+
ssrData = getSSRData();
|
|
77
95
|
loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
78
96
|
initialLoadersState = Object.keys(loadersData).reduce(function(res, key) {
|
|
79
97
|
var loaderData = loadersData[key];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
import { merge } from "
|
|
2
|
+
import { merge } from "../utils/merge";
|
|
3
3
|
import { runtime } from "./base";
|
|
4
4
|
import { setGlobalRunner } from "./runner";
|
|
5
5
|
export * from "./base";
|