@modern-js/runtime 2.5.0 → 2.7.0

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 (148) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/cjs/cli/index.js +9 -0
  3. package/dist/cjs/common.js +6 -0
  4. package/dist/cjs/core/{app-config.js → appConfig.js} +8 -4
  5. package/dist/cjs/core/compatible.js +11 -10
  6. package/dist/cjs/core/index.js +6 -6
  7. package/dist/cjs/core/loader/index.js +4 -0
  8. package/dist/cjs/core/loader/loaderManager.js +6 -0
  9. package/dist/cjs/core/loader/useLoader.js +6 -2
  10. package/dist/cjs/core/types.js +15 -0
  11. package/dist/cjs/document/Body.js +6 -8
  12. package/dist/cjs/document/DocumentContext.js +4 -0
  13. package/dist/cjs/document/DocumentStructureContext.js +4 -0
  14. package/dist/cjs/document/Head.js +7 -11
  15. package/dist/cjs/document/Html.js +24 -22
  16. package/dist/cjs/document/Links.js +1 -3
  17. package/dist/cjs/document/Root.js +8 -14
  18. package/dist/cjs/document/Script.js +5 -7
  19. package/dist/cjs/document/Scripts.js +1 -3
  20. package/dist/cjs/document/cli/index.js +8 -2
  21. package/dist/cjs/exports/head.js +4 -0
  22. package/dist/cjs/exports/loadable.js +4 -0
  23. package/dist/cjs/exports/styled.js +4 -0
  24. package/dist/cjs/router/cli/index.js +3 -7
  25. package/dist/cjs/router/index.js +4 -0
  26. package/dist/cjs/router/runtime/DefaultNotFound.js +13 -10
  27. package/dist/cjs/router/runtime/DeferredDataScripts.js +165 -0
  28. package/dist/cjs/router/runtime/index.js +116 -3
  29. package/dist/cjs/router/runtime/plugin.js +18 -6
  30. package/dist/cjs/router/runtime/plugin.node.js +16 -49
  31. package/dist/cjs/router/runtime/utils.js +79 -101
  32. package/dist/cjs/router/runtime/withRouter.js +9 -6
  33. package/dist/cjs/{runtime-context.js → runtimeContext.js} +3 -3
  34. package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +4 -0
  35. package/dist/cjs/ssr/cli/index.js +6 -0
  36. package/dist/cjs/ssr/index.js +10 -24
  37. package/dist/cjs/ssr/index.node.js +5 -0
  38. package/dist/cjs/ssr/prefetch.js +3 -6
  39. package/dist/cjs/ssr/react/nossr/index.js +4 -0
  40. package/dist/cjs/ssr/react/prerender/index.js +4 -0
  41. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +7 -13
  42. package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -0
  43. package/dist/cjs/ssr/serverRender/renderToStream/index.js +4 -0
  44. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +22 -7
  45. package/dist/cjs/ssr/serverRender/renderToStream/template.js +2 -1
  46. package/dist/cjs/ssr/serverRender/renderToString/entry.js +28 -11
  47. package/dist/cjs/ssr/serverRender/renderToString/index.js +4 -0
  48. package/dist/cjs/ssr/serverRender/renderToString/loadable.js +1 -1
  49. package/dist/cjs/ssr/serverRender/time.worker.js +1 -1
  50. package/dist/cjs/ssr/serverRender/utils.js +1 -1
  51. package/dist/cjs/ssr/utils.js +16 -4
  52. package/dist/cjs/state/index.js +4 -0
  53. package/dist/cjs/state/plugins.js +4 -0
  54. package/dist/cjs/state/runtime/index.js +4 -0
  55. package/dist/cjs/state/runtime/plugin.js +5 -7
  56. package/dist/esm/cli/index.js +5 -1
  57. package/dist/esm/common.js +3 -1
  58. package/dist/esm/core/{app-config.js → appConfig.js} +3 -1
  59. package/dist/esm/core/compatible.js +4 -2
  60. package/dist/esm/core/index.js +2 -2
  61. package/dist/esm/core/loader/loaderManager.js +3 -1
  62. package/dist/esm/core/loader/useLoader.js +1 -1
  63. package/dist/esm/core/types.js +1 -0
  64. package/dist/esm/document/cli/index.js +4 -2
  65. package/dist/esm/router/cli/index.js +1 -5
  66. package/dist/esm/router/runtime/DeferredDataScripts.js +166 -0
  67. package/dist/esm/router/runtime/index.js +3 -2
  68. package/dist/esm/router/runtime/plugin.js +11 -3
  69. package/dist/esm/router/runtime/plugin.node.js +11 -68
  70. package/dist/esm/router/runtime/utils.js +138 -81
  71. package/dist/esm/ssr/cli/index.js +2 -0
  72. package/dist/esm/ssr/index.node.js +1 -0
  73. package/dist/esm/ssr/prefetch.js +1 -0
  74. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +37 -10
  75. package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -0
  76. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +19 -8
  77. package/dist/esm/ssr/serverRender/renderToStream/template.js +2 -1
  78. package/dist/esm/ssr/serverRender/renderToString/entry.js +37 -13
  79. package/dist/esm/ssr/serverRender/time.worker.js +1 -1
  80. package/dist/esm/ssr/utils.js +6 -4
  81. package/dist/esm-node/cli/index.js +5 -0
  82. package/dist/esm-node/common.js +4 -0
  83. package/dist/esm-node/core/{app-config.js → appConfig.js} +5 -1
  84. package/dist/esm-node/core/compatible.js +5 -8
  85. package/dist/esm-node/core/index.js +2 -2
  86. package/dist/esm-node/core/loader/loaderManager.js +2 -0
  87. package/dist/esm-node/core/loader/useLoader.js +1 -1
  88. package/dist/esm-node/core/types.js +0 -0
  89. package/dist/esm-node/document/Body.js +6 -8
  90. package/dist/esm-node/document/Head.js +7 -11
  91. package/dist/esm-node/document/Html.js +24 -22
  92. package/dist/esm-node/document/Links.js +1 -3
  93. package/dist/esm-node/document/Root.js +8 -14
  94. package/dist/esm-node/document/Script.js +5 -7
  95. package/dist/esm-node/document/Scripts.js +1 -3
  96. package/dist/esm-node/document/cli/index.js +4 -2
  97. package/dist/esm-node/router/cli/index.js +2 -5
  98. package/dist/esm-node/router/runtime/DefaultNotFound.js +13 -10
  99. package/dist/esm-node/router/runtime/DeferredDataScripts.js +148 -0
  100. package/dist/esm-node/router/runtime/index.js +113 -2
  101. package/dist/esm-node/router/runtime/plugin.js +15 -7
  102. package/dist/esm-node/router/runtime/plugin.node.js +12 -52
  103. package/dist/esm-node/router/runtime/utils.js +70 -101
  104. package/dist/esm-node/router/runtime/withRouter.js +9 -6
  105. package/dist/esm-node/ssr/cli/index.js +2 -0
  106. package/dist/esm-node/ssr/index.js +6 -24
  107. package/dist/esm-node/ssr/index.node.js +1 -0
  108. package/dist/esm-node/ssr/prefetch.js +3 -6
  109. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +7 -7
  110. package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -0
  111. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +22 -7
  112. package/dist/esm-node/ssr/serverRender/renderToStream/template.js +2 -1
  113. package/dist/esm-node/ssr/serverRender/renderToString/entry.js +24 -11
  114. package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +1 -1
  115. package/dist/esm-node/ssr/serverRender/time.worker.js +1 -1
  116. package/dist/esm-node/ssr/serverRender/utils.js +1 -1
  117. package/dist/esm-node/ssr/utils.js +6 -4
  118. package/dist/esm-node/state/runtime/plugin.js +1 -7
  119. package/dist/types/common.d.ts +3 -1
  120. package/dist/types/core/compatible.d.ts +1 -1
  121. package/dist/types/core/index.d.ts +4 -3
  122. package/dist/types/core/loader/index.d.ts +1 -2
  123. package/dist/types/core/loader/useLoader.d.ts +1 -15
  124. package/dist/types/core/plugin.d.ts +15 -15
  125. package/dist/types/core/types.d.ts +22 -0
  126. package/dist/types/index.d.ts +1 -1
  127. package/dist/types/router/runtime/DeferredDataScripts.d.ts +8 -0
  128. package/dist/types/router/runtime/index.d.ts +4 -2
  129. package/dist/types/router/runtime/utils.d.ts +23 -4
  130. package/dist/types/{runtime-context.d.ts → runtimeContext.d.ts} +2 -0
  131. package/dist/types/ssr/serverRender/renderToStream/buildTemplate.after.d.ts +2 -0
  132. package/dist/types/ssr/serverRender/renderToString/type.d.ts +1 -0
  133. package/package.json +14 -15
  134. package/dist/cjs/ssr/prefetch.worker.js +0 -67
  135. package/dist/cjs/ssr/serverRender/renderToStream/index.worker.js +0 -64
  136. package/dist/cjs/ssr/serverRender/renderToString/index.worker.js +0 -58
  137. package/dist/esm/ssr/prefetch.worker.js +0 -191
  138. package/dist/esm/ssr/serverRender/renderToStream/index.worker.js +0 -32
  139. package/dist/esm/ssr/serverRender/renderToString/index.worker.js +0 -167
  140. package/dist/esm-node/ssr/prefetch.worker.js +0 -46
  141. package/dist/esm-node/ssr/serverRender/renderToStream/index.worker.js +0 -35
  142. package/dist/esm-node/ssr/serverRender/renderToString/index.worker.js +0 -29
  143. package/dist/types/ssr/prefetch.worker.d.ts +0 -13
  144. package/dist/types/ssr/serverRender/renderToStream/index.worker.d.ts +0 -6
  145. package/dist/types/ssr/serverRender/renderToString/index.worker.d.ts +0 -6
  146. /package/dist/esm/{runtime-context.js → runtimeContext.js} +0 -0
  147. /package/dist/esm-node/{runtime-context.js → runtimeContext.js} +0 -0
  148. /package/dist/types/core/{app-config.d.ts → appConfig.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dcad887024: feat: support deferred data for streaming ssr
8
+ feat: 流式渲染支持 deferred data
9
+
10
+ ### Patch Changes
11
+
12
+ - a4672f7c16: fix: lock @modern-js/utils/ssr by webpack alias
13
+ fix: 通过 webpack 别名将 @modern-js/utils/ssr 锁到同一版本
14
+ - 7fff9020e1: chore: make file naming consistent
15
+
16
+ chore: 统一文件命名为小驼峰格式
17
+
18
+ - 1eea234fdd: chore: make test files naming consistent
19
+
20
+ chore: 统一测试文件命名为小驼峰格式
21
+
22
+ - Updated dependencies [0f15fc597c]
23
+ - Updated dependencies [dcad887024]
24
+ - Updated dependencies [a4672f7c16]
25
+ - Updated dependencies [7fff9020e1]
26
+ - Updated dependencies [84bfb439b8]
27
+ - @modern-js/utils@2.7.0
28
+ - @modern-js/types@2.7.0
29
+ - @modern-js/plugin@2.7.0
30
+
31
+ ## 2.6.0
32
+
33
+ ### Patch Changes
34
+
35
+ - 671477d: chore(CI): make CI faster
36
+
37
+ chore(CI): 提升 CI 执行速度
38
+
39
+ - 7915ab3: fix: should not assign nestedRoutesEntry to entrypoint if use v5 router
40
+ fix: 使用 v5 路由的时候,不应该在 entrypoint 上挂载 nestedRoutesEntry 属性
41
+ - a909ad1: feat: revert worker use async_hooks
42
+
43
+ feat: 还原 worker 使用 async_hooks 代码
44
+
45
+ - 49fa0b1: fix: remove header info from SSR ctx to avoid security issues, reserved a switch
46
+ fix: 移除 SSR 上下文中的 header 信息,避免造成安全问题,预留一个字段开启
47
+ - 1906d7b: fix: document param output get undefined in default template
48
+ fix: 修复 Document param 中 output 参数取值问题
49
+ - Updated dependencies [e1f799e]
50
+ - Updated dependencies [7915ab3]
51
+ - Updated dependencies [49fa0b1]
52
+ - Updated dependencies [0fe658a]
53
+ - Updated dependencies [62930b9]
54
+ - @modern-js/utils@2.6.0
55
+ - @modern-js/types@2.6.0
56
+ - @modern-js/plugin@2.6.0
57
+
3
58
  ## 2.5.0
4
59
 
5
60
  ### Patch Changes
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -52,6 +56,11 @@ var cli_default = () => ({
52
56
  runtimeByEntries: {},
53
57
  source: {
54
58
  alias: {
59
+ /**
60
+ * twin.macro inserts styled-components into the code during the compilation process
61
+ * But it will not be installed under the user project.
62
+ * So need to add alias
63
+ */
55
64
  "styled-components": require.resolve("styled-components")
56
65
  },
57
66
  globalVars: {
@@ -17,11 +17,17 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var common_exports = {};
19
19
  __export(common_exports, {
20
+ ESCAPED_SHELL_STREAM_END_MARK: () => ESCAPED_SHELL_STREAM_END_MARK,
21
+ JSX_SHELL_STREAM_END_MARK: () => JSX_SHELL_STREAM_END_MARK,
20
22
  isBrowser: () => isBrowser
21
23
  });
22
24
  module.exports = __toCommonJS(common_exports);
23
25
  const isBrowser = () => typeof window !== "undefined" && window.name !== "nodejs";
26
+ const JSX_SHELL_STREAM_END_MARK = "<!--<?- SHELL_STREAM_END ?>-->";
27
+ const ESCAPED_SHELL_STREAM_END_MARK = "&lt;!--&lt;?- SHELL_STREAM_END ?&gt;--&gt;";
24
28
  // Annotate the CommonJS export names for ESM import in node:
25
29
  0 && (module.exports = {
30
+ ESCAPED_SHELL_STREAM_END_MARK,
31
+ JSX_SHELL_STREAM_END_MARK,
26
32
  isBrowser
27
33
  });
@@ -15,14 +15,18 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var app_config_exports = {};
19
- __export(app_config_exports, {
18
+ var appConfig_exports = {};
19
+ __export(appConfig_exports, {
20
20
  defineConfig: () => defineConfig,
21
21
  getConfig: () => getConfig
22
22
  });
23
- module.exports = __toCommonJS(app_config_exports);
23
+ module.exports = __toCommonJS(appConfig_exports);
24
24
  const APP_CONFIG_SYMBOL = "config";
25
- const getConfig = (Component) => Component[APP_CONFIG_SYMBOL];
25
+ const getConfig = (Component) => (
26
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
27
+ // @ts-expect-error
28
+ Component[APP_CONFIG_SYMBOL]
29
+ );
26
30
  const defineConfig = (Component, config) => {
27
31
  Component[APP_CONFIG_SYMBOL] = config;
28
32
  return Component;
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -32,7 +36,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
32
36
  var import_react = __toESM(require("react"));
33
37
  var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
34
38
  var import_constants = require("@modern-js/utils/constants");
35
- var import_runtime_context = require("../runtime-context");
39
+ var import_runtimeContext = require("../runtimeContext");
36
40
  var import_plugin = require("./plugin");
37
41
  var import_loaderManager = require("./loader/loaderManager");
38
42
  const IS_REACT18 = process.env.IS_REACT18 === "true";
@@ -57,7 +61,7 @@ const createApp = ({ plugins }) => {
57
61
  { ...props },
58
62
  props.children
59
63
  );
60
- const context = (0, import_react.useContext)(import_runtime_context.RuntimeReactContext);
64
+ const context = (0, import_react.useContext)(import_runtimeContext.RuntimeReactContext);
61
65
  return runner.provide(
62
66
  { element, props: { ...props }, context },
63
67
  {
@@ -86,12 +90,7 @@ const createApp = ({ plugins }) => {
86
90
  }
87
91
  );
88
92
  }
89
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_runtime_context.RuntimeReactContext.Provider, {
90
- value: contextValue,
91
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App2, {
92
- ...props
93
- })
94
- });
93
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_runtimeContext.RuntimeReactContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App2, { ...props }) });
95
94
  };
96
95
  return (0, import_hoist_non_react_statics.default)(WrapComponent, App2);
97
96
  }
@@ -218,12 +217,14 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
218
217
  {},
219
218
  {
220
219
  skipNonStatic: id.staticGenerate,
220
+ // if not static generate, only non-static loader can exec on prod env
221
221
  skipStatic: process.env.NODE_ENV === "production" && !id.staticGenerate
222
222
  }
223
223
  )
224
224
  });
225
225
  const isRedirectResponse = (result) => {
226
- if (typeof Response !== "undefined" && result instanceof Response && result.status >= 300 && result.status <= 399) {
226
+ if (typeof Response !== "undefined" && // fix: ssg workflow doesn't inject Web Response
227
+ result instanceof Response && result.status >= 300 && result.status <= 399) {
227
228
  const { status } = result;
228
229
  const redirectUrl = result.headers.get("Location") || "/";
229
230
  const { ssrContext } = context;
@@ -249,7 +250,7 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
249
250
  }
250
251
  };
251
252
  const useRuntimeContext = () => {
252
- const context = (0, import_react.useContext)(import_runtime_context.RuntimeReactContext);
253
+ const context = (0, import_react.useContext)(import_runtimeContext.RuntimeReactContext);
253
254
  const memoizedContext = (0, import_react.useMemo)(
254
255
  () => context.runner.pickContext(
255
256
  { context, pickedContext: {} },
@@ -18,20 +18,20 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var core_exports = {};
20
20
  __export(core_exports, {
21
- RuntimeReactContext: () => import_runtime_context.RuntimeReactContext,
22
- ServerRouterContext: () => import_runtime_context.ServerRouterContext,
21
+ RuntimeReactContext: () => import_runtimeContext.RuntimeReactContext,
22
+ ServerRouterContext: () => import_runtimeContext.ServerRouterContext,
23
23
  createPlugin: () => import_plugin.createPlugin,
24
24
  createRuntime: () => import_plugin.createRuntime,
25
- defineConfig: () => import_app_config.defineConfig,
26
- getConfig: () => import_app_config.getConfig,
25
+ defineConfig: () => import_appConfig.defineConfig,
26
+ getConfig: () => import_appConfig.getConfig,
27
27
  registerInit: () => import_plugin.registerInit,
28
28
  runtime: () => import_plugin.runtime
29
29
  });
30
30
  module.exports = __toCommonJS(core_exports);
31
31
  var import_plugin = require("./plugin");
32
- var import_app_config = require("./app-config");
32
+ var import_appConfig = require("./appConfig");
33
33
  __reExport(core_exports, require("./compatible"), module.exports);
34
- var import_runtime_context = require("../runtime-context");
34
+ var import_runtimeContext = require("../runtimeContext");
35
35
  __reExport(core_exports, require("./loader"), module.exports);
36
36
  __reExport(core_exports, require("@modern-js/plugin"), module.exports);
37
37
  // Annotate the CommonJS export names for ESM import in node:
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -88,6 +92,7 @@ const createLoader = (id, initialData = {
88
92
  reloading: hasLoaded && status === 1 /* loading */,
89
93
  data,
90
94
  error: error instanceof Error ? `${error.message}` : error,
95
+ // redundant fields for ssr log
91
96
  _error: error
92
97
  });
93
98
  const notify = () => {
@@ -128,6 +133,7 @@ const createLoaderManager = (initialDataMap, managerOptions = {}) => {
128
133
  id,
129
134
  typeof initialDataMap[id] !== "undefined" ? initialDataMap[id] : { data: loaderOptions.initialData },
130
135
  loaderFn,
136
+ // Todo whether static loader is exec when CSR
131
137
  skipExec
132
138
  );
133
139
  loadersMap.set(id, loader);
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -28,10 +32,10 @@ __export(useLoader_exports, {
28
32
  module.exports = __toCommonJS(useLoader_exports);
29
33
  var import_react = require("react");
30
34
  var import_invariant = __toESM(require("invariant"));
31
- var import_runtime_context = require("../../runtime-context");
35
+ var import_runtimeContext = require("../../runtimeContext");
32
36
  var import_loaderManager = require("./loaderManager");
33
37
  const useLoader = (loaderFn, options = { params: void 0 }) => {
34
- const context = (0, import_react.useContext)(import_runtime_context.RuntimeReactContext);
38
+ const context = (0, import_react.useContext)(import_runtimeContext.RuntimeReactContext);
35
39
  const isSSRRender = Boolean(context.ssr);
36
40
  const { loaderManager } = context;
37
41
  const loaderRef = (0, import_react.useRef)();
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
@@ -28,14 +28,12 @@ var import_Root = require("./Root");
28
28
  function Body(props) {
29
29
  const { hasSetRoot } = (0, import_react.useContext)(import_DocumentStructureContext.DocumentStructureContext);
30
30
  const { children } = props;
31
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", {
32
- children: [
33
- hasSetRoot ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Root.DefaultRoot, {}),
34
- children,
35
- `${import_constants.DOCUMENT_CHUNKSMAP_PLACEHOLDER}`,
36
- `${import_constants.DOCUMENT_SSRDATASCRIPT_PLACEHOLDER}`
37
- ]
38
- });
31
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", { children: [
32
+ hasSetRoot ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Root.DefaultRoot, {}),
33
+ children,
34
+ `${import_constants.DOCUMENT_CHUNKSMAP_PLACEHOLDER}`,
35
+ `${import_constants.DOCUMENT_SSRDATASCRIPT_PLACEHOLDER}`
36
+ ] });
39
37
  }
40
38
  // Annotate the CommonJS export names for ESM import in node:
41
39
  0 && (module.exports = {
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -30,19 +30,15 @@ var import_constants = require("./constants");
30
30
  function Head(props) {
31
31
  const { hasSetScripts, hasSetLinks } = (0, import_react.useContext)(import_DocumentStructureContext.DocumentStructureContext);
32
32
  const { children } = props;
33
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("head", {
34
- children: [
35
- `${import_constants.DOCUMENT_META_PLACEHOLDER}`,
36
- !hasSetLinks && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Links.Links, {}),
37
- !hasSetScripts && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Scripts.Scripts, {}),
38
- children
39
- ]
40
- });
33
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("head", { children: [
34
+ `${import_constants.DOCUMENT_META_PLACEHOLDER}`,
35
+ !hasSetLinks && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Links.Links, {}),
36
+ !hasSetScripts && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Scripts.Scripts, {}),
37
+ children
38
+ ] });
41
39
  }
42
40
  function DefaultHead() {
43
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("head", {
44
- children: `${import_constants.DOCUMENT_META_PLACEHOLDER}`
45
- });
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("head", { children: `${import_constants.DOCUMENT_META_PLACEHOLDER}` });
46
42
  }
47
43
  // Annotate the CommonJS export names for ESM import in node:
48
44
  0 && (module.exports = {
@@ -56,29 +56,31 @@ function Html(props) {
56
56
  const notMissMustChild = [
57
57
  hasSetHead,
58
58
  hasSetBody
59
+ // hasSetScripts,
60
+ // hasSetRoot,
59
61
  ].every((item) => item);
60
62
  if (!notMissMustChild) {
61
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("html", {
62
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", {
63
- style: { color: "red" },
64
- children: [
65
- `Miss the `,
66
- [
67
- hasSetHead,
68
- hasSetBody
69
- ].map((item, index) => {
70
- return item ? null : [
71
- "Head",
72
- "Body"
73
- ][index];
74
- }),
75
- ` Element`
76
- ]
77
- })
78
- });
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("html", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", { style: { color: "red" }, children: [
64
+ `Miss the `,
65
+ [
66
+ hasSetHead,
67
+ hasSetBody
68
+ // hasSetScripts,
69
+ // hasSetRoot,
70
+ ].map((item, index) => {
71
+ return item ? null : [
72
+ "Head",
73
+ "Body"
74
+ // 'Scripts',
75
+ // 'Root',
76
+ ][index];
77
+ }),
78
+ ` Element`
79
+ ] }) });
79
80
  }
80
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("html", {
81
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_DocumentStructureContext.DocumentStructureContext.Provider, {
81
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("html", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
82
+ import_DocumentStructureContext.DocumentStructureContext.Provider,
83
+ {
82
84
  value: {
83
85
  hasSetHead,
84
86
  hasSetScripts,
@@ -92,8 +94,8 @@ function Html(props) {
92
94
  !hasSetBody && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Body.Body, {}),
93
95
  children
94
96
  ]
95
- })
96
- });
97
+ }
98
+ ) });
97
99
  }
98
100
  // Annotate the CommonJS export names for ESM import in node:
99
101
  0 && (module.exports = {
@@ -23,9 +23,7 @@ module.exports = __toCommonJS(Links_exports);
23
23
  var import_jsx_runtime = require("react/jsx-runtime");
24
24
  var import_constants = require("./constants");
25
25
  function Links() {
26
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
27
- children: import_constants.DOCUMENT_LINKS_PLACEHOLDER
28
- });
26
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: import_constants.DOCUMENT_LINKS_PLACEHOLDER });
29
27
  }
30
28
  // Annotate the CommonJS export names for ESM import in node:
31
29
  0 && (module.exports = {
@@ -30,25 +30,19 @@ function Root(props) {
30
30
  const {
31
31
  templateParams: { mountId = "root" }
32
32
  } = (0, import_react.useContext)(import_DocumentContext.DocumentContext);
33
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
34
- id: `${rootId || mountId}`,
35
- children: [
36
- `${import_constants.DOCUMENT_SSR_PLACEHOLDER}`,
37
- children
38
- ]
39
- });
33
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { id: `${rootId || mountId}`, children: [
34
+ `${import_constants.DOCUMENT_SSR_PLACEHOLDER}`,
35
+ children
36
+ ] });
40
37
  }
41
38
  function DefaultRoot(props) {
42
39
  const {
43
40
  templateParams: { mountId = "root" }
44
41
  } = (0, import_react.useContext)(import_DocumentContext.DocumentContext);
45
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
46
- id: `${mountId}`,
47
- children: [
48
- `${import_constants.DOCUMENT_SSR_PLACEHOLDER}`,
49
- props.children
50
- ]
51
- });
42
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { id: `${mountId}`, children: [
43
+ `${import_constants.DOCUMENT_SSR_PLACEHOLDER}`,
44
+ props.children
45
+ ] });
52
46
  }
53
47
  // Annotate the CommonJS export names for ESM import in node:
54
48
  0 && (module.exports = {
@@ -26,13 +26,11 @@ function Script(props) {
26
26
  const { content } = props;
27
27
  const contentStr = content.toString();
28
28
  const contentIIFE = encodeURIComponent(`(${contentStr})()`);
29
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
30
- children: [
31
- `${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_START}`,
32
- `${contentIIFE}`,
33
- `${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_END}`
34
- ]
35
- });
29
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
30
+ `${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_START}`,
31
+ `${contentIIFE}`,
32
+ `${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_END}`
33
+ ] });
36
34
  }
37
35
  // Annotate the CommonJS export names for ESM import in node:
38
36
  0 && (module.exports = {
@@ -23,9 +23,7 @@ module.exports = __toCommonJS(Scripts_exports);
23
23
  var import_jsx_runtime = require("react/jsx-runtime");
24
24
  var import_constants = require("./constants");
25
25
  function Scripts() {
26
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
27
- children: `${import_constants.DOCUMENT_SCRIPTS_PLACEHOLDER}`
28
- });
26
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: `${import_constants.DOCUMENT_SCRIPTS_PLACEHOLDER}` });
29
27
  }
30
28
  // Annotate the CommonJS export names for ESM import in node:
31
29
  0 && (module.exports = {
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -76,7 +80,7 @@ var cli_default = () => ({
76
80
  }
77
81
  return async ({ htmlWebpackPlugin }) => {
78
82
  const documentParams = getDocParams({
79
- config: api.useConfigContext(),
83
+ config: api.useResolvedConfigContext(),
80
84
  entryName,
81
85
  templateParameters
82
86
  });
@@ -107,6 +111,7 @@ var cli_default = () => ({
107
111
  entryPoints: [documentFilePath],
108
112
  outfile: htmlOutputFile,
109
113
  platform: "node",
114
+ // change esbuild use the rootDir tsconfig.json as default to tempTsConfigFile
110
115
  tsconfig: tempTsConfigFile,
111
116
  target: "es6",
112
117
  loader: {
@@ -163,7 +168,7 @@ var cli_default = () => ({
163
168
  `${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_START}(.*?)${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_END}`,
164
169
  "g"
165
170
  ),
166
- (_scriptStr, $1) => `<script>${decodeURIComponent($1)}<\/script>`
171
+ (_scriptStr, $1) => `<script>${decodeURIComponent($1)}</script>`
167
172
  );
168
173
  }
169
174
  const finalHtml = `<!DOCTYPE html>${html}`.replace(import_constants.DOCUMENT_META_PLACEHOLDER, metas).replace(import_constants.DOCUMENT_SSR_PLACEHOLDER, import_constants.HTML_SEPARATOR).replace(import_constants.DOCUMENT_SCRIPTS_PLACEHOLDER, scripts).replace(import_constants.DOCUMENT_LINKS_PLACEHOLDER, links).replace(
@@ -189,6 +194,7 @@ var cli_default = () => ({
189
194
  ) : { ...options == null ? void 0 : options.templateParameters };
190
195
  const templateContent = documentEntry(
191
196
  entry.entryName,
197
+ // options,
192
198
  hackParameters
193
199
  );
194
200
  const documentHtmlOptions = templateContent ? {
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  };
19
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  };
19
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  };
19
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -23,10 +23,6 @@ module.exports = __toCommonJS(cli_exports);
23
23
  var import_utils = require("@modern-js/utils");
24
24
  const PLUGIN_IDENTIFIER = "router";
25
25
  const ROUTES_IDENTIFIER = "routes";
26
- const isV5 = (config) => {
27
- var _a, _b;
28
- return ((_b = (_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.router) == null ? void 0 : _b.mode) === "react-router-5";
29
- };
30
26
  var cli_default = () => ({
31
27
  name: "@modern-js/plugin-router",
32
28
  required: ["@modern-js/runtime"],
@@ -63,7 +59,7 @@ var cli_default = () => ({
63
59
  );
64
60
  runtimeConfigMap.set(entryName, runtimeConfig);
65
61
  if (runtimeConfig == null ? void 0 : runtimeConfig.router) {
66
- if (!isV5(userConfig)) {
62
+ if (!(0, import_utils.isRouterV5)(userConfig)) {
67
63
  imports.push({
68
64
  value: "@modern-js/runtime/plugins",
69
65
  specifiers: [{ imported: PLUGIN_IDENTIFIER }]
@@ -84,7 +80,7 @@ var cli_default = () => ({
84
80
  const { serverRoutes } = api.useAppContext();
85
81
  const userConfig = api.useResolvedConfigContext();
86
82
  const runtimeConfig = runtimeConfigMap.get(entryName);
87
- if (runtimeConfig.router && !isV5(userConfig)) {
83
+ if (runtimeConfig.router && !(0, import_utils.isRouterV5)(userConfig)) {
88
84
  const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
89
85
  plugins.push({
90
86
  name: PLUGIN_IDENTIFIER,
@@ -105,7 +101,7 @@ var cli_default = () => ({
105
101
  },
106
102
  addRuntimeExports() {
107
103
  const userConfig = api.useResolvedConfigContext();
108
- if (!isV5(userConfig)) {
104
+ if (!(0, import_utils.isRouterV5)(userConfig)) {
109
105
  pluginsExportsUtils.addExport(
110
106
  `export { default as router } from '@modern-js/runtime/router'`
111
107
  );