@modern-js/runtime 2.69.5 → 2.69.7

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.
@@ -26,6 +26,7 @@ __export(shared_exports, {
26
26
  module.exports = __toCommonJS(shared_exports);
27
27
  var import_jsx_runtime = require("react/jsx-runtime");
28
28
  var import_time = require("@modern-js/runtime-utils/time");
29
+ var import_common = require("../../../common");
29
30
  var import_wrapper = require("../../react/wrapper");
30
31
  var import_tracer = require("../tracer");
31
32
  var import_utils = require("../utils");
@@ -61,15 +62,18 @@ function createRenderStreaming(createReadableStreamPromise) {
61
62
  const { onError, onTiming } = options;
62
63
  const { htmlTemplate, entryName } = resource;
63
64
  const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
64
- const RSCServerRoot = ({ children }) => {
65
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
66
- children
65
+ const StreamServerRootWrapper = ({ children }) => {
66
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
67
+ children: [
68
+ children,
69
+ import_common.JSX_SHELL_STREAM_END_MARK
70
+ ]
67
71
  });
68
72
  };
69
73
  let rootElement = (0, import_wrapper.wrapRuntimeContextProvider)(serverRoot, Object.assign(runtimeContext, {
70
74
  ssr: true
71
75
  }));
72
- rootElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RSCServerRoot, {
76
+ rootElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StreamServerRootWrapper, {
73
77
  children: rootElement
74
78
  });
75
79
  const stream = await createReadableStreamFromElement(request, rootElement, {
@@ -41,7 +41,6 @@ var import_router2 = require("@modern-js/runtime-utils/router");
41
41
  var import_time = require("@modern-js/runtime-utils/time");
42
42
  var import_constants = require("@modern-js/utils/universal/constants");
43
43
  var import_react = require("react");
44
- var import_common = require("../../common");
45
44
  var import_core = require("../../core");
46
45
  var import_context = require("../../core/context");
47
46
  var import_serverPayload = require("../../core/context/serverPayload/index.server");
@@ -179,8 +178,7 @@ const routerPlugin = (userConfig = {}) => {
179
178
  nonce,
180
179
  context: routerContext,
181
180
  useJsonScript
182
- }),
183
- mode === "stream" && import_common.JSX_SHELL_STREAM_END_MARK
181
+ })
184
182
  ]
185
183
  });
186
184
  return App ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
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
6
  var __copyProps = (to, from, except, desc) => {
11
7
  if (from && typeof from === "object" || typeof from === "function") {
12
8
  for (let key of __getOwnPropNames(from))
@@ -18,45 +14,9 @@ var __copyProps = (to, from, except, desc) => {
18
14
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
16
  var server_exports = {};
21
- __export(server_exports, {
22
- processRSCStream: () => processRSCStream
23
- });
24
17
  module.exports = __toCommonJS(server_exports);
25
18
  __reExport(server_exports, require("@modern-js/render/rsc"), module.exports);
26
- async function processRSCStream(rscStream, controller, encoder) {
27
- try {
28
- const reader = rscStream.getReader();
29
- const decoder = new TextDecoder("utf-8", {
30
- fatal: true
31
- });
32
- while (true) {
33
- const { done, value } = await reader.read();
34
- if (done)
35
- break;
36
- try {
37
- const chunk = JSON.stringify(decoder.decode(value, {
38
- stream: true
39
- }));
40
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${chunk})</script>`;
41
- controller.enqueue(encoder.encode(scriptTag));
42
- } catch (err) {
43
- const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
44
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))</script>`;
45
- controller.enqueue(encoder.encode(scriptTag));
46
- }
47
- }
48
- const remaining = decoder.decode();
49
- if (remaining.length) {
50
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})</script>`;
51
- controller.enqueue(encoder.encode(scriptTag));
52
- }
53
- controller.close();
54
- } catch (error) {
55
- controller.error(error);
56
- }
57
- }
58
19
  // Annotate the CommonJS export names for ESM import in node:
59
20
  0 && (module.exports = {
60
- processRSCStream,
61
21
  ...require("@modern-js/render/rsc")
62
22
  });
@@ -1,7 +1,8 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
4
4
  import { time } from "@modern-js/runtime-utils/time";
5
+ import { JSX_SHELL_STREAM_END_MARK } from "../../../common";
5
6
  import { wrapRuntimeContextProvider } from "../../react/wrapper";
6
7
  import { SSRErrors, SSRTimings } from "../tracer";
7
8
  import { getSSRConfigByEntry } from "../utils";
@@ -32,7 +33,7 @@ function getReadableStreamFromString(content) {
32
33
  function createRenderStreaming(createReadableStreamPromise) {
33
34
  return function() {
34
35
  var _ref = _async_to_generator(function(request, serverRoot, options) {
35
- var createReadableStreamFromElement, end, runtimeContext, config, resource, onError, onTiming, htmlTemplate, entryName, ssrConfig, RSCServerRoot, rootElement, stream;
36
+ var createReadableStreamFromElement, end, runtimeContext, config, resource, onError, onTiming, htmlTemplate, entryName, ssrConfig, StreamServerRootWrapper, rootElement, stream;
36
37
  return _ts_generator(this, function(_state) {
37
38
  switch (_state.label) {
38
39
  case 0:
@@ -47,16 +48,19 @@ function createRenderStreaming(createReadableStreamPromise) {
47
48
  onError = options.onError, onTiming = options.onTiming;
48
49
  htmlTemplate = resource.htmlTemplate, entryName = resource.entryName;
49
50
  ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
50
- RSCServerRoot = function(param) {
51
+ StreamServerRootWrapper = function(param) {
51
52
  var children = param.children;
52
- return /* @__PURE__ */ _jsx(_Fragment, {
53
- children
53
+ return /* @__PURE__ */ _jsxs(_Fragment, {
54
+ children: [
55
+ children,
56
+ JSX_SHELL_STREAM_END_MARK
57
+ ]
54
58
  });
55
59
  };
56
60
  rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
57
61
  ssr: true
58
62
  }));
59
- rootElement = /* @__PURE__ */ _jsx(RSCServerRoot, {
63
+ rootElement = /* @__PURE__ */ _jsx(StreamServerRootWrapper, {
60
64
  children: rootElement
61
65
  });
62
66
  return [
@@ -11,7 +11,6 @@ import { createRoutesFromElements } from "@modern-js/runtime-utils/router";
11
11
  import { time } from "@modern-js/runtime-utils/time";
12
12
  import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
13
13
  import { useContext } from "react";
14
- import { JSX_SHELL_STREAM_END_MARK } from "../../common";
15
14
  import { RuntimeReactContext } from "../../core";
16
15
  import { getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
17
16
  import { setServerPayload } from "../../core/context/serverPayload/index.server";
@@ -206,8 +205,7 @@ var routerPlugin = function() {
206
205
  nonce,
207
206
  context: routerContext,
208
207
  useJsonScript
209
- }),
210
- mode === "stream" && JSX_SHELL_STREAM_END_MARK
208
+ })
211
209
  ]
212
210
  });
213
211
  return App ? /* @__PURE__ */ _jsx(App, {
@@ -1,87 +1 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
1
  export * from "@modern-js/render/rsc";
5
- function processRSCStream(rscStream, controller, encoder) {
6
- return _processRSCStream.apply(this, arguments);
7
- }
8
- function _processRSCStream() {
9
- _processRSCStream = _async_to_generator(function(rscStream, controller, encoder) {
10
- var reader, decoder, _ref, done, value, chunk, scriptTag, _String, base64, scriptTag1, remaining, scriptTag2, error;
11
- return _ts_generator(this, function(_state) {
12
- switch (_state.label) {
13
- case 0:
14
- _state.trys.push([
15
- 0,
16
- 4,
17
- ,
18
- 5
19
- ]);
20
- reader = rscStream.getReader();
21
- decoder = new TextDecoder("utf-8", {
22
- fatal: true
23
- });
24
- _state.label = 1;
25
- case 1:
26
- if (false)
27
- return [
28
- 3,
29
- 3
30
- ];
31
- return [
32
- 4,
33
- reader.read()
34
- ];
35
- case 2:
36
- _ref = _state.sent(), done = _ref.done, value = _ref.value;
37
- if (done)
38
- return [
39
- 3,
40
- 3
41
- ];
42
- try {
43
- chunk = JSON.stringify(decoder.decode(value, {
44
- stream: true
45
- }));
46
- scriptTag = "<script>(self.__FLIGHT_DATA||=[]).push(".concat(chunk, ")</script>");
47
- controller.enqueue(encoder.encode(scriptTag));
48
- } catch (err) {
49
- ;
50
- base64 = JSON.stringify(btoa((_String = String).fromCodePoint.apply(_String, _to_consumable_array(value))));
51
- scriptTag1 = "<script>(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(".concat(base64, "), m => m.codePointAt(0)))</script>");
52
- controller.enqueue(encoder.encode(scriptTag1));
53
- }
54
- return [
55
- 3,
56
- 1
57
- ];
58
- case 3:
59
- remaining = decoder.decode();
60
- if (remaining.length) {
61
- scriptTag2 = "<script>(self.__FLIGHT_DATA||=[]).push(".concat(JSON.stringify(remaining), ")</script>");
62
- controller.enqueue(encoder.encode(scriptTag2));
63
- }
64
- controller.close();
65
- return [
66
- 3,
67
- 5
68
- ];
69
- case 4:
70
- error = _state.sent();
71
- controller.error(error);
72
- return [
73
- 3,
74
- 5
75
- ];
76
- case 5:
77
- return [
78
- 2
79
- ];
80
- }
81
- });
82
- });
83
- return _processRSCStream.apply(this, arguments);
84
- }
85
- export {
86
- processRSCStream
87
- };
@@ -1,5 +1,6 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { time } from "@modern-js/runtime-utils/time";
3
+ import { JSX_SHELL_STREAM_END_MARK } from "../../../common";
3
4
  import { wrapRuntimeContextProvider } from "../../react/wrapper";
4
5
  import { SSRErrors, SSRTimings } from "../tracer";
5
6
  import { getSSRConfigByEntry } from "../utils";
@@ -35,15 +36,18 @@ function createRenderStreaming(createReadableStreamPromise) {
35
36
  const { onError, onTiming } = options;
36
37
  const { htmlTemplate, entryName } = resource;
37
38
  const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
38
- const RSCServerRoot = ({ children }) => {
39
- return /* @__PURE__ */ _jsx(_Fragment, {
40
- children
39
+ const StreamServerRootWrapper = ({ children }) => {
40
+ return /* @__PURE__ */ _jsxs(_Fragment, {
41
+ children: [
42
+ children,
43
+ JSX_SHELL_STREAM_END_MARK
44
+ ]
41
45
  });
42
46
  };
43
47
  let rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
44
48
  ssr: true
45
49
  }));
46
- rootElement = /* @__PURE__ */ _jsx(RSCServerRoot, {
50
+ rootElement = /* @__PURE__ */ _jsx(StreamServerRootWrapper, {
47
51
  children: rootElement
48
52
  });
49
53
  const stream = await createReadableStreamFromElement(request, rootElement, {
@@ -7,7 +7,6 @@ import { createRoutesFromElements } from "@modern-js/runtime-utils/router";
7
7
  import { time } from "@modern-js/runtime-utils/time";
8
8
  import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
9
9
  import { useContext } from "react";
10
- import { JSX_SHELL_STREAM_END_MARK } from "../../common";
11
10
  import { RuntimeReactContext } from "../../core";
12
11
  import { getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
13
12
  import { setServerPayload } from "../../core/context/serverPayload/index.server";
@@ -145,8 +144,7 @@ const routerPlugin = (userConfig = {}) => {
145
144
  nonce,
146
145
  context: routerContext,
147
146
  useJsonScript
148
- }),
149
- mode === "stream" && JSX_SHELL_STREAM_END_MARK
147
+ })
150
148
  ]
151
149
  });
152
150
  return App ? /* @__PURE__ */ _jsx(App, {
@@ -1,36 +1 @@
1
1
  export * from "@modern-js/render/rsc";
2
- async function processRSCStream(rscStream, controller, encoder) {
3
- try {
4
- const reader = rscStream.getReader();
5
- const decoder = new TextDecoder("utf-8", {
6
- fatal: true
7
- });
8
- while (true) {
9
- const { done, value } = await reader.read();
10
- if (done)
11
- break;
12
- try {
13
- const chunk = JSON.stringify(decoder.decode(value, {
14
- stream: true
15
- }));
16
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${chunk})</script>`;
17
- controller.enqueue(encoder.encode(scriptTag));
18
- } catch (err) {
19
- const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
20
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))</script>`;
21
- controller.enqueue(encoder.encode(scriptTag));
22
- }
23
- }
24
- const remaining = decoder.decode();
25
- if (remaining.length) {
26
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})</script>`;
27
- controller.enqueue(encoder.encode(scriptTag));
28
- }
29
- controller.close();
30
- } catch (error) {
31
- controller.error(error);
32
- }
33
- }
34
- export {
35
- processRSCStream
36
- };
@@ -1,2 +1 @@
1
1
  export * from '@modern-js/render/rsc';
2
- export declare function processRSCStream(rscStream: ReadableStream, controller: ReadableStreamDefaultController<Uint8Array>, encoder: TextEncoder): Promise<void>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.69.5",
18
+ "version": "2.69.7",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -219,13 +219,13 @@
219
219
  "react-is": "^18",
220
220
  "react-side-effect": "^2.1.2",
221
221
  "styled-components": "^5.3.1",
222
- "@modern-js/plugin": "2.69.5",
223
- "@modern-js/plugin-data-loader": "2.69.5",
224
- "@modern-js/plugin-v2": "2.69.5",
225
- "@modern-js/render": "2.69.5",
226
- "@modern-js/runtime-utils": "2.69.5",
227
- "@modern-js/types": "2.69.5",
228
- "@modern-js/utils": "2.69.5"
222
+ "@modern-js/plugin-data-loader": "2.69.7",
223
+ "@modern-js/plugin": "2.69.7",
224
+ "@modern-js/runtime-utils": "2.69.7",
225
+ "@modern-js/render": "2.69.7",
226
+ "@modern-js/plugin-v2": "2.69.7",
227
+ "@modern-js/types": "2.69.7",
228
+ "@modern-js/utils": "2.69.7"
229
229
  },
230
230
  "peerDependencies": {
231
231
  "react": ">=17",
@@ -233,7 +233,7 @@
233
233
  },
234
234
  "devDependencies": {
235
235
  "@remix-run/web-fetch": "^4.1.3",
236
- "@rsbuild/core": "1.6.15",
236
+ "@rsbuild/core": "1.7.1",
237
237
  "@testing-library/react": "^13.4.0",
238
238
  "@types/cookie": "0.6.0",
239
239
  "@types/invariant": "^2.2.30",
@@ -249,10 +249,10 @@
249
249
  "ts-node": "^10.9.1",
250
250
  "typescript": "^5",
251
251
  "webpack": "^5.103.0",
252
- "@modern-js/app-tools": "2.69.5",
252
+ "@modern-js/app-tools": "2.69.7",
253
253
  "@scripts/build": "2.66.0",
254
254
  "@scripts/jest-config": "2.66.0",
255
- "@modern-js/core": "2.69.5"
255
+ "@modern-js/core": "2.69.7"
256
256
  },
257
257
  "sideEffects": false,
258
258
  "publishConfig": {