@modern-js/runtime 3.0.0-alpha.0 → 3.0.0-alpha.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.
@@ -31,6 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  });
32
32
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
33
33
  const time_namespaceObject = require("@modern-js/runtime-utils/time");
34
+ const external_common_js_namespaceObject = require("../../../common.js");
34
35
  const wrapper_js_namespaceObject = require("../../react/wrapper.js");
35
36
  const external_tracer_js_namespaceObject = require("../tracer.js");
36
37
  const external_utils_js_namespaceObject = require("../utils.js");
@@ -62,13 +63,16 @@ function createRenderStreaming(createReadableStreamPromise) {
62
63
  const { onError, onTiming } = options;
63
64
  const { htmlTemplate, entryName } = resource;
64
65
  const ssrConfig = (0, external_utils_js_namespaceObject.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
65
- const RSCServerRoot = ({ children })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
66
- children: children
66
+ const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
67
+ children: [
68
+ children,
69
+ external_common_js_namespaceObject.JSX_SHELL_STREAM_END_MARK
70
+ ]
67
71
  });
68
72
  let rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(serverRoot, Object.assign(runtimeContext, {
69
73
  ssr: true
70
74
  }));
71
- rootElement = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RSCServerRoot, {
75
+ rootElement = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StreamServerRootWrapper, {
72
76
  children: rootElement
73
77
  });
74
78
  const stream = await createReadableStreamFromElement(request, rootElement, {
@@ -43,7 +43,6 @@ const router_namespaceObject = require("@modern-js/runtime-utils/router");
43
43
  const time_namespaceObject = require("@modern-js/runtime-utils/time");
44
44
  const constants_namespaceObject = require("@modern-js/utils/universal/constants");
45
45
  const external_react_namespaceObject = require("react");
46
- const external_common_js_namespaceObject = require("../../common.js");
47
46
  const index_js_namespaceObject = require("../../core/context/index.js");
48
47
  const index_server_js_namespaceObject = require("../../core/context/serverPayload/index.server.js");
49
48
  const external_DeferredDataScripts_node_js_namespaceObject = require("./DeferredDataScripts.node.js");
@@ -159,8 +158,7 @@ const routerPlugin = (userConfig = {})=>({
159
158
  nonce: nonce,
160
159
  context: routerContext,
161
160
  useJsonScript: useJsonScript
162
- }),
163
- 'stream' === mode && external_common_js_namespaceObject.JSX_SHELL_STREAM_END_MARK
161
+ })
164
162
  ]
165
163
  });
166
164
  return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
@@ -47,52 +47,12 @@ function __webpack_require__(moduleId) {
47
47
  var __webpack_exports__ = {};
48
48
  (()=>{
49
49
  __webpack_require__.r(__webpack_exports__);
50
- __webpack_require__.d(__webpack_exports__, {
51
- processRSCStream: ()=>processRSCStream
52
- });
53
50
  var _modern_js_render_rsc__rspack_import_0 = __webpack_require__("@modern-js/render/rsc");
54
51
  var __rspack_reexport = {};
55
- for(const __rspack_import_key in _modern_js_render_rsc__rspack_import_0)if ([
56
- "processRSCStream",
57
- "default"
58
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_render_rsc__rspack_import_0[__rspack_import_key];
52
+ for(const __rspack_import_key in _modern_js_render_rsc__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_render_rsc__rspack_import_0[__rspack_import_key];
59
53
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
60
- async function processRSCStream(rscStream, controller, encoder) {
61
- try {
62
- const reader = rscStream.getReader();
63
- const decoder = new TextDecoder('utf-8', {
64
- fatal: true
65
- });
66
- while(true){
67
- const { done, value } = await reader.read();
68
- if (done) break;
69
- try {
70
- const chunk = JSON.stringify(decoder.decode(value, {
71
- stream: true
72
- }));
73
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${chunk})</script>`;
74
- controller.enqueue(encoder.encode(scriptTag));
75
- } catch (err) {
76
- const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
77
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))</script>`;
78
- controller.enqueue(encoder.encode(scriptTag));
79
- }
80
- }
81
- const remaining = decoder.decode();
82
- if (remaining.length) {
83
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})</script>`;
84
- controller.enqueue(encoder.encode(scriptTag));
85
- }
86
- controller.close();
87
- } catch (error) {
88
- controller.error(error);
89
- }
90
- }
91
54
  })();
92
- exports.processRSCStream = __webpack_exports__.processRSCStream;
93
- for(var __rspack_i in __webpack_exports__)if (-1 === [
94
- "processRSCStream"
95
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
96
56
  Object.defineProperty(exports, '__esModule', {
97
57
  value: true
98
58
  });
@@ -1,5 +1,6 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } 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";
@@ -31,13 +32,16 @@ function createRenderStreaming(createReadableStreamPromise) {
31
32
  const { onError, onTiming } = options;
32
33
  const { htmlTemplate, entryName } = resource;
33
34
  const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
34
- const RSCServerRoot = ({ children })=>/*#__PURE__*/ jsx(Fragment, {
35
- children: children
35
+ const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ jsxs(Fragment, {
36
+ children: [
37
+ children,
38
+ JSX_SHELL_STREAM_END_MARK
39
+ ]
36
40
  });
37
41
  let rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
38
42
  ssr: true
39
43
  }));
40
- rootElement = /*#__PURE__*/ jsx(RSCServerRoot, {
44
+ rootElement = /*#__PURE__*/ jsx(StreamServerRootWrapper, {
41
45
  children: rootElement
42
46
  });
43
47
  const stream = await createReadableStreamFromElement(request, rootElement, {
@@ -5,7 +5,6 @@ import { StaticRouterProvider, createRoutesFromElements, createStaticHandler, cr
5
5
  import { time } from "@modern-js/runtime-utils/time";
6
6
  import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
7
7
  import { useContext } from "react";
8
- import { JSX_SHELL_STREAM_END_MARK } from "../../common";
9
8
  import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
10
9
  import { setServerPayload } from "../../core/context/serverPayload/index.server.mjs";
11
10
  import DeferredDataScripts_node from "./DeferredDataScripts.node.mjs";
@@ -120,8 +119,7 @@ const routerPlugin = (userConfig = {})=>({
120
119
  nonce: nonce,
121
120
  context: routerContext,
122
121
  useJsonScript: useJsonScript
123
- }),
124
- 'stream' === mode && JSX_SHELL_STREAM_END_MARK
122
+ })
125
123
  ]
126
124
  });
127
125
  return App ? /*#__PURE__*/ jsx(App, {
@@ -1,33 +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) break;
11
- try {
12
- const chunk = JSON.stringify(decoder.decode(value, {
13
- stream: true
14
- }));
15
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${chunk})</script>`;
16
- controller.enqueue(encoder.encode(scriptTag));
17
- } catch (err) {
18
- const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
19
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))</script>`;
20
- controller.enqueue(encoder.encode(scriptTag));
21
- }
22
- }
23
- const remaining = decoder.decode();
24
- if (remaining.length) {
25
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})</script>`;
26
- controller.enqueue(encoder.encode(scriptTag));
27
- }
28
- controller.close();
29
- } catch (error) {
30
- controller.error(error);
31
- }
32
- }
33
- export { processRSCStream };
@@ -1,5 +1,6 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { time } from "@modern-js/runtime-utils/time";
3
+ import { JSX_SHELL_STREAM_END_MARK } from "../../../common.mjs";
3
4
  import { wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
4
5
  import { SSRErrors, SSRTimings } from "../tracer.mjs";
5
6
  import { getSSRConfigByEntry } from "../utils.mjs";
@@ -31,13 +32,16 @@ function createRenderStreaming(createReadableStreamPromise) {
31
32
  const { onError, onTiming } = options;
32
33
  const { htmlTemplate, entryName } = resource;
33
34
  const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
34
- const RSCServerRoot = ({ children })=>/*#__PURE__*/ jsx(Fragment, {
35
- children: children
35
+ const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ jsxs(Fragment, {
36
+ children: [
37
+ children,
38
+ JSX_SHELL_STREAM_END_MARK
39
+ ]
36
40
  });
37
41
  let rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
38
42
  ssr: true
39
43
  }));
40
- rootElement = /*#__PURE__*/ jsx(RSCServerRoot, {
44
+ rootElement = /*#__PURE__*/ jsx(StreamServerRootWrapper, {
41
45
  children: rootElement
42
46
  });
43
47
  const stream = await createReadableStreamFromElement(request, rootElement, {
@@ -5,7 +5,6 @@ import { StaticRouterProvider, createRoutesFromElements, createStaticHandler, cr
5
5
  import { time } from "@modern-js/runtime-utils/time";
6
6
  import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
7
7
  import { useContext } from "react";
8
- import { JSX_SHELL_STREAM_END_MARK } from "../../common.mjs";
9
8
  import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context/index.mjs";
10
9
  import { setServerPayload } from "../../core/context/serverPayload/index.server.mjs";
11
10
  import DeferredDataScripts_node from "./DeferredDataScripts.node.mjs";
@@ -120,8 +119,7 @@ const routerPlugin = (userConfig = {})=>({
120
119
  nonce: nonce,
121
120
  context: routerContext,
122
121
  useJsonScript: useJsonScript
123
- }),
124
- 'stream' === mode && JSX_SHELL_STREAM_END_MARK
122
+ })
125
123
  ]
126
124
  });
127
125
  return App ? /*#__PURE__*/ jsx(App, {
@@ -1,33 +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) break;
11
- try {
12
- const chunk = JSON.stringify(decoder.decode(value, {
13
- stream: true
14
- }));
15
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${chunk})</script>`;
16
- controller.enqueue(encoder.encode(scriptTag));
17
- } catch (err) {
18
- const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
19
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))</script>`;
20
- controller.enqueue(encoder.encode(scriptTag));
21
- }
22
- }
23
- const remaining = decoder.decode();
24
- if (remaining.length) {
25
- const scriptTag = `<script>(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})</script>`;
26
- controller.enqueue(encoder.encode(scriptTag));
27
- }
28
- controller.close();
29
- } catch (error) {
30
- controller.error(error);
31
- }
32
- }
33
- export { processRSCStream };
@@ -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": "3.0.0-alpha.0",
18
+ "version": "3.0.0-alpha.1",
19
19
  "engines": {
20
20
  "node": ">=20"
21
21
  },
@@ -221,7 +221,7 @@
221
221
  "dependencies": {
222
222
  "@loadable/component": "5.16.7",
223
223
  "@loadable/server": "5.16.7",
224
- "@swc/plugin-loadable-components": "^9.0.0",
224
+ "@swc/plugin-loadable-components": "^11.3.0",
225
225
  "@swc/helpers": "^0.5.17",
226
226
  "@types/loadable__component": "^5.13.10",
227
227
  "@types/react-helmet": "^6.1.11",
@@ -233,21 +233,21 @@
233
233
  "react-helmet": "^6.1.0",
234
234
  "react-is": "^18.3.1",
235
235
  "entities": "^7.0.0",
236
- "@modern-js/plugin-data-loader": "3.0.0-alpha.0",
237
- "@modern-js/plugin": "3.0.0-alpha.0",
238
- "@modern-js/render": "3.0.0-alpha.0",
239
- "@modern-js/runtime-utils": "3.0.0-alpha.0",
240
- "@modern-js/types": "3.0.0-alpha.0",
241
- "@modern-js/utils": "3.0.0-alpha.0"
236
+ "@modern-js/plugin-data-loader": "3.0.0-alpha.1",
237
+ "@modern-js/plugin": "3.0.0-alpha.1",
238
+ "@modern-js/render": "3.0.0-alpha.1",
239
+ "@modern-js/utils": "3.0.0-alpha.1",
240
+ "@modern-js/types": "3.0.0-alpha.1",
241
+ "@modern-js/runtime-utils": "3.0.0-alpha.1"
242
242
  },
243
243
  "peerDependencies": {
244
244
  "react": ">=17.0.2",
245
245
  "react-dom": ">=17.0.2"
246
246
  },
247
247
  "devDependencies": {
248
- "@rslib/core": "0.18.5",
248
+ "@rslib/core": "0.19.1",
249
249
  "@remix-run/web-fetch": "^4.1.3",
250
- "@rsbuild/core": "1.6.15",
250
+ "@rsbuild/core": "1.7.1",
251
251
  "@testing-library/react": "^16.3.1",
252
252
  "@testing-library/dom": "^10.4.1",
253
253
  "@types/cookie": "0.6.0",
@@ -261,9 +261,9 @@
261
261
  "ts-jest": "^29.4.6",
262
262
  "ts-node": "^10.9.2",
263
263
  "typescript": "^5",
264
- "@modern-js/rslib": "2.68.10",
265
- "@modern-js/app-tools": "3.0.0-alpha.0",
266
- "@scripts/jest-config": "2.66.0"
264
+ "@modern-js/app-tools": "3.0.0-alpha.1",
265
+ "@scripts/jest-config": "2.66.0",
266
+ "@modern-js/rslib": "2.68.10"
267
267
  },
268
268
  "sideEffects": false,
269
269
  "publishConfig": {