@modern-js/runtime 2.56.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/core/server/stream/createReadableStream.js +3 -3
- package/dist/cjs/core/server/string/loadable.js +1 -1
- package/dist/esm/core/server/stream/createReadableStream.js +99 -78
- package/dist/esm/core/server/string/loadable.js +1 -1
- package/dist/esm-node/core/server/stream/createReadableStream.js +2 -2
- package/dist/esm-node/core/server/string/loadable.js +1 -1
- package/package.json +10 -11
|
@@ -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;
|
|
@@ -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;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
1
2
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
3
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
5
|
import { Transform } from "stream";
|
|
4
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
5
6
|
import { createReadableStreamFromReadable } from "@modern-js/runtime-utils/node";
|
|
6
7
|
import { ServerStyleSheet } from "styled-components";
|
|
7
8
|
import checkIsBot from "isbot";
|
|
@@ -9,84 +10,104 @@ import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
|
9
10
|
import { RenderLevel } from "../../constants";
|
|
10
11
|
import { getTemplates } from "./template";
|
|
11
12
|
import { ShellChunkStatus, getReadableStreamFromString } from "./shared";
|
|
12
|
-
var createReadableStreamFromElement = function(
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
13
|
+
var createReadableStreamFromElement = function() {
|
|
14
|
+
var _ref = _async_to_generator(function(request, rootElement, options) {
|
|
15
|
+
var renderToPipeableStream, runtimeContext, htmlTemplate, config, ssrConfig, shellChunkStatus, renderLevel, forceStream2String, isbot, onReady, sheet, chunkVec, root;
|
|
16
|
+
return _ts_generator(this, function(_state) {
|
|
17
|
+
switch (_state.label) {
|
|
18
|
+
case 0:
|
|
19
|
+
return [
|
|
20
|
+
4,
|
|
21
|
+
import("react-dom/server")
|
|
22
|
+
];
|
|
23
|
+
case 1:
|
|
24
|
+
renderToPipeableStream = _state.sent().renderToPipeableStream;
|
|
25
|
+
runtimeContext = options.runtimeContext, htmlTemplate = options.htmlTemplate, config = options.config, ssrConfig = options.ssrConfig;
|
|
26
|
+
shellChunkStatus = ShellChunkStatus.START;
|
|
27
|
+
renderLevel = RenderLevel.SERVER_RENDER;
|
|
28
|
+
forceStream2String = Boolean(process.env.MODERN_JS_STREAM_TO_STRING);
|
|
29
|
+
isbot = checkIsBot(request.headers.get("user-agent"));
|
|
30
|
+
onReady = isbot || forceStream2String ? "onAllReady" : "onShellReady";
|
|
31
|
+
sheet = new ServerStyleSheet();
|
|
32
|
+
chunkVec = [];
|
|
33
|
+
root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
|
|
34
|
+
return [
|
|
35
|
+
2,
|
|
36
|
+
new Promise(function(resolve) {
|
|
37
|
+
var _obj;
|
|
38
|
+
var pipe = renderToPipeableStream(root, (_obj = {
|
|
39
|
+
nonce: config.nonce
|
|
40
|
+
}, _define_property(_obj, onReady, function() {
|
|
41
|
+
var _options_onReady;
|
|
42
|
+
var styledComponentsStyleTags = forceStream2String ? sheet.getStyleTags() : "";
|
|
43
|
+
(_options_onReady = options[onReady]) === null || _options_onReady === void 0 ? void 0 : _options_onReady.call(options);
|
|
44
|
+
getTemplates(htmlTemplate, {
|
|
45
|
+
request,
|
|
46
|
+
ssrConfig,
|
|
47
|
+
renderLevel,
|
|
48
|
+
runtimeContext,
|
|
49
|
+
config,
|
|
50
|
+
styledComponentsStyleTags
|
|
51
|
+
}).then(function(param) {
|
|
52
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
53
|
+
var body = new Transform({
|
|
54
|
+
transform: function transform(chunk, _encoding, callback) {
|
|
55
|
+
try {
|
|
56
|
+
if (shellChunkStatus !== ShellChunkStatus.FINISH) {
|
|
57
|
+
chunkVec.push(chunk.toString());
|
|
58
|
+
var concatedChunk = chunkVec.join("");
|
|
59
|
+
if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
|
|
60
|
+
concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
|
|
61
|
+
shellChunkStatus = ShellChunkStatus.FINISH;
|
|
62
|
+
this.push("".concat(shellBefore).concat(concatedChunk).concat(shellAfter));
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
this.push(chunk);
|
|
66
|
+
}
|
|
67
|
+
callback();
|
|
68
|
+
} catch (e) {
|
|
69
|
+
if (_instanceof(e, Error)) {
|
|
70
|
+
callback(e);
|
|
71
|
+
} else {
|
|
72
|
+
callback(new Error("Received unkown error when streaming"));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var stream = createReadableStreamFromReadable(body);
|
|
78
|
+
resolve(stream);
|
|
79
|
+
pipe(body);
|
|
80
|
+
});
|
|
81
|
+
}), _define_property(_obj, "onShellError", function onShellError(error) {
|
|
82
|
+
renderLevel = RenderLevel.CLIENT_RENDER;
|
|
83
|
+
getTemplates(htmlTemplate, {
|
|
84
|
+
request,
|
|
85
|
+
ssrConfig,
|
|
86
|
+
renderLevel,
|
|
87
|
+
runtimeContext,
|
|
88
|
+
config
|
|
89
|
+
}).then(function(param) {
|
|
90
|
+
var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
|
|
91
|
+
var _options_onShellError;
|
|
92
|
+
var fallbackHtml = "".concat(shellBefore).concat(shellAfter);
|
|
93
|
+
var readableStream = getReadableStreamFromString(fallbackHtml);
|
|
94
|
+
resolve(readableStream);
|
|
95
|
+
options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
|
|
96
|
+
});
|
|
97
|
+
}), _define_property(_obj, "onError", function onError(error) {
|
|
98
|
+
var _options_onError;
|
|
99
|
+
renderLevel = RenderLevel.CLIENT_RENDER;
|
|
100
|
+
options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
|
|
101
|
+
}), _obj)).pipe;
|
|
102
|
+
})
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
88
106
|
});
|
|
89
|
-
|
|
107
|
+
return function createReadableStreamFromElement2(request, rootElement, options) {
|
|
108
|
+
return _ref.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}();
|
|
90
111
|
export {
|
|
91
112
|
createReadableStreamFromElement
|
|
92
113
|
};
|
|
@@ -243,7 +243,7 @@ var LoadableCollector = /* @__PURE__ */ function() {
|
|
|
243
243
|
];
|
|
244
244
|
case 1:
|
|
245
245
|
css = _state.sent();
|
|
246
|
-
chunkSet.
|
|
246
|
+
chunkSet.cssChunk += css.filter(function(css2) {
|
|
247
247
|
return Boolean(css2);
|
|
248
248
|
}).join("");
|
|
249
249
|
return [
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Transform } from "stream";
|
|
2
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
3
2
|
import { createReadableStreamFromReadable } from "@modern-js/runtime-utils/node";
|
|
4
3
|
import { ServerStyleSheet } from "styled-components";
|
|
5
4
|
import checkIsBot from "isbot";
|
|
@@ -7,7 +6,8 @@ import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common";
|
|
|
7
6
|
import { RenderLevel } from "../../constants";
|
|
8
7
|
import { getTemplates } from "./template";
|
|
9
8
|
import { ShellChunkStatus, getReadableStreamFromString } from "./shared";
|
|
10
|
-
const createReadableStreamFromElement = (request, rootElement, options) => {
|
|
9
|
+
const createReadableStreamFromElement = async (request, rootElement, options) => {
|
|
10
|
+
const { renderToPipeableStream } = await import("react-dom/server");
|
|
11
11
|
const { runtimeContext, htmlTemplate, config, ssrConfig } = options;
|
|
12
12
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
13
13
|
let renderLevel = RenderLevel.SERVER_RENDER;
|
|
@@ -111,7 +111,7 @@ class LoadableCollector {
|
|
|
111
111
|
return link;
|
|
112
112
|
}
|
|
113
113
|
}));
|
|
114
|
-
chunkSet.
|
|
114
|
+
chunkSet.cssChunk += css.filter((css2) => Boolean(css2)).join("");
|
|
115
115
|
}
|
|
116
116
|
generateAttributes(extraAtr = {}) {
|
|
117
117
|
const { config } = this.options;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.56.
|
|
18
|
+
"version": "2.56.1",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -182,7 +182,6 @@
|
|
|
182
182
|
"@loadable/babel-plugin": "5.15.3",
|
|
183
183
|
"@loadable/component": "5.15.3",
|
|
184
184
|
"@loadable/server": "5.15.3",
|
|
185
|
-
"@loadable/webpack-plugin": "5.15.2",
|
|
186
185
|
"@modern-js-reduck/plugin-auto-actions": "^1.1.10",
|
|
187
186
|
"@modern-js-reduck/plugin-devtools": "^1.1.10",
|
|
188
187
|
"@modern-js-reduck/plugin-effects": "^1.1.10",
|
|
@@ -200,11 +199,11 @@
|
|
|
200
199
|
"react-side-effect": "^2.1.1",
|
|
201
200
|
"styled-components": "^5.3.1",
|
|
202
201
|
"@swc/helpers": "0.5.3",
|
|
203
|
-
"@modern-js/
|
|
204
|
-
"@modern-js/
|
|
205
|
-
"@modern-js/utils": "2.56.
|
|
206
|
-
"@modern-js/
|
|
207
|
-
"@modern-js/
|
|
202
|
+
"@modern-js/types": "2.56.1",
|
|
203
|
+
"@modern-js/plugin": "2.56.1",
|
|
204
|
+
"@modern-js/utils": "2.56.1",
|
|
205
|
+
"@modern-js/plugin-data-loader": "2.56.1",
|
|
206
|
+
"@modern-js/runtime-utils": "2.56.1"
|
|
208
207
|
},
|
|
209
208
|
"peerDependencies": {
|
|
210
209
|
"react": ">=17",
|
|
@@ -227,10 +226,10 @@
|
|
|
227
226
|
"ts-jest": "^29.1.0",
|
|
228
227
|
"typescript": "^5",
|
|
229
228
|
"webpack": "^5.93.0",
|
|
230
|
-
"@modern-js/app-tools": "2.56.
|
|
231
|
-
"@modern-js/core": "2.56.
|
|
232
|
-
"@scripts/build": "2.56.
|
|
233
|
-
"@scripts/jest-config": "2.56.
|
|
229
|
+
"@modern-js/app-tools": "2.56.1",
|
|
230
|
+
"@modern-js/core": "2.56.1",
|
|
231
|
+
"@scripts/build": "2.56.1",
|
|
232
|
+
"@scripts/jest-config": "2.56.1"
|
|
234
233
|
},
|
|
235
234
|
"sideEffects": false,
|
|
236
235
|
"publishConfig": {
|