@modern-js/runtime 2.48.0 → 2.48.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/ssr/cli/loadable-bundler-plugin.js +0 -3
- package/dist/cjs/ssr/index.js +3 -2
- package/dist/cjs/ssr/react/prerender/index.js +5 -7
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +2 -13
- package/dist/cjs/ssr/serverRender/renderToString/loadable.js +0 -3
- package/dist/cjs/ssr/serverRender/renderToString/render.js +8 -6
- package/dist/cjs/ssr/serverRender/renderToString/styledComponent.js +1 -3
- package/dist/esm/ssr/cli/loadable-bundler-plugin.js +63 -77
- package/dist/esm/ssr/index.js +4 -3
- package/dist/esm/ssr/react/prerender/index.js +20 -27
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm/ssr/serverRender/renderToString/entry.js +177 -202
- package/dist/esm/ssr/serverRender/renderToString/loadable.js +197 -217
- package/dist/esm/ssr/serverRender/renderToString/render.js +40 -46
- package/dist/esm/ssr/serverRender/renderToString/styledComponent.js +9 -19
- package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +0 -3
- package/dist/esm-node/ssr/index.js +3 -2
- package/dist/esm-node/ssr/react/prerender/index.js +5 -7
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +2 -13
- package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +0 -3
- package/dist/esm-node/ssr/serverRender/renderToString/render.js +8 -6
- package/dist/esm-node/ssr/serverRender/renderToString/styledComponent.js +1 -3
- package/dist/types/ssr/serverRender/renderToString/render.d.ts +4 -2
- package/dist/types/ssr/serverRender/types.d.ts +2 -0
- package/package.json +10 -10
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
4
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
5
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
7
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
8
6
|
import React from "react";
|
|
9
7
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
10
|
-
import ReactHelmet from "react-helmet";
|
|
11
8
|
import { time } from "@modern-js/runtime-utils/time";
|
|
12
9
|
import { serializeErrors } from "../../../router/runtime/utils";
|
|
13
10
|
import helmetReplace from "../helmet";
|
|
@@ -52,15 +49,6 @@ var Entry = /* @__PURE__ */ function() {
|
|
|
52
49
|
"use strict";
|
|
53
50
|
function Entry2(options) {
|
|
54
51
|
_class_call_check(this, Entry2);
|
|
55
|
-
_define_property(this, "entryName", void 0);
|
|
56
|
-
_define_property(this, "result", void 0);
|
|
57
|
-
_define_property(this, "tracker", void 0);
|
|
58
|
-
_define_property(this, "template", void 0);
|
|
59
|
-
_define_property(this, "App", void 0);
|
|
60
|
-
_define_property(this, "pluginConfig", void 0);
|
|
61
|
-
_define_property(this, "htmlModifiers", void 0);
|
|
62
|
-
_define_property(this, "nonce", void 0);
|
|
63
|
-
_define_property(this, "routeManifest", void 0);
|
|
64
52
|
var ctx = options.ctx, config = options.config;
|
|
65
53
|
var entryName = ctx.entryName, template = ctx.template, nonce = ctx.nonce;
|
|
66
54
|
this.template = template;
|
|
@@ -80,201 +68,188 @@ var Entry = /* @__PURE__ */ function() {
|
|
|
80
68
|
}
|
|
81
69
|
};
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
""
|
|
98
|
-
];
|
|
99
|
-
}
|
|
100
|
-
return [
|
|
101
|
-
4,
|
|
102
|
-
_this.prefetch(context)
|
|
103
|
-
];
|
|
104
|
-
case 1:
|
|
105
|
-
prefetchData = _state.sent();
|
|
106
|
-
if ((_ssrContext_redirection1 = ssrContext.redirection) === null || _ssrContext_redirection1 === void 0 ? void 0 : _ssrContext_redirection1.url) {
|
|
107
|
-
return [
|
|
108
|
-
2,
|
|
109
|
-
""
|
|
110
|
-
];
|
|
111
|
-
}
|
|
112
|
-
if (!(_this.result.renderLevel >= RenderLevel.SERVER_PREFETCH))
|
|
113
|
-
return [
|
|
114
|
-
3,
|
|
115
|
-
3
|
|
116
|
-
];
|
|
117
|
-
_ = _this.result;
|
|
118
|
-
return [
|
|
119
|
-
4,
|
|
120
|
-
_this.renderToString(context)
|
|
121
|
-
];
|
|
122
|
-
case 2:
|
|
123
|
-
_.html = _state.sent();
|
|
124
|
-
_state.label = 3;
|
|
125
|
-
case 3:
|
|
126
|
-
if ((_ssrContext_redirection2 = ssrContext.redirection) === null || _ssrContext_redirection2 === void 0 ? void 0 : _ssrContext_redirection2.url) {
|
|
127
|
-
return [
|
|
128
|
-
2,
|
|
129
|
-
""
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
routerContext = context.routerContext;
|
|
133
|
-
routerData = routerContext ? {
|
|
134
|
-
loaderData: routerContext.loaderData,
|
|
135
|
-
errors: serializeErrors(routerContext.errors)
|
|
136
|
-
} : void 0;
|
|
137
|
-
templateData = buildTemplateData(ssrContext, prefetchData, _this.result.renderLevel, _this.tracker, _this.pluginConfig);
|
|
138
|
-
ssrDataScripts = _this.getSSRDataScript(templateData, routerData);
|
|
139
|
-
html = buildHtml(_this.template, [
|
|
140
|
-
createReplaceChunkCss(_this.result.chunksMap.css),
|
|
141
|
-
createReplaceChunkJs(_this.result.chunksMap.js),
|
|
142
|
-
createReplaceSSRDataScript(ssrDataScripts),
|
|
143
|
-
createReplaceHtml(_this.result.html || "")
|
|
144
|
-
].concat(_to_consumable_array(_this.htmlModifiers)));
|
|
145
|
-
helmetData = ReactHelmet.renderStatic();
|
|
146
|
-
return [
|
|
147
|
-
2,
|
|
148
|
-
helmetData ? helmetReplace(html, helmetData) : html
|
|
149
|
-
];
|
|
71
|
+
var _proto = Entry2.prototype;
|
|
72
|
+
_proto.renderToHtml = function renderToHtml(context) {
|
|
73
|
+
var _this = this;
|
|
74
|
+
return _async_to_generator(function() {
|
|
75
|
+
var _ssrContext_redirection, _ssrContext_redirection1, _ssrContext_redirection2, ssrContext, prefetchData, _, routerContext, routerData, templateData, ssrDataScripts, html, helmetData;
|
|
76
|
+
return _ts_generator(this, function(_state) {
|
|
77
|
+
switch (_state.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
ssrContext = context.ssrContext;
|
|
80
|
+
if ((_ssrContext_redirection = ssrContext.redirection) === null || _ssrContext_redirection === void 0 ? void 0 : _ssrContext_redirection.url) {
|
|
81
|
+
return [
|
|
82
|
+
2,
|
|
83
|
+
""
|
|
84
|
+
];
|
|
150
85
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
switch (_state.label) {
|
|
163
|
-
case 0:
|
|
164
|
-
_state.trys.push([
|
|
165
|
-
0,
|
|
166
|
-
2,
|
|
167
|
-
,
|
|
168
|
-
3
|
|
169
|
-
]);
|
|
170
|
-
return [
|
|
171
|
-
4,
|
|
172
|
-
prefetch(_this.App, context, _this.pluginConfig, _this.tracker)
|
|
173
|
-
];
|
|
174
|
-
case 1:
|
|
175
|
-
prefetchData = _state.sent();
|
|
176
|
-
_this.result.renderLevel = RenderLevel.SERVER_PREFETCH;
|
|
177
|
-
return [
|
|
178
|
-
3,
|
|
179
|
-
3
|
|
180
|
-
];
|
|
181
|
-
case 2:
|
|
182
|
-
e = _state.sent();
|
|
183
|
-
_this.result.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
184
|
-
return [
|
|
185
|
-
3,
|
|
186
|
-
3
|
|
187
|
-
];
|
|
188
|
-
case 3:
|
|
189
|
-
return [
|
|
190
|
-
2,
|
|
191
|
-
prefetchData || {}
|
|
192
|
-
];
|
|
86
|
+
return [
|
|
87
|
+
4,
|
|
88
|
+
_this.prefetch(context)
|
|
89
|
+
];
|
|
90
|
+
case 1:
|
|
91
|
+
prefetchData = _state.sent();
|
|
92
|
+
if ((_ssrContext_redirection1 = ssrContext.redirection) === null || _ssrContext_redirection1 === void 0 ? void 0 : _ssrContext_redirection1.url) {
|
|
93
|
+
return [
|
|
94
|
+
2,
|
|
95
|
+
""
|
|
96
|
+
];
|
|
193
97
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
1,
|
|
214
|
-
3,
|
|
215
|
-
,
|
|
216
|
-
4
|
|
217
|
-
]);
|
|
218
|
-
App = React.createElement(_this.App, {
|
|
219
|
-
context: Object.assign(context, {
|
|
220
|
-
ssr: true
|
|
221
|
-
})
|
|
222
|
-
});
|
|
223
|
-
return [
|
|
224
|
-
4,
|
|
225
|
-
createRender(App).addCollector(createStyledCollector(_this.result)).addCollector(createLoadableCollector({
|
|
226
|
-
stats: ssrContext.loadableStats,
|
|
227
|
-
result: _this.result,
|
|
228
|
-
entryName: _this.entryName,
|
|
229
|
-
config: _this.pluginConfig,
|
|
230
|
-
nonce: _this.nonce,
|
|
231
|
-
template: _this.template,
|
|
232
|
-
routeManifest: _this.routeManifest
|
|
233
|
-
})).finish()
|
|
234
|
-
];
|
|
235
|
-
case 2:
|
|
236
|
-
html = _state.sent();
|
|
237
|
-
cost = end();
|
|
238
|
-
_this.tracker.trackTiming(SSRTimings.RENDER_HTML, cost);
|
|
239
|
-
_this.result.renderLevel = RenderLevel.SERVER_RENDER;
|
|
240
|
-
return [
|
|
241
|
-
3,
|
|
242
|
-
4
|
|
243
|
-
];
|
|
244
|
-
case 3:
|
|
245
|
-
e = _state.sent();
|
|
246
|
-
_this.tracker.trackError(SSRErrors.RENDER_HTML, e);
|
|
247
|
-
return [
|
|
248
|
-
3,
|
|
249
|
-
4
|
|
250
|
-
];
|
|
251
|
-
case 4:
|
|
252
|
-
return [
|
|
253
|
-
2,
|
|
254
|
-
html
|
|
255
|
-
];
|
|
98
|
+
if (!(_this.result.renderLevel >= RenderLevel.SERVER_PREFETCH))
|
|
99
|
+
return [
|
|
100
|
+
3,
|
|
101
|
+
3
|
|
102
|
+
];
|
|
103
|
+
_ = _this.result;
|
|
104
|
+
return [
|
|
105
|
+
4,
|
|
106
|
+
_this.renderToString(context)
|
|
107
|
+
];
|
|
108
|
+
case 2:
|
|
109
|
+
_.html = _state.sent();
|
|
110
|
+
_state.label = 3;
|
|
111
|
+
case 3:
|
|
112
|
+
if ((_ssrContext_redirection2 = ssrContext.redirection) === null || _ssrContext_redirection2 === void 0 ? void 0 : _ssrContext_redirection2.url) {
|
|
113
|
+
return [
|
|
114
|
+
2,
|
|
115
|
+
""
|
|
116
|
+
];
|
|
256
117
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
118
|
+
routerContext = context.routerContext;
|
|
119
|
+
routerData = routerContext ? {
|
|
120
|
+
loaderData: routerContext.loaderData,
|
|
121
|
+
errors: serializeErrors(routerContext.errors)
|
|
122
|
+
} : void 0;
|
|
123
|
+
templateData = buildTemplateData(ssrContext, prefetchData, _this.result.renderLevel, _this.tracker, _this.pluginConfig);
|
|
124
|
+
ssrDataScripts = _this.getSSRDataScript(templateData, routerData);
|
|
125
|
+
html = buildHtml(_this.template, [
|
|
126
|
+
createReplaceChunkCss(_this.result.chunksMap.css),
|
|
127
|
+
createReplaceChunkJs(_this.result.chunksMap.js),
|
|
128
|
+
createReplaceSSRDataScript(ssrDataScripts),
|
|
129
|
+
createReplaceHtml(_this.result.html || "")
|
|
130
|
+
].concat(_to_consumable_array(_this.htmlModifiers)));
|
|
131
|
+
helmetData = _this.result.helmet;
|
|
132
|
+
return [
|
|
133
|
+
2,
|
|
134
|
+
helmetData ? helmetReplace(html, helmetData) : html
|
|
135
|
+
];
|
|
273
136
|
}
|
|
274
|
-
|
|
275
|
-
|
|
137
|
+
});
|
|
138
|
+
})();
|
|
139
|
+
};
|
|
140
|
+
_proto.prefetch = function prefetch1(context) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
return _async_to_generator(function() {
|
|
143
|
+
var prefetchData, e;
|
|
144
|
+
return _ts_generator(this, function(_state) {
|
|
145
|
+
switch (_state.label) {
|
|
146
|
+
case 0:
|
|
147
|
+
_state.trys.push([
|
|
148
|
+
0,
|
|
149
|
+
2,
|
|
150
|
+
,
|
|
151
|
+
3
|
|
152
|
+
]);
|
|
153
|
+
return [
|
|
154
|
+
4,
|
|
155
|
+
prefetch(_this.App, context, _this.pluginConfig, _this.tracker)
|
|
156
|
+
];
|
|
157
|
+
case 1:
|
|
158
|
+
prefetchData = _state.sent();
|
|
159
|
+
_this.result.renderLevel = RenderLevel.SERVER_PREFETCH;
|
|
160
|
+
return [
|
|
161
|
+
3,
|
|
162
|
+
3
|
|
163
|
+
];
|
|
164
|
+
case 2:
|
|
165
|
+
e = _state.sent();
|
|
166
|
+
_this.result.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
167
|
+
return [
|
|
168
|
+
3,
|
|
169
|
+
3
|
|
170
|
+
];
|
|
171
|
+
case 3:
|
|
172
|
+
return [
|
|
173
|
+
2,
|
|
174
|
+
prefetchData || {}
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
})();
|
|
179
|
+
};
|
|
180
|
+
_proto.renderToString = function renderToString(context) {
|
|
181
|
+
var _this = this;
|
|
182
|
+
return _async_to_generator(function() {
|
|
183
|
+
var html, end, ssrContext, App, cost, e;
|
|
184
|
+
return _ts_generator(this, function(_state) {
|
|
185
|
+
switch (_state.label) {
|
|
186
|
+
case 0:
|
|
187
|
+
html = "";
|
|
188
|
+
end = time();
|
|
189
|
+
ssrContext = context.ssrContext;
|
|
190
|
+
_state.label = 1;
|
|
191
|
+
case 1:
|
|
192
|
+
_state.trys.push([
|
|
193
|
+
1,
|
|
194
|
+
3,
|
|
195
|
+
,
|
|
196
|
+
4
|
|
197
|
+
]);
|
|
198
|
+
App = React.createElement(_this.App, {
|
|
199
|
+
context: Object.assign(context, {
|
|
200
|
+
ssr: true
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
return [
|
|
204
|
+
4,
|
|
205
|
+
createRender(App, _this.result).addCollector(createStyledCollector(_this.result)).addCollector(createLoadableCollector({
|
|
206
|
+
stats: ssrContext.loadableStats,
|
|
207
|
+
result: _this.result,
|
|
208
|
+
entryName: _this.entryName,
|
|
209
|
+
config: _this.pluginConfig,
|
|
210
|
+
nonce: _this.nonce,
|
|
211
|
+
template: _this.template,
|
|
212
|
+
routeManifest: _this.routeManifest
|
|
213
|
+
})).finish()
|
|
214
|
+
];
|
|
215
|
+
case 2:
|
|
216
|
+
html = _state.sent();
|
|
217
|
+
cost = end();
|
|
218
|
+
_this.tracker.trackTiming(SSRTimings.RENDER_HTML, cost);
|
|
219
|
+
_this.result.renderLevel = RenderLevel.SERVER_RENDER;
|
|
220
|
+
return [
|
|
221
|
+
3,
|
|
222
|
+
4
|
|
223
|
+
];
|
|
224
|
+
case 3:
|
|
225
|
+
e = _state.sent();
|
|
226
|
+
_this.tracker.trackError(SSRErrors.RENDER_HTML, e);
|
|
227
|
+
return [
|
|
228
|
+
3,
|
|
229
|
+
4
|
|
230
|
+
];
|
|
231
|
+
case 4:
|
|
232
|
+
return [
|
|
233
|
+
2,
|
|
234
|
+
html
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
})();
|
|
239
|
+
};
|
|
240
|
+
_proto.getSSRDataScript = function getSSRDataScript(templateData, routerData) {
|
|
241
|
+
var useInlineScript = this.pluginConfig.inlineScript !== false;
|
|
242
|
+
var ssrData = serializeJson(templateData);
|
|
243
|
+
var attrsStr = attributesToString({
|
|
244
|
+
nonce: this.nonce
|
|
245
|
+
});
|
|
246
|
+
var ssrDataScripts = useInlineScript ? "<script".concat(attrsStr, ">window._SSR_DATA = ").concat(ssrData, "</script>") : '<script type="application/json" id="'.concat(SSR_DATA_JSON_ID, '">').concat(ssrData, "</script>");
|
|
247
|
+
if (routerData) {
|
|
248
|
+
var serializedRouterData = serializeJson(routerData);
|
|
249
|
+
ssrDataScripts += useInlineScript ? "\n<script".concat(attrsStr, ">window._ROUTER_DATA = ").concat(serializedRouterData, "</script>") : '\n<script type="application/json" id="'.concat(ROUTER_DATA_JSON_ID, '">').concat(serializedRouterData, "</script>");
|
|
276
250
|
}
|
|
277
|
-
|
|
251
|
+
return ssrDataScripts;
|
|
252
|
+
};
|
|
278
253
|
return Entry2;
|
|
279
254
|
}();
|
|
280
255
|
export {
|