@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.
@@ -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 } = (0, import_server.renderToPipeableStream)(root, {
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.jsChunk += css.filter((css2) => Boolean(css2)).join("");
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(request, rootElement, options) {
13
- var runtimeContext = options.runtimeContext, htmlTemplate = options.htmlTemplate, config = options.config, ssrConfig = options.ssrConfig;
14
- var shellChunkStatus = ShellChunkStatus.START;
15
- var renderLevel = RenderLevel.SERVER_RENDER;
16
- var forceStream2String = Boolean(process.env.MODERN_JS_STREAM_TO_STRING);
17
- var isbot = checkIsBot(request.headers.get("user-agent"));
18
- var onReady = isbot || forceStream2String ? "onAllReady" : "onShellReady";
19
- var sheet = new ServerStyleSheet();
20
- var chunkVec = [];
21
- var root = forceStream2String ? sheet.collectStyles(rootElement) : rootElement;
22
- return new Promise(function(resolve) {
23
- var _obj;
24
- var pipe = renderToPipeableStream(root, (_obj = {
25
- nonce: config.nonce
26
- }, _define_property(_obj, onReady, function() {
27
- var _options_onReady;
28
- var styledComponentsStyleTags = forceStream2String ? sheet.getStyleTags() : "";
29
- (_options_onReady = options[onReady]) === null || _options_onReady === void 0 ? void 0 : _options_onReady.call(options);
30
- getTemplates(htmlTemplate, {
31
- request,
32
- ssrConfig,
33
- renderLevel,
34
- runtimeContext,
35
- config,
36
- styledComponentsStyleTags
37
- }).then(function(param) {
38
- var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
39
- var body = new Transform({
40
- transform: function transform(chunk, _encoding, callback) {
41
- try {
42
- if (shellChunkStatus !== ShellChunkStatus.FINISH) {
43
- chunkVec.push(chunk.toString());
44
- var concatedChunk = chunkVec.join("");
45
- if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
46
- concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
47
- shellChunkStatus = ShellChunkStatus.FINISH;
48
- this.push("".concat(shellBefore).concat(concatedChunk).concat(shellAfter));
49
- }
50
- } else {
51
- this.push(chunk);
52
- }
53
- callback();
54
- } catch (e) {
55
- if (_instanceof(e, Error)) {
56
- callback(e);
57
- } else {
58
- callback(new Error("Received unkown error when streaming"));
59
- }
60
- }
61
- }
62
- });
63
- var stream = createReadableStreamFromReadable(body);
64
- resolve(stream);
65
- pipe(body);
66
- });
67
- }), _define_property(_obj, "onShellError", function onShellError(error) {
68
- renderLevel = RenderLevel.CLIENT_RENDER;
69
- getTemplates(htmlTemplate, {
70
- request,
71
- ssrConfig,
72
- renderLevel,
73
- runtimeContext,
74
- config
75
- }).then(function(param) {
76
- var shellAfter = param.shellAfter, shellBefore = param.shellBefore;
77
- var _options_onShellError;
78
- var fallbackHtml = "".concat(shellBefore).concat(shellAfter);
79
- var readableStream = getReadableStreamFromString(fallbackHtml);
80
- resolve(readableStream);
81
- options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
82
- });
83
- }), _define_property(_obj, "onError", function onError(error) {
84
- var _options_onError;
85
- renderLevel = RenderLevel.CLIENT_RENDER;
86
- options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
87
- }), _obj)).pipe;
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.jsChunk += css.filter(function(css2) {
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.jsChunk += css.filter((css2) => Boolean(css2)).join("");
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.0",
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/plugin": "2.56.0",
204
- "@modern-js/types": "2.56.0",
205
- "@modern-js/utils": "2.56.0",
206
- "@modern-js/runtime-utils": "2.56.0",
207
- "@modern-js/plugin-data-loader": "2.56.0"
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.0",
231
- "@modern-js/core": "2.56.0",
232
- "@scripts/build": "2.56.0",
233
- "@scripts/jest-config": "2.56.0"
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": {