@modern-js/runtime 2.17.1 → 2.18.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/CHANGELOG.md +23 -0
- package/README.md +6 -0
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +6 -6
- package/dist/cjs/router/runtime/index.js +5 -5
- package/dist/cjs/router/runtime/plugin.js +2 -2
- package/dist/cjs/router/runtime/plugin.node.js +2 -2
- package/dist/cjs/router/runtime/utils.js +4 -5
- package/dist/cjs/ssr/cli/index.js +30 -15
- package/dist/cjs/ssr/cli/loadable-bundler-plugin.js +112 -0
- package/dist/cjs/ssr/index.js +3 -3
- package/dist/cjs/ssr/prefetch.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToStream/index.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +3 -3
- package/dist/cjs/ssr/serverRender/renderToString/index.js +2 -2
- package/dist/esm/core/compatible.js +13 -13
- package/dist/esm/core/loader/loaderManager.js +7 -7
- package/dist/esm/core/loader/useLoader.js +2 -2
- package/dist/esm/core/plugin.js +6 -6
- package/dist/esm/document/Html.js +5 -5
- package/dist/esm/document/cli/index.js +6 -6
- package/dist/esm/document/constants.js +1 -1
- package/dist/esm/router/cli/index.js +6 -6
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +4 -4
- package/dist/esm/router/runtime/PrefetchLink.js +7 -7
- package/dist/esm/router/runtime/index.js +2 -2
- package/dist/esm/router/runtime/plugin.js +10 -10
- package/dist/esm/router/runtime/plugin.node.js +8 -8
- package/dist/esm/router/runtime/utils.js +7 -8
- package/dist/esm/router/runtime/withRouter.js +4 -4
- package/dist/esm/ssr/cli/index.js +37 -22
- package/dist/esm/ssr/cli/loadable-bundler-plugin.js +209 -0
- package/dist/esm/ssr/index.js +14 -14
- package/dist/esm/ssr/index.node.js +9 -9
- package/dist/esm/ssr/prefetch.js +4 -4
- package/dist/esm/ssr/react/prerender/index.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +4 -4
- package/dist/esm/ssr/serverRender/renderToStream/index.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/loadable.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/template.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/entry.js +4 -4
- package/dist/esm/ssr/serverRender/renderToString/index.js +3 -3
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +1 -1
- package/dist/esm/ssr/serverRender/renderToString/template.js +1 -1
- package/dist/esm/ssr/utils.js +4 -4
- package/dist/esm/state/cli/index.js +4 -4
- package/dist/esm/state/runtime/plugin.js +7 -7
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm-node/router/runtime/index.js +2 -2
- package/dist/esm-node/router/runtime/plugin.js +1 -1
- package/dist/esm-node/router/runtime/plugin.node.js +1 -1
- package/dist/esm-node/router/runtime/utils.js +1 -2
- package/dist/esm-node/ssr/cli/index.js +30 -15
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +103 -0
- package/dist/esm-node/ssr/index.js +1 -1
- package/dist/esm-node/ssr/prefetch.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/index.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToString/index.js +1 -1
- package/dist/types/router/runtime/index.d.ts +1 -1
- package/dist/types/router/runtime/utils.d.ts +1 -1
- package/dist/types/runtimeContext.d.ts +1 -1
- package/dist/types/ssr/cli/loadable-bundler-plugin.d.ts +10 -0
- package/package.json +9 -9
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_without_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function _class_call_check(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for (var i = 0; i < props.length; i++) {
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor)
|
|
23
|
+
descriptor.writable = true;
|
|
24
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
28
|
+
if (protoProps)
|
|
29
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
30
|
+
if (staticProps)
|
|
31
|
+
_defineProperties(Constructor, staticProps);
|
|
32
|
+
return Constructor;
|
|
33
|
+
}
|
|
34
|
+
function _define_property(obj, key, value) {
|
|
35
|
+
if (key in obj) {
|
|
36
|
+
Object.defineProperty(obj, key, {
|
|
37
|
+
value: value,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
obj[key] = value;
|
|
44
|
+
}
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
function _iterable_to_array(iter) {
|
|
48
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
49
|
+
return Array.from(iter);
|
|
50
|
+
}
|
|
51
|
+
function _non_iterable_spread() {
|
|
52
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
53
|
+
}
|
|
54
|
+
function _object_spread(target) {
|
|
55
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
56
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
57
|
+
var ownKeys2 = Object.keys(source);
|
|
58
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
59
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
60
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
ownKeys2.forEach(function(key) {
|
|
64
|
+
_define_property(target, key, source[key]);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
function ownKeys(object, enumerableOnly) {
|
|
70
|
+
var keys = Object.keys(object);
|
|
71
|
+
if (Object.getOwnPropertySymbols) {
|
|
72
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
73
|
+
if (enumerableOnly) {
|
|
74
|
+
symbols = symbols.filter(function(sym) {
|
|
75
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
keys.push.apply(keys, symbols);
|
|
79
|
+
}
|
|
80
|
+
return keys;
|
|
81
|
+
}
|
|
82
|
+
function _object_spread_props(target, source) {
|
|
83
|
+
source = source != null ? source : {};
|
|
84
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
85
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
86
|
+
} else {
|
|
87
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
88
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function _to_consumable_array(arr) {
|
|
94
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
95
|
+
}
|
|
96
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
97
|
+
if (!o)
|
|
98
|
+
return;
|
|
99
|
+
if (typeof o === "string")
|
|
100
|
+
return _array_like_to_array(o, minLen);
|
|
101
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
102
|
+
if (n === "Object" && o.constructor)
|
|
103
|
+
n = o.constructor.name;
|
|
104
|
+
if (n === "Map" || n === "Set")
|
|
105
|
+
return Array.from(n);
|
|
106
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
107
|
+
return _array_like_to_array(o, minLen);
|
|
108
|
+
}
|
|
109
|
+
import path from "path";
|
|
110
|
+
import { fs } from "@modern-js/utils";
|
|
111
|
+
var LoadablePlugin = /* @__PURE__ */ function() {
|
|
112
|
+
"use strict";
|
|
113
|
+
function LoadablePlugin2() {
|
|
114
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
115
|
+
filename: "loadable-stats.json",
|
|
116
|
+
outputAsset: true,
|
|
117
|
+
chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
|
|
118
|
+
}, _ref_filename = _ref.filename, filename = _ref_filename === void 0 ? "loadable-stats.json" : _ref_filename, path2 = _ref.path, writeToDisk = _ref.writeToDisk, _ref_outputAsset = _ref.outputAsset, outputAsset = _ref_outputAsset === void 0 ? true : _ref_outputAsset, _ref_chunkLoadingGlobal = _ref.chunkLoadingGlobal, chunkLoadingGlobal = _ref_chunkLoadingGlobal === void 0 ? "__LOADABLE_LOADED_CHUNKS__" : _ref_chunkLoadingGlobal;
|
|
119
|
+
_class_call_check(this, LoadablePlugin2);
|
|
120
|
+
_define_property(this, "opts", void 0);
|
|
121
|
+
_define_property(this, "compiler", void 0);
|
|
122
|
+
this.opts = {
|
|
123
|
+
filename: filename,
|
|
124
|
+
path: path2,
|
|
125
|
+
writeToDisk: writeToDisk,
|
|
126
|
+
outputAsset: outputAsset,
|
|
127
|
+
chunkLoadingGlobal: chunkLoadingGlobal
|
|
128
|
+
};
|
|
129
|
+
this.compiler = null;
|
|
130
|
+
}
|
|
131
|
+
_create_class(LoadablePlugin2, [
|
|
132
|
+
{
|
|
133
|
+
key: "apply",
|
|
134
|
+
value: function apply(compiler) {
|
|
135
|
+
var _this = this;
|
|
136
|
+
this.compiler = compiler;
|
|
137
|
+
compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
|
|
138
|
+
if (this.opts.outputAsset || this.opts.writeToDisk) {
|
|
139
|
+
compiler.hooks.make.tap(LoadablePlugin2.name, function(compilation) {
|
|
140
|
+
compilation.hooks.processAssets.tap({
|
|
141
|
+
name: LoadablePlugin2.name,
|
|
142
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
143
|
+
}, function() {
|
|
144
|
+
var asset = _this.handleEmit(compilation);
|
|
145
|
+
if (asset) {
|
|
146
|
+
compilation.emitAsset(_this.opts.filename, asset);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
key: "handleEmit",
|
|
155
|
+
value: function handleEmit(compilation) {
|
|
156
|
+
var stats = compilation.getStats().toJson({
|
|
157
|
+
all: false,
|
|
158
|
+
assets: true,
|
|
159
|
+
// rspack not support cachedAssets,
|
|
160
|
+
cachedAssets: true,
|
|
161
|
+
chunks: true,
|
|
162
|
+
chunkGroups: true,
|
|
163
|
+
entrypoints: true,
|
|
164
|
+
// rspack not support chunkGroupChildren.
|
|
165
|
+
chunkGroupChildren: true,
|
|
166
|
+
hash: true,
|
|
167
|
+
ids: true,
|
|
168
|
+
outputPath: true,
|
|
169
|
+
publicPath: true
|
|
170
|
+
});
|
|
171
|
+
var output = _object_spread_props(_object_spread({}, stats), {
|
|
172
|
+
generator: "loadable-components",
|
|
173
|
+
chunks: _to_consumable_array(stats.chunks || []).map(function(chunk) {
|
|
174
|
+
return {
|
|
175
|
+
id: chunk.id,
|
|
176
|
+
files: _to_consumable_array(chunk.files || [])
|
|
177
|
+
};
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
var result = JSON.stringify(output, null, 2);
|
|
181
|
+
if (this.opts.writeToDisk) {
|
|
182
|
+
this.writeAssetsFile(result);
|
|
183
|
+
}
|
|
184
|
+
if (this.opts.outputAsset) {
|
|
185
|
+
return {
|
|
186
|
+
source: function source() {
|
|
187
|
+
return result;
|
|
188
|
+
},
|
|
189
|
+
size: function size() {
|
|
190
|
+
return result.length;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "writeAssetsFile",
|
|
199
|
+
value: function writeAssetsFile(manifest) {
|
|
200
|
+
var _this_compiler;
|
|
201
|
+
var outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
|
|
202
|
+
var outputFile = path.resolve(outputFolder || "", this.opts.filename);
|
|
203
|
+
fs.outputFileSync(outputFile, manifest);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
]);
|
|
207
|
+
return LoadablePlugin2;
|
|
208
|
+
}();
|
|
209
|
+
module.exports = LoadablePlugin;
|
package/dist/esm/ssr/index.js
CHANGED
|
@@ -30,7 +30,7 @@ function _async_to_generator(fn) {
|
|
|
30
30
|
function _define_property(obj, key, value) {
|
|
31
31
|
if (key in obj) {
|
|
32
32
|
Object.defineProperty(obj, key, {
|
|
33
|
-
value,
|
|
33
|
+
value: value,
|
|
34
34
|
enumerable: true,
|
|
35
35
|
configurable: true,
|
|
36
36
|
writable: true
|
|
@@ -184,7 +184,7 @@ var __generator = function(thisArg, body) {
|
|
|
184
184
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
185
185
|
import { loadableReady } from "@loadable/component";
|
|
186
186
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
187
|
-
import { parsedJSONFromElement } from "@modern-js/utils/runtime";
|
|
187
|
+
import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
|
|
188
188
|
import { RenderLevel } from "./serverRender/types";
|
|
189
189
|
import { WithCallback } from "./react/withCallback";
|
|
190
190
|
import { formatClient, mockResponse, isReact18 } from "./utils";
|
|
@@ -205,14 +205,14 @@ export var ssr = function(config) {
|
|
|
205
205
|
function stringSSRHydrate() {
|
|
206
206
|
if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
|
|
207
207
|
ModernRender(/* @__PURE__ */ _jsx(App, {
|
|
208
|
-
context
|
|
208
|
+
context: context
|
|
209
209
|
}));
|
|
210
210
|
} else if (renderLevel === RenderLevel.SERVER_RENDER) {
|
|
211
211
|
if (isReact18()) {
|
|
212
212
|
loadableReady(function() {
|
|
213
213
|
var SSRApp = function() {
|
|
214
214
|
return /* @__PURE__ */ _jsx(WithCallback, {
|
|
215
|
-
callback,
|
|
215
|
+
callback: callback,
|
|
216
216
|
children: /* @__PURE__ */ _jsx(App, {
|
|
217
217
|
context: hydrateContext
|
|
218
218
|
})
|
|
@@ -231,7 +231,7 @@ export var ssr = function(config) {
|
|
|
231
231
|
} else {
|
|
232
232
|
console.warn("unknow render level: ".concat(renderLevel, ", execute render()"));
|
|
233
233
|
ModernRender(/* @__PURE__ */ _jsx(App, {
|
|
234
|
-
context
|
|
234
|
+
context: context
|
|
235
235
|
}));
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -239,7 +239,7 @@ export var ssr = function(config) {
|
|
|
239
239
|
if (renderLevel === RenderLevel.SERVER_RENDER) {
|
|
240
240
|
var SSRApp = function() {
|
|
241
241
|
return /* @__PURE__ */ _jsx(WithCallback, {
|
|
242
|
-
callback,
|
|
242
|
+
callback: callback,
|
|
243
243
|
children: /* @__PURE__ */ _jsx(App, {
|
|
244
244
|
context: hydrateContext
|
|
245
245
|
})
|
|
@@ -249,7 +249,7 @@ export var ssr = function(config) {
|
|
|
249
249
|
ModernHydrate(/* @__PURE__ */ _jsx(SSRApp, {}));
|
|
250
250
|
} else {
|
|
251
251
|
ModernRender(/* @__PURE__ */ _jsx(App, {
|
|
252
|
-
context
|
|
252
|
+
context: context
|
|
253
253
|
}));
|
|
254
254
|
}
|
|
255
255
|
}
|
|
@@ -291,13 +291,13 @@ export var ssr = function(config) {
|
|
|
291
291
|
request: formatClient({})
|
|
292
292
|
});
|
|
293
293
|
return next({
|
|
294
|
-
context
|
|
294
|
+
context: context
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
297
|
context.ssrContext.response = mockResp;
|
|
298
298
|
context.ssrContext.request = formatClient(request);
|
|
299
299
|
return next({
|
|
300
|
-
context
|
|
300
|
+
context: context
|
|
301
301
|
});
|
|
302
302
|
},
|
|
303
303
|
pickContext: function(param, next) {
|
|
@@ -307,17 +307,17 @@ export var ssr = function(config) {
|
|
|
307
307
|
var initialData = context.initialData;
|
|
308
308
|
if (!request) {
|
|
309
309
|
return next({
|
|
310
|
-
context,
|
|
310
|
+
context: context,
|
|
311
311
|
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
312
|
-
initialData
|
|
312
|
+
initialData: initialData
|
|
313
313
|
})
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
return next({
|
|
317
|
-
context,
|
|
317
|
+
context: context,
|
|
318
318
|
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
319
|
-
initialData,
|
|
320
|
-
request,
|
|
319
|
+
initialData: initialData,
|
|
320
|
+
request: request,
|
|
321
321
|
response: mockResp
|
|
322
322
|
})
|
|
323
323
|
});
|
|
@@ -30,7 +30,7 @@ function _async_to_generator(fn) {
|
|
|
30
30
|
function _define_property(obj, key, value) {
|
|
31
31
|
if (key in obj) {
|
|
32
32
|
Object.defineProperty(obj, key, {
|
|
33
|
-
value,
|
|
33
|
+
value: value,
|
|
34
34
|
enumerable: true,
|
|
35
35
|
configurable: true,
|
|
36
36
|
writable: true
|
|
@@ -199,9 +199,9 @@ export var ssr = function() {
|
|
|
199
199
|
return [
|
|
200
200
|
4,
|
|
201
201
|
render({
|
|
202
|
-
context,
|
|
203
|
-
App,
|
|
204
|
-
config
|
|
202
|
+
context: context,
|
|
203
|
+
App: App,
|
|
204
|
+
config: config
|
|
205
205
|
})
|
|
206
206
|
];
|
|
207
207
|
case 1:
|
|
@@ -223,7 +223,7 @@ export var ssr = function() {
|
|
|
223
223
|
context.ssrContext.request = formatServer(request);
|
|
224
224
|
context.ssrContext.mode = config.mode;
|
|
225
225
|
return next({
|
|
226
|
-
context
|
|
226
|
+
context: context
|
|
227
227
|
});
|
|
228
228
|
},
|
|
229
229
|
pickContext: function(param, next) {
|
|
@@ -231,11 +231,11 @@ export var ssr = function() {
|
|
|
231
231
|
var _ref = context === null || context === void 0 ? void 0 : context.ssrContext, request = _ref.request, response = _ref.response;
|
|
232
232
|
var initialData = context.initialData;
|
|
233
233
|
return next({
|
|
234
|
-
context,
|
|
234
|
+
context: context,
|
|
235
235
|
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
236
|
-
initialData,
|
|
237
|
-
request,
|
|
238
|
-
response
|
|
236
|
+
initialData: initialData,
|
|
237
|
+
request: request,
|
|
238
|
+
response: response
|
|
239
239
|
})
|
|
240
240
|
});
|
|
241
241
|
}
|
package/dist/esm/ssr/prefetch.js
CHANGED
|
@@ -131,7 +131,7 @@ var __generator = function(thisArg, body) {
|
|
|
131
131
|
};
|
|
132
132
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
133
133
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
134
|
-
import { run } from "@modern-js/utils/
|
|
134
|
+
import { run } from "@modern-js/utils/runtime-node";
|
|
135
135
|
import { ChunkExtractor } from "@loadable/server";
|
|
136
136
|
var prefetch = function() {
|
|
137
137
|
var _ref = _async_to_generator(function(App, context) {
|
|
@@ -153,11 +153,11 @@ var prefetch = function() {
|
|
|
153
153
|
].filter(Boolean)
|
|
154
154
|
});
|
|
155
155
|
renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ _jsx(App, {
|
|
156
|
-
context
|
|
156
|
+
context: context
|
|
157
157
|
})));
|
|
158
158
|
} else {
|
|
159
159
|
renderToStaticMarkup(/* @__PURE__ */ _jsx(App, {
|
|
160
|
-
context
|
|
160
|
+
context: context
|
|
161
161
|
}));
|
|
162
162
|
}
|
|
163
163
|
if (!context.loaderManager.hasPendingLoaders()) {
|
|
@@ -186,7 +186,7 @@ var prefetch = function() {
|
|
|
186
186
|
return [
|
|
187
187
|
2,
|
|
188
188
|
{
|
|
189
|
-
loadersData,
|
|
189
|
+
loadersData: loadersData,
|
|
190
190
|
initialData: context.initialData,
|
|
191
191
|
i18nData: context.__i18nData__,
|
|
192
192
|
// todo: move to plugin state
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _define_property(obj, key, value) {
|
|
2
2
|
if (key in obj) {
|
|
3
3
|
Object.defineProperty(obj, key, {
|
|
4
|
-
value,
|
|
4
|
+
value: value,
|
|
5
5
|
enumerable: true,
|
|
6
6
|
configurable: true,
|
|
7
7
|
writable: true
|
|
@@ -26,7 +26,7 @@ function _object_spread(target) {
|
|
|
26
26
|
}
|
|
27
27
|
return target;
|
|
28
28
|
}
|
|
29
|
-
import { serializeJson } from "@modern-js/utils/
|
|
29
|
+
import { serializeJson } from "@modern-js/utils/runtime-node";
|
|
30
30
|
import { buildTemplate } from "./buildTemplate.share";
|
|
31
31
|
export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
32
32
|
var injectSSRDataScript = function injectSSRDataScript2(template) {
|
|
@@ -40,7 +40,7 @@ export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
40
40
|
};
|
|
41
41
|
var SSRData = {
|
|
42
42
|
data: {
|
|
43
|
-
initialData,
|
|
43
|
+
initialData: initialData,
|
|
44
44
|
i18nData: __i18nData__
|
|
45
45
|
},
|
|
46
46
|
context: {
|
|
@@ -52,7 +52,7 @@ export function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
52
52
|
url: request.url
|
|
53
53
|
}, enableUnsafeCtx ? unsafeContext : {})
|
|
54
54
|
},
|
|
55
|
-
renderLevel
|
|
55
|
+
renderLevel: renderLevel
|
|
56
56
|
};
|
|
57
57
|
return "\n <script>window._SSR_DATA = ".concat(serializeJson(SSRData), "</script>\n ");
|
|
58
58
|
}
|
|
@@ -130,7 +130,7 @@ var __generator = function(thisArg, body) {
|
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
132
|
import { createElement } from "react";
|
|
133
|
-
import { run } from "@modern-js/utils/
|
|
133
|
+
import { run } from "@modern-js/utils/runtime-node";
|
|
134
134
|
import { PreRender } from "../../react/prerender";
|
|
135
135
|
import { time } from "../time";
|
|
136
136
|
import renderToPipe from "./renderToPipe";
|
|
@@ -4,7 +4,7 @@ export function getLoadableChunks(param) {
|
|
|
4
4
|
var _context_ssrContext = context.ssrContext, loadableStats = _context_ssrContext.loadableStats, entryName = _context_ssrContext.entryName;
|
|
5
5
|
if (!loadableStats) {
|
|
6
6
|
return {
|
|
7
|
-
jsx
|
|
7
|
+
jsx: jsx
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
var extractor = new ChunkExtractor({
|
|
@@ -64,8 +64,8 @@ export var getTemplates = function(context, renderLevel) {
|
|
|
64
64
|
var _ref = _sliced_to_array(ssrContext.template.split(HTML_SEPARATOR) || [], 2), tmp = _ref[0], beforeAppTemplate = tmp === void 0 ? "" : tmp, tmp1 = _ref[1], afterAppHtmlTemplate = tmp1 === void 0 ? "" : tmp1;
|
|
65
65
|
var builtBeforeTemplate = buildShellBeforeTemplate(beforeAppTemplate, context);
|
|
66
66
|
var builtAfterTemplate = buildShellAfterTemplate(afterAppHtmlTemplate, {
|
|
67
|
-
context,
|
|
68
|
-
renderLevel
|
|
67
|
+
context: context,
|
|
68
|
+
renderLevel: renderLevel
|
|
69
69
|
});
|
|
70
70
|
return {
|
|
71
71
|
shellBefore: builtBeforeTemplate,
|
|
@@ -52,7 +52,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
52
52
|
function _define_property(obj, key, value) {
|
|
53
53
|
if (key in obj) {
|
|
54
54
|
Object.defineProperty(obj, key, {
|
|
55
|
-
value,
|
|
55
|
+
value: value,
|
|
56
56
|
enumerable: true,
|
|
57
57
|
configurable: true,
|
|
58
58
|
writable: true
|
|
@@ -181,7 +181,7 @@ var __generator = function(thisArg, body) {
|
|
|
181
181
|
};
|
|
182
182
|
import React from "react";
|
|
183
183
|
import ReactDomServer from "react-dom/server";
|
|
184
|
-
import { serializeJson } from "@modern-js/utils/
|
|
184
|
+
import { serializeJson } from "@modern-js/utils/runtime-node";
|
|
185
185
|
import ReactHelmet from "react-helmet";
|
|
186
186
|
import { serializeErrors } from "../../../router/runtime/utils";
|
|
187
187
|
import helmetReplace from "../helmet";
|
|
@@ -199,7 +199,7 @@ var buildTemplateData = function(context, data, renderLevel) {
|
|
|
199
199
|
headers: request.headers
|
|
200
200
|
};
|
|
201
201
|
return {
|
|
202
|
-
data,
|
|
202
|
+
data: data,
|
|
203
203
|
context: {
|
|
204
204
|
request: _object_spread({
|
|
205
205
|
params: request.params,
|
|
@@ -209,7 +209,7 @@ var buildTemplateData = function(context, data, renderLevel) {
|
|
|
209
209
|
url: request.url
|
|
210
210
|
}, enableUnsafeCtx ? unsafeContext : {})
|
|
211
211
|
},
|
|
212
|
-
renderLevel
|
|
212
|
+
renderLevel: renderLevel
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
215
|
var Entry = /* @__PURE__ */ function() {
|
|
@@ -129,7 +129,7 @@ var __generator = function(thisArg, body) {
|
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
|
-
import { run } from "@modern-js/utils/
|
|
132
|
+
import { run } from "@modern-js/utils/runtime-node";
|
|
133
133
|
import { PreRender } from "../../react/prerender";
|
|
134
134
|
import { time } from "../time";
|
|
135
135
|
import SSREntry from "./entry";
|
|
@@ -143,8 +143,8 @@ export var render = function(param) {
|
|
|
143
143
|
case 0:
|
|
144
144
|
entry = new SSREntry({
|
|
145
145
|
ctx: ssrContext,
|
|
146
|
-
App,
|
|
147
|
-
config
|
|
146
|
+
App: App,
|
|
147
|
+
config: config
|
|
148
148
|
});
|
|
149
149
|
entry.metrics.emitCounter("app.visit.count", 1);
|
|
150
150
|
end = time();
|
package/dist/esm/ssr/utils.js
CHANGED
|
@@ -12,7 +12,7 @@ function _array_with_holes(arr) {
|
|
|
12
12
|
function _define_property(obj, key, value) {
|
|
13
13
|
if (key in obj) {
|
|
14
14
|
Object.defineProperty(obj, key, {
|
|
15
|
-
value,
|
|
15
|
+
value: value,
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true
|
|
@@ -91,10 +91,10 @@ export var isReact18 = function() {
|
|
|
91
91
|
export var formatServer = function(request) {
|
|
92
92
|
var _ref = request.headers || {}, _ref_cookie = _ref.cookie, cookie = _ref_cookie === void 0 ? "" : _ref_cookie, tmp = _ref["user-agent"], userAgent = tmp === void 0 ? "" : tmp, referer = _ref.referer;
|
|
93
93
|
return _object_spread({
|
|
94
|
-
cookie,
|
|
94
|
+
cookie: cookie,
|
|
95
95
|
cookieMap: cookieTool.parse(cookie || "") || {},
|
|
96
|
-
userAgent,
|
|
97
|
-
referer
|
|
96
|
+
userAgent: userAgent,
|
|
97
|
+
referer: referer
|
|
98
98
|
}, request);
|
|
99
99
|
};
|
|
100
100
|
var getQuery = function() {
|
|
@@ -40,8 +40,8 @@ export default function() {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
return {
|
|
43
|
-
entrypoint,
|
|
44
|
-
imports
|
|
43
|
+
entrypoint: entrypoint,
|
|
44
|
+
imports: imports
|
|
45
45
|
};
|
|
46
46
|
},
|
|
47
47
|
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
|
|
@@ -54,8 +54,8 @@ export default function() {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
return {
|
|
57
|
-
entrypoint,
|
|
58
|
-
plugins
|
|
57
|
+
entrypoint: entrypoint,
|
|
58
|
+
plugins: plugins
|
|
59
59
|
};
|
|
60
60
|
},
|
|
61
61
|
validateSchema: function validateSchema() {
|
|
@@ -12,7 +12,7 @@ function _array_with_holes(arr) {
|
|
|
12
12
|
function _define_property(obj, key, value) {
|
|
13
13
|
if (key in obj) {
|
|
14
14
|
Object.defineProperty(obj, key, {
|
|
15
|
-
value,
|
|
15
|
+
value: value,
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true
|
|
@@ -117,10 +117,10 @@ import { immer, effects, autoActions, devtools } from "../plugins";
|
|
|
117
117
|
import { RuntimeReactContext } from "../../core";
|
|
118
118
|
import { isBrowser } from "../../common";
|
|
119
119
|
var StatePluginHandleMap = {
|
|
120
|
-
immer,
|
|
121
|
-
effects,
|
|
122
|
-
autoActions,
|
|
123
|
-
devtools
|
|
120
|
+
immer: immer,
|
|
121
|
+
effects: effects,
|
|
122
|
+
autoActions: autoActions,
|
|
123
|
+
devtools: devtools
|
|
124
124
|
};
|
|
125
125
|
var getStoreConfig = function(config) {
|
|
126
126
|
var internalPlugins = [
|
|
@@ -189,13 +189,13 @@ var state = function(config) {
|
|
|
189
189
|
}
|
|
190
190
|
context.store = createStore(storeConfig);
|
|
191
191
|
return next({
|
|
192
|
-
context
|
|
192
|
+
context: context
|
|
193
193
|
});
|
|
194
194
|
},
|
|
195
195
|
pickContext: function pickContext(param, next) {
|
|
196
196
|
var context = param.context, pickedContext = param.pickedContext;
|
|
197
197
|
return next({
|
|
198
|
-
context,
|
|
198
|
+
context: context,
|
|
199
199
|
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
200
200
|
store: context.store
|
|
201
201
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Suspense, useEffect, useRef, useMemo, useContext } from "react";
|
|
3
3
|
import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "react-router-dom";
|
|
4
|
-
import { serializeJson } from "@modern-js/utils/
|
|
4
|
+
import { serializeJson } from "@modern-js/utils/runtime-node";
|
|
5
5
|
import { JSX_SHELL_STREAM_END_MARK } from "../../common";
|
|
6
6
|
import { serializeErrors } from "./utils";
|
|
7
7
|
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}}))};`;
|
|
@@ -5,7 +5,7 @@ export { modifyRoutes } from "./plugin";
|
|
|
5
5
|
export * from "./withRouter";
|
|
6
6
|
export { Link, NavLink } from "./PrefetchLink";
|
|
7
7
|
export const useRouteLoaderData = (routeId) => {
|
|
8
|
-
const realRouteId = routeId.replace(/\(
|
|
8
|
+
const realRouteId = routeId.replace(/\[(.*?)\]/g, "($1)");
|
|
9
9
|
return useRouteData(realRouteId);
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
@@ -63,4 +63,4 @@ export {
|
|
|
63
63
|
unstable_useBlocker,
|
|
64
64
|
unstable_usePrompt
|
|
65
65
|
} from "react-router-dom";
|
|
66
|
-
export { defer, json, redirect } from "@modern-js/utils/
|
|
66
|
+
export { defer, json, redirect } from "@modern-js/utils/runtime/router";
|