@modern-js/runtime 2.57.1 → 2.57.2-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.
Files changed (43) hide show
  1. package/dist/cjs/core/browser/hydrate.js +9 -25
  2. package/dist/cjs/core/browser/index.js +8 -5
  3. package/dist/cjs/core/compatible.js +6 -19
  4. package/dist/cjs/core/constants.js +8 -2
  5. package/dist/cjs/core/context/index.js +2 -0
  6. package/dist/cjs/core/react/index.js +1 -10
  7. package/dist/cjs/core/react/wrapper.js +44 -0
  8. package/dist/cjs/core/server/constants.js +0 -6
  9. package/dist/cjs/core/server/stream/shared.js +4 -16
  10. package/dist/cjs/core/server/string/index.js +4 -6
  11. package/dist/cjs/core/server/string/prefetch.js +7 -21
  12. package/dist/cjs/core/server/string/ssrData.js +1 -1
  13. package/dist/esm/core/browser/hydrate.js +9 -15
  14. package/dist/esm/core/browser/index.js +9 -6
  15. package/dist/esm/core/compatible.js +5 -22
  16. package/dist/esm/core/constants.js +5 -1
  17. package/dist/esm/core/context/index.js +2 -1
  18. package/dist/esm/core/react/index.js +2 -14
  19. package/dist/esm/core/react/wrapper.js +10 -0
  20. package/dist/esm/core/server/constants.js +0 -4
  21. package/dist/esm/core/server/stream/shared.js +4 -6
  22. package/dist/esm/core/server/string/index.js +4 -6
  23. package/dist/esm/core/server/string/prefetch.js +7 -11
  24. package/dist/esm/core/server/string/ssrData.js +1 -1
  25. package/dist/esm-node/core/browser/hydrate.js +9 -15
  26. package/dist/esm-node/core/browser/index.js +8 -5
  27. package/dist/esm-node/core/compatible.js +6 -19
  28. package/dist/esm-node/core/constants.js +5 -1
  29. package/dist/esm-node/core/context/index.js +2 -1
  30. package/dist/esm-node/core/react/index.js +2 -11
  31. package/dist/esm-node/core/react/wrapper.js +10 -0
  32. package/dist/esm-node/core/server/constants.js +0 -4
  33. package/dist/esm-node/core/server/stream/shared.js +4 -6
  34. package/dist/esm-node/core/server/string/index.js +4 -6
  35. package/dist/esm-node/core/server/string/prefetch.js +7 -11
  36. package/dist/esm-node/core/server/string/ssrData.js +1 -1
  37. package/dist/types/core/compatible.d.ts +1 -1
  38. package/dist/types/core/constants.d.ts +2 -0
  39. package/dist/types/core/context/index.d.ts +1 -1
  40. package/dist/types/core/react/index.d.ts +1 -1
  41. package/dist/types/core/react/wrapper.d.ts +3 -0
  42. package/dist/types/core/server/constants.d.ts +0 -2
  43. package/package.json +5 -6
@@ -4,6 +4,10 @@ var RenderLevel;
4
4
  RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
5
5
  RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
6
6
  })(RenderLevel || (RenderLevel = {}));
7
+ var SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
8
+ var ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
7
9
  export {
8
- RenderLevel
10
+ ROUTER_DATA_JSON_ID,
11
+ RenderLevel,
12
+ SSR_DATA_JSON_ID
9
13
  };
@@ -1,4 +1,4 @@
1
- import { RuntimeReactContext } from "./runtime";
1
+ import { RuntimeReactContext, getInitialContext } from "./runtime";
2
2
  var globalContext = {};
3
3
  function setGlobalContext(context) {
4
4
  globalContext.App = context.App;
@@ -31,5 +31,6 @@ export {
31
31
  getGlobalAppInit,
32
32
  getGlobalLayoutApp,
33
33
  getGlobalRoutes,
34
+ getInitialContext,
34
35
  setGlobalContext
35
36
  };
@@ -1,22 +1,10 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- import { RuntimeReactContext, getGlobalApp } from "../context";
1
+ import { getGlobalApp } from "../context";
5
2
  import { getGlobalRunner } from "../plugin/runner";
6
3
  function createRoot(UserApp) {
7
4
  var App = UserApp || getGlobalApp();
8
5
  var runner = getGlobalRunner();
9
6
  var WrapperApp = runner.wrapRoot(App);
10
- var WrapComponent = function(_param) {
11
- var _internal_context = _param._internal_context, props = _object_without_properties(_param, [
12
- "_internal_context"
13
- ]);
14
- return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
15
- value: _internal_context,
16
- children: /* @__PURE__ */ _jsx(WrapperApp, _object_spread({}, props))
17
- });
18
- };
19
- return WrapComponent;
7
+ return WrapperApp;
20
8
  }
21
9
  export {
22
10
  createRoot
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { RuntimeReactContext } from "../context";
3
+ function wrapRuntimeContextProvider(App, contextValue) {
4
+ return /* @__PURE__ */ React.createElement(RuntimeReactContext.Provider, {
5
+ value: contextValue
6
+ }, App);
7
+ }
8
+ export {
9
+ wrapRuntimeContextProvider
10
+ };
@@ -2,13 +2,9 @@ var HTML_PLACEHOLDER = "<!--<?- html ?>-->";
2
2
  var SSR_DATA_PLACEHOLDER = "<!--<?- SSRDataScript ?>-->";
3
3
  var CHUNK_JS_PLACEHOLDER = "<!--<?- chunksMap.js ?>-->";
4
4
  var CHUNK_CSS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
5
- var SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
6
- var ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
7
5
  export {
8
6
  CHUNK_CSS_PLACEHOLDER,
9
7
  CHUNK_JS_PLACEHOLDER,
10
8
  HTML_PLACEHOLDER,
11
- ROUTER_DATA_JSON_ID,
12
- SSR_DATA_JSON_ID,
13
9
  SSR_DATA_PLACEHOLDER
14
10
  };
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { time } from "@modern-js/runtime-utils/time";
4
4
  import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
5
5
  import { run } from "@modern-js/runtime-utils/node";
6
- import React from "react";
6
+ import { wrapRuntimeContextProvider } from "../../react/wrapper";
7
7
  import { SSRErrors, SSRTimings, createOnError, createOnTiming } from "../tracer";
8
8
  import { getSSRConfigByEntry } from "../utils";
9
9
  var ShellChunkStatus;
@@ -49,11 +49,9 @@ function createRenderStreaming(createReadableStreamFromElement) {
49
49
  onTiming = createOnTiming(options.onTiming);
50
50
  htmlTemplate = resource.htmlTemplate, entryName = resource.entryName;
51
51
  ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
52
- rootElement = React.cloneElement(serverRoot, {
53
- _internal_context: Object.assign(runtimeContext, {
54
- ssr: true
55
- })
56
- });
52
+ rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
53
+ ssr: true
54
+ }));
57
55
  return [
58
56
  4,
59
57
  createReadableStreamFromElement(request, rootElement, {
@@ -3,10 +3,10 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import ReactHelmet from "react-helmet";
5
5
  import ReactDomServer from "react-dom/server";
6
- import React from "react";
7
6
  import { time } from "@modern-js/runtime-utils/time";
8
7
  import { run } from "@modern-js/runtime-utils/node";
9
8
  import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
9
+ import { wrapRuntimeContextProvider } from "../../react/wrapper";
10
10
  import { createReplaceHelemt } from "../helmet";
11
11
  import { getSSRConfigByEntry, safeReplace } from "../utils";
12
12
  import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants";
@@ -93,11 +93,9 @@ var renderString = function() {
93
93
  nonce: config.nonce
94
94
  })
95
95
  ];
96
- rootElement = React.cloneElement(serverRoot, {
97
- _internal_context: Object.assign(runtimeContext, {
98
- ssr: true
99
- })
100
- });
96
+ rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
97
+ ssr: true
98
+ }));
101
99
  return [
102
100
  4,
103
101
  generateHtml(rootElement, htmlTemplate, chunkSet, collectors, ((_runtimeContext_ssrContext = runtimeContext.ssrContext) === null || _runtimeContext_ssrContext === void 0 ? void 0 : _runtimeContext_ssrContext.htmlModifiers) || [], tracer)
@@ -5,7 +5,7 @@ import { run } from "@modern-js/runtime-utils/node";
5
5
  import { ChunkExtractor } from "@loadable/server";
6
6
  import { time } from "@modern-js/runtime-utils/time";
7
7
  import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
8
- import React from "react";
8
+ import { wrapRuntimeContextProvider } from "../../react/wrapper";
9
9
  import { SSRErrors, SSRTimings } from "../tracer";
10
10
  var prefetch = function() {
11
11
  var _ref = _async_to_generator(function(App, request, options, ssrConfig, param) {
@@ -32,17 +32,13 @@ var prefetch = function() {
32
32
  entryName
33
33
  ].filter(Boolean)
34
34
  });
35
- renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ React.cloneElement(App, {
36
- _internal_context: Object.assign(context, {
37
- ssr: false
38
- })
39
- })));
35
+ renderToStaticMarkup(extractor.collectChunks(wrapRuntimeContextProvider(App, Object.assign(context, {
36
+ ssr: false
37
+ }))));
40
38
  } else {
41
- renderToStaticMarkup(/* @__PURE__ */ React.cloneElement(App, {
42
- _internal_context: Object.assign(context, {
43
- ssr: false
44
- })
45
- }));
39
+ renderToStaticMarkup(wrapRuntimeContextProvider(App, Object.assign(context, {
40
+ ssr: false
41
+ })));
46
42
  }
47
43
  cost = end();
48
44
  onTiming(SSRTimings.PRERENDER, cost);
@@ -7,7 +7,7 @@ import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_m
7
7
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
8
8
  import { serializeJson } from "@modern-js/runtime-utils/node";
9
9
  import { attributesToString, serializeErrors } from "../utils";
10
- import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
10
+ import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants";
11
11
  var _options = /* @__PURE__ */ new WeakMap(), _getSSRData = /* @__PURE__ */ new WeakSet(), _getSSRDataScripts = /* @__PURE__ */ new WeakSet();
12
12
  var SSRDataCollector = /* @__PURE__ */ function() {
13
13
  "use strict";
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { normalizePathname } from "@modern-js/runtime-utils/url";
3
3
  import { loadableReady } from "@loadable/component";
4
- import React from "react";
5
4
  import { RenderLevel } from "../constants";
5
+ import { wrapRuntimeContextProvider } from "../react/wrapper";
6
6
  import { WithCallback } from "./withCallback";
7
7
  const isReact18 = () => process.env.IS_REACT18 === "true";
8
8
  function hydrateRoot(App, context, ModernRender, ModernHydrate) {
@@ -34,38 +34,32 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
34
34
  if (renderLevel === RenderLevel.SERVER_RENDER) {
35
35
  const SSRApp = () => /* @__PURE__ */ _jsx(WithCallback, {
36
36
  callback,
37
- children: /* @__PURE__ */ React.cloneElement(App, {
38
- _internal_context: hydrateContext
39
- })
37
+ children: App
40
38
  });
41
- return ModernHydrate(/* @__PURE__ */ _jsx(SSRApp, {}));
39
+ return ModernHydrate(wrapRuntimeContextProvider(/* @__PURE__ */ _jsx(SSRApp, {}), hydrateContext));
42
40
  } else {
43
- return ModernRender(App);
41
+ return ModernRender(wrapRuntimeContextProvider(App, context));
44
42
  }
45
43
  }
46
44
  return stringSSRHydrate();
47
45
  function stringSSRHydrate() {
48
46
  if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
49
- return ModernRender(App);
47
+ return ModernRender(wrapRuntimeContextProvider(App, context));
50
48
  } else if (renderLevel === RenderLevel.SERVER_RENDER) {
51
49
  return new Promise((resolve) => {
52
50
  if (isReact18()) {
53
51
  loadableReady(() => {
54
52
  const SSRApp = () => /* @__PURE__ */ _jsx(WithCallback, {
55
53
  callback,
56
- children: /* @__PURE__ */ React.cloneElement(App, {
57
- _internal_context: hydrateContext
58
- })
54
+ children: App
59
55
  });
60
- ModernHydrate(/* @__PURE__ */ _jsx(SSRApp, {})).then((root) => {
56
+ ModernHydrate(wrapRuntimeContextProvider(/* @__PURE__ */ _jsx(SSRApp, {}), hydrateContext)).then((root) => {
61
57
  resolve(root);
62
58
  });
63
59
  });
64
60
  } else {
65
61
  loadableReady(() => {
66
- ModernHydrate(/* @__PURE__ */ React.cloneElement(App, {
67
- _internal_context: hydrateContext
68
- }), callback).then((root) => {
62
+ ModernHydrate(wrapRuntimeContextProvider(App, hydrateContext), callback).then((root) => {
69
63
  resolve(root);
70
64
  });
71
65
  });
@@ -73,7 +67,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
73
67
  });
74
68
  } else {
75
69
  console.warn(`unknow render level: ${renderLevel}, execute render()`);
76
- return ModernRender(App);
70
+ return ModernRender(wrapRuntimeContextProvider(App, context));
77
71
  }
78
72
  }
79
73
  }
@@ -1,9 +1,11 @@
1
- import React from "react";
2
1
  import cookieTool from "cookie";
2
+ import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
3
3
  import { getGlobalAppInit } from "../context";
4
4
  import { getInitialContext } from "../context/runtime";
5
5
  import { createLoaderManager } from "../loader/loaderManager";
6
6
  import { getGlobalRunner } from "../plugin/runner";
7
+ import { wrapRuntimeContextProvider } from "../react/wrapper";
8
+ import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
7
9
  import { hydrateRoot } from "./hydrate";
8
10
  const IS_REACT18 = process.env.IS_REACT18 === "true";
9
11
  function getSSRData() {
@@ -38,6 +40,9 @@ async function render(App, id) {
38
40
  };
39
41
  if (isClientArgs(id)) {
40
42
  var _ssrData_data, _ssrData_data1;
43
+ window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
44
+ const routeData = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
45
+ window._ROUTER_DATA = window._ROUTER_DATA || routeData;
41
46
  const ssrData = getSSRData();
42
47
  const loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
43
48
  const initialLoadersState = Object.keys(loadersData).reduce((res, key) => {
@@ -66,9 +71,7 @@ async function render(App, id) {
66
71
  const rootElement = id && typeof id !== "string" ? id : document.getElementById(id || "root");
67
72
  async function ModernRender(App2) {
68
73
  const renderFunc = IS_REACT18 ? renderWithReact18 : renderWithReact17;
69
- return renderFunc(/* @__PURE__ */ React.cloneElement(App2, {
70
- _internal_context: context
71
- }), rootElement);
74
+ return renderFunc(App2, rootElement);
72
75
  }
73
76
  async function ModernHydrate(App2, callback) {
74
77
  const hydrateFunc = IS_REACT18 ? hydrateWithReact18 : hydrateWithReact17;
@@ -77,7 +80,7 @@ async function render(App, id) {
77
80
  if (ssrData) {
78
81
  return hydrateRoot(App, context, ModernRender, ModernHydrate);
79
82
  }
80
- return ModernRender(App);
83
+ return ModernRender(wrapRuntimeContextProvider(App, context));
81
84
  }
82
85
  throw Error("`render` function needs id in browser environment, it needs to be string or element");
83
86
  }
@@ -7,6 +7,7 @@ import { createLoaderManager } from "./loader/loaderManager";
7
7
  import { getGlobalRunner } from "./plugin/runner";
8
8
  import { getGlobalAppInit } from "./context";
9
9
  import { hydrateRoot as ModernHydrateRoot } from "./browser/hydrate";
10
+ import { wrapRuntimeContextProvider } from "./react/wrapper";
10
11
  const IS_REACT18 = process.env.IS_REACT18 === "true";
11
12
  function isClientArgs(id) {
12
13
  return typeof id === "string" || typeof HTMLElement !== "undefined" && id instanceof HTMLElement;
@@ -31,23 +32,13 @@ const createApp = ({ plugins, runtime, props: globalProps }) => {
31
32
  }) : child));
32
33
  };
33
34
  const WrapperApp = runner.wrapRoot(WrapperComponent);
34
- const WrapComponent = ({ _internal_context, ...props }) => {
35
- let contextValue = _internal_context;
36
- if (!(contextValue === null || contextValue === void 0 ? void 0 : contextValue.runner)) {
37
- var _getGlobalAppInit;
38
- contextValue = getInitialContext(runner);
39
- runner === null || runner === void 0 ? void 0 : runner.beforeRender(contextValue);
40
- (_getGlobalAppInit = getGlobalAppInit()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(contextValue);
41
- }
35
+ const WrapComponent = (props) => {
42
36
  const mergedProps = {
43
37
  ...props,
44
38
  ...globalProps
45
39
  };
46
- return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
47
- value: contextValue,
48
- children: /* @__PURE__ */ _jsx(WrapperApp, {
49
- ...mergedProps
50
- })
40
+ return /* @__PURE__ */ _jsx(WrapperApp, {
41
+ ...mergedProps
51
42
  });
52
43
  };
53
44
  return WrapComponent;
@@ -63,9 +54,7 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
63
54
  return init === null || init === void 0 ? void 0 : init(context2);
64
55
  };
65
56
  if (!id) {
66
- return /* @__PURE__ */ React.createElement(App, {
67
- _internal_context: context
68
- });
57
+ return wrapRuntimeContextProvider(/* @__PURE__ */ _jsx(App, {}), context);
69
58
  }
70
59
  const isBrowser = typeof window !== "undefined" && window.name !== "nodejs";
71
60
  if (isBrowser) {
@@ -136,9 +125,7 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
136
125
  if (ssrData) {
137
126
  return ModernHydrateRoot(/* @__PURE__ */ _jsx(App, {}), context, ModernRender, ModernHydrate);
138
127
  }
139
- return ModernRender(/* @__PURE__ */ React.createElement(App, {
140
- _internal_context: context
141
- }));
128
+ return ModernRender(wrapRuntimeContextProvider(/* @__PURE__ */ _jsx(App, {}), context));
142
129
  } else {
143
130
  throw Error("`bootstrap` needs id in browser environment, it needs to be string or element");
144
131
  }
@@ -4,6 +4,10 @@ var RenderLevel;
4
4
  RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
5
5
  RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
6
6
  })(RenderLevel || (RenderLevel = {}));
7
+ const SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
8
+ const ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
7
9
  export {
8
- RenderLevel
10
+ ROUTER_DATA_JSON_ID,
11
+ RenderLevel,
12
+ SSR_DATA_JSON_ID
9
13
  };
@@ -1,4 +1,4 @@
1
- import { RuntimeReactContext } from "./runtime";
1
+ import { RuntimeReactContext, getInitialContext } from "./runtime";
2
2
  const globalContext = {};
3
3
  function setGlobalContext(context) {
4
4
  globalContext.App = context.App;
@@ -31,5 +31,6 @@ export {
31
31
  getGlobalAppInit,
32
32
  getGlobalLayoutApp,
33
33
  getGlobalRoutes,
34
+ getInitialContext,
34
35
  setGlobalContext
35
36
  };
@@ -1,19 +1,10 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { RuntimeReactContext, getGlobalApp } from "../context";
1
+ import { getGlobalApp } from "../context";
3
2
  import { getGlobalRunner } from "../plugin/runner";
4
3
  function createRoot(UserApp) {
5
4
  const App = UserApp || getGlobalApp();
6
5
  const runner = getGlobalRunner();
7
6
  const WrapperApp = runner.wrapRoot(App);
8
- const WrapComponent = ({ _internal_context, ...props }) => {
9
- return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
10
- value: _internal_context,
11
- children: /* @__PURE__ */ _jsx(WrapperApp, {
12
- ...props
13
- })
14
- });
15
- };
16
- return WrapComponent;
7
+ return WrapperApp;
17
8
  }
18
9
  export {
19
10
  createRoot
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { RuntimeReactContext } from "../context";
3
+ function wrapRuntimeContextProvider(App, contextValue) {
4
+ return /* @__PURE__ */ React.createElement(RuntimeReactContext.Provider, {
5
+ value: contextValue
6
+ }, App);
7
+ }
8
+ export {
9
+ wrapRuntimeContextProvider
10
+ };
@@ -2,13 +2,9 @@ const HTML_PLACEHOLDER = "<!--<?- html ?>-->";
2
2
  const SSR_DATA_PLACEHOLDER = "<!--<?- SSRDataScript ?>-->";
3
3
  const CHUNK_JS_PLACEHOLDER = "<!--<?- chunksMap.js ?>-->";
4
4
  const CHUNK_CSS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
5
- const SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
6
- const ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
7
5
  export {
8
6
  CHUNK_CSS_PLACEHOLDER,
9
7
  CHUNK_JS_PLACEHOLDER,
10
8
  HTML_PLACEHOLDER,
11
- ROUTER_DATA_JSON_ID,
12
- SSR_DATA_JSON_ID,
13
9
  SSR_DATA_PLACEHOLDER
14
10
  };
@@ -1,7 +1,7 @@
1
1
  import { time } from "@modern-js/runtime-utils/time";
2
2
  import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
3
3
  import { run } from "@modern-js/runtime-utils/node";
4
- import React from "react";
4
+ import { wrapRuntimeContextProvider } from "../../react/wrapper";
5
5
  import { SSRErrors, SSRTimings, createOnError, createOnTiming } from "../tracer";
6
6
  import { getSSRConfigByEntry } from "../utils";
7
7
  var ShellChunkStatus;
@@ -38,11 +38,9 @@ function createRenderStreaming(createReadableStreamFromElement) {
38
38
  const onTiming = createOnTiming(options.onTiming);
39
39
  const { htmlTemplate, entryName } = resource;
40
40
  const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
41
- const rootElement = React.cloneElement(serverRoot, {
42
- _internal_context: Object.assign(runtimeContext, {
43
- ssr: true
44
- })
45
- });
41
+ const rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
42
+ ssr: true
43
+ }));
46
44
  const stream = await createReadableStreamFromElement(request, rootElement, {
47
45
  config,
48
46
  htmlTemplate,
@@ -1,9 +1,9 @@
1
1
  import ReactHelmet from "react-helmet";
2
2
  import ReactDomServer from "react-dom/server";
3
- import React from "react";
4
3
  import { time } from "@modern-js/runtime-utils/time";
5
4
  import { run } from "@modern-js/runtime-utils/node";
6
5
  import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
6
+ import { wrapRuntimeContextProvider } from "../../react/wrapper";
7
7
  import { createReplaceHelemt } from "../helmet";
8
8
  import { getSSRConfigByEntry, safeReplace } from "../utils";
9
9
  import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants";
@@ -61,11 +61,9 @@ const renderString = async (request, serverRoot, options) => {
61
61
  nonce: config.nonce
62
62
  })
63
63
  ];
64
- const rootElement = React.cloneElement(serverRoot, {
65
- _internal_context: Object.assign(runtimeContext, {
66
- ssr: true
67
- })
68
- });
64
+ const rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
65
+ ssr: true
66
+ }));
69
67
  const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, ((_runtimeContext_ssrContext = runtimeContext.ssrContext) === null || _runtimeContext_ssrContext === void 0 ? void 0 : _runtimeContext_ssrContext.htmlModifiers) || [], tracer);
70
68
  return html;
71
69
  });
@@ -3,7 +3,7 @@ import { run } from "@modern-js/runtime-utils/node";
3
3
  import { ChunkExtractor } from "@loadable/server";
4
4
  import { time } from "@modern-js/runtime-utils/time";
5
5
  import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
6
- import React from "react";
6
+ import { wrapRuntimeContextProvider } from "../../react/wrapper";
7
7
  import { SSRErrors, SSRTimings } from "../tracer";
8
8
  const prefetch = async (App, request, options, ssrConfig, { onError, onTiming }) => {
9
9
  const headersData = parseHeaders(request);
@@ -21,17 +21,13 @@ const prefetch = async (App, request, options, ssrConfig, { onError, onTiming })
21
21
  entryName
22
22
  ].filter(Boolean)
23
23
  });
24
- renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ React.cloneElement(App, {
25
- _internal_context: Object.assign(context, {
26
- ssr: false
27
- })
28
- })));
24
+ renderToStaticMarkup(extractor.collectChunks(wrapRuntimeContextProvider(App, Object.assign(context, {
25
+ ssr: false
26
+ }))));
29
27
  } else {
30
- renderToStaticMarkup(/* @__PURE__ */ React.cloneElement(App, {
31
- _internal_context: Object.assign(context, {
32
- ssr: false
33
- })
34
- }));
28
+ renderToStaticMarkup(wrapRuntimeContextProvider(App, Object.assign(context, {
29
+ ssr: false
30
+ })));
35
31
  }
36
32
  const cost = end();
37
33
  onTiming(SSRTimings.PRERENDER, cost);
@@ -5,7 +5,7 @@ import { _ as _class_private_method_get } from "@swc/helpers/_/_class_private_me
5
5
  import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_method_init";
6
6
  import { serializeJson } from "@modern-js/runtime-utils/node";
7
7
  import { attributesToString, serializeErrors } from "../utils";
8
- import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
8
+ import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants";
9
9
  var _options = /* @__PURE__ */ new WeakMap(), _getSSRData = /* @__PURE__ */ new WeakSet(), _getSSRDataScripts = /* @__PURE__ */ new WeakSet();
10
10
  class SSRDataCollector {
11
11
  effect() {
@@ -11,7 +11,7 @@ export type CreateAppOptions = {
11
11
  runtime?: typeof runtime;
12
12
  props?: any;
13
13
  };
14
- export declare const createApp: ({ plugins, runtime, props: globalProps, }: CreateAppOptions) => (App?: React.ComponentType<any>) => ({ _internal_context, ...props }: any) => JSX.Element;
14
+ export declare const createApp: ({ plugins, runtime, props: globalProps, }: CreateAppOptions) => (App?: React.ComponentType<any>) => (props: any) => JSX.Element;
15
15
  type BootStrap<T = unknown> = (App: React.ComponentType, id: string | HTMLElement | RuntimeContext, root?: any, ReactDOM?: {
16
16
  render?: Renderer;
17
17
  hydrate?: Renderer;
@@ -3,3 +3,5 @@ export declare enum RenderLevel {
3
3
  SERVER_PREFETCH = 1,
4
4
  SERVER_RENDER = 2
5
5
  }
6
+ export declare const SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
7
+ export declare const ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { NestedRoute, PageRoute } from '@modern-js/types';
3
3
  import { AppConfig } from '../../common';
4
- export { RuntimeReactContext, type RuntimeContext } from './runtime';
4
+ export { RuntimeReactContext, type RuntimeContext, getInitialContext, } from './runtime';
5
5
  interface GlobalContext {
6
6
  /**
7
7
  * App.tsx export default component
@@ -1,2 +1,2 @@
1
1
  import React from 'react';
2
- export declare function createRoot(UserApp?: React.ComponentType | null): ({ _internal_context, ...props }: any) => JSX.Element;
2
+ export declare function createRoot(UserApp?: React.ComponentType | null): React.ComponentType<any>;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { RuntimeContext } from '../context';
3
+ export declare function wrapRuntimeContextProvider(App: React.ReactElement, contextValue: RuntimeContext): React.FunctionComponentElement<React.ProviderProps<RuntimeContext>>;
@@ -2,5 +2,3 @@ export declare const HTML_PLACEHOLDER = "<!--<?- html ?>-->";
2
2
  export declare const SSR_DATA_PLACEHOLDER = "<!--<?- SSRDataScript ?>-->";
3
3
  export declare const CHUNK_JS_PLACEHOLDER = "<!--<?- chunksMap.js ?>-->";
4
4
  export declare const CHUNK_CSS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
5
- export declare const SSR_DATA_JSON_ID = "__MODERN_SSR_DATA__";
6
- export declare const ROUTER_DATA_JSON_ID = "__MODERN_ROUTER_DATA__";
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.57.1",
18
+ "version": "2.57.2-alpha.1",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -201,16 +201,16 @@
201
201
  "@swc/helpers": "0.5.3",
202
202
  "@modern-js/plugin": "2.57.1",
203
203
  "@modern-js/types": "2.57.1",
204
+ "@modern-js/runtime-utils": "2.57.1",
204
205
  "@modern-js/plugin-data-loader": "2.57.1",
205
- "@modern-js/utils": "2.57.1",
206
- "@modern-js/runtime-utils": "2.57.1"
206
+ "@modern-js/utils": "2.57.1"
207
207
  },
208
208
  "peerDependencies": {
209
209
  "react": ">=17",
210
210
  "react-dom": ">=17"
211
211
  },
212
212
  "devDependencies": {
213
- "@rsbuild/core": "1.0.1-beta.3",
213
+ "@rsbuild/core": "1.0.1-beta.9",
214
214
  "@types/cookie": "0.5.1",
215
215
  "@remix-run/web-fetch": "^4.1.3",
216
216
  "@testing-library/react": "^13.4.0",
@@ -234,8 +234,7 @@
234
234
  "sideEffects": false,
235
235
  "publishConfig": {
236
236
  "registry": "https://registry.npmjs.org/",
237
- "access": "public",
238
- "provenance": true
237
+ "access": "public"
239
238
  },
240
239
  "scripts": {
241
240
  "dev": "modern-lib build --watch",