@bleedingdev/modern-js-runtime 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10

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 (207) hide show
  1. package/dist/cjs/cli/code.js +3 -1
  2. package/dist/cjs/cli/ssr/index.js +2 -74
  3. package/dist/cjs/core/browser/hydrate.js +6 -1
  4. package/dist/cjs/core/context/index.js +4 -43
  5. package/dist/cjs/core/context/public.js +4 -7
  6. package/dist/cjs/core/context/runtime.js +17 -5
  7. package/dist/cjs/core/react/wrapper.js +22 -65
  8. package/dist/cjs/core/server/helmet.js +5 -4
  9. package/dist/cjs/core/server/requestResponse.js +4 -4
  10. package/dist/cjs/core/server/routerCleanup.js +2 -2
  11. package/dist/cjs/core/server/shared.js +171 -4
  12. package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
  13. package/dist/cjs/core/server/stream/beforeTemplate.js +34 -25
  14. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +28 -21
  15. package/dist/cjs/core/server/stream/createReadableStream.js +208 -123
  16. package/dist/cjs/core/server/stream/createReadableStream.worker.js +159 -90
  17. package/dist/cjs/core/server/stream/deferredScript.js +3 -3
  18. package/dist/cjs/core/server/stream/shared.js +2 -2
  19. package/dist/cjs/core/server/string/index.js +100 -64
  20. package/dist/cjs/core/server/string/loadable.js +34 -19
  21. package/dist/cjs/core/server/string/ssrData.js +5 -12
  22. package/dist/cjs/core/server/utils.js +1 -2
  23. package/dist/cjs/document/cli/index.js +1 -2
  24. package/dist/cjs/exports/head.js +7 -14
  25. package/dist/cjs/router/runtime/PrefetchLink.js +67 -123
  26. package/dist/cjs/router/runtime/hooks.js +13 -2
  27. package/dist/cjs/router/runtime/internal.js +7 -45
  28. package/dist/cjs/router/runtime/plugin.js +2 -8
  29. package/dist/cjs/router/runtime/plugin.node.js +2 -30
  30. package/dist/cjs/router/runtime/redirect.js +1 -1
  31. package/dist/esm/cli/code.mjs +3 -1
  32. package/dist/esm/cli/ssr/index.mjs +3 -72
  33. package/dist/esm/core/browser/hydrate.mjs +7 -2
  34. package/dist/esm/core/context/index.mjs +2 -5
  35. package/dist/esm/core/context/public.mjs +1 -5
  36. package/dist/esm/core/context/runtime.mjs +13 -4
  37. package/dist/esm/core/react/wrapper.mjs +21 -67
  38. package/dist/esm/core/server/helmet.mjs +5 -4
  39. package/dist/esm/core/server/requestResponse.mjs +3 -3
  40. package/dist/esm/core/server/routerCleanup.mjs +1 -1
  41. package/dist/esm/core/server/shared.mjs +153 -1
  42. package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
  43. package/dist/esm/core/server/stream/beforeTemplate.mjs +37 -28
  44. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +31 -24
  45. package/dist/esm/core/server/stream/createReadableStream.mjs +207 -122
  46. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +149 -90
  47. package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
  48. package/dist/esm/core/server/stream/shared.mjs +2 -2
  49. package/dist/esm/core/server/string/index.mjs +104 -68
  50. package/dist/esm/core/server/string/loadable.mjs +34 -19
  51. package/dist/esm/core/server/string/ssrData.mjs +5 -12
  52. package/dist/esm/core/server/utils.mjs +1 -2
  53. package/dist/esm/document/cli/index.mjs +2 -3
  54. package/dist/esm/exports/head.mjs +7 -14
  55. package/dist/esm/router/runtime/PrefetchLink.mjs +68 -124
  56. package/dist/esm/router/runtime/hooks.mjs +9 -1
  57. package/dist/esm/router/runtime/internal.mjs +2 -33
  58. package/dist/esm/router/runtime/plugin.mjs +1 -7
  59. package/dist/esm/router/runtime/plugin.node.mjs +1 -29
  60. package/dist/esm/router/runtime/redirect.mjs +1 -1
  61. package/dist/esm-node/cli/code.mjs +3 -1
  62. package/dist/esm-node/cli/ssr/index.mjs +3 -72
  63. package/dist/esm-node/core/browser/hydrate.mjs +7 -2
  64. package/dist/esm-node/core/context/index.mjs +2 -5
  65. package/dist/esm-node/core/context/public.mjs +1 -5
  66. package/dist/esm-node/core/context/runtime.mjs +13 -4
  67. package/dist/esm-node/core/react/wrapper.mjs +21 -67
  68. package/dist/esm-node/core/server/helmet.mjs +5 -4
  69. package/dist/esm-node/core/server/requestResponse.mjs +3 -3
  70. package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
  71. package/dist/esm-node/core/server/shared.mjs +153 -1
  72. package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
  73. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +37 -28
  74. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +31 -24
  75. package/dist/esm-node/core/server/stream/createReadableStream.mjs +207 -122
  76. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +149 -90
  77. package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
  78. package/dist/esm-node/core/server/stream/shared.mjs +2 -2
  79. package/dist/esm-node/core/server/string/index.mjs +104 -68
  80. package/dist/esm-node/core/server/string/loadable.mjs +34 -19
  81. package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
  82. package/dist/esm-node/core/server/utils.mjs +1 -2
  83. package/dist/esm-node/document/cli/index.mjs +2 -3
  84. package/dist/esm-node/exports/head.mjs +7 -14
  85. package/dist/esm-node/router/runtime/PrefetchLink.mjs +68 -124
  86. package/dist/esm-node/router/runtime/hooks.mjs +9 -1
  87. package/dist/esm-node/router/runtime/internal.mjs +2 -33
  88. package/dist/esm-node/router/runtime/plugin.mjs +1 -7
  89. package/dist/esm-node/router/runtime/plugin.node.mjs +1 -29
  90. package/dist/esm-node/router/runtime/redirect.mjs +1 -1
  91. package/dist/types/cli/index.d.ts +7 -7
  92. package/dist/types/cli/ssr/index.d.ts +0 -3
  93. package/dist/types/core/browser/hydrate.d.ts +1 -1
  94. package/dist/types/core/browser/index.d.ts +1 -1
  95. package/dist/types/core/compat/hooks.d.ts +1 -1
  96. package/dist/types/core/compat/index.d.ts +1 -1
  97. package/dist/types/core/compat/requestContext.d.ts +3 -3
  98. package/dist/types/core/config.d.ts +1 -1
  99. package/dist/types/core/context/index.d.ts +8 -10
  100. package/dist/types/core/context/monitors/index.d.ts +1 -1
  101. package/dist/types/core/context/monitors/index.server.d.ts +1 -1
  102. package/dist/types/core/context/public.d.ts +1 -23
  103. package/dist/types/core/context/runtime.d.ts +27 -3
  104. package/dist/types/core/context/serverPayload/index.d.ts +1 -1
  105. package/dist/types/core/index.d.ts +5 -5
  106. package/dist/types/core/plugin/index.d.ts +1 -1
  107. package/dist/types/core/plugin/types.d.ts +2 -2
  108. package/dist/types/core/react/wrapper.d.ts +7 -1
  109. package/dist/types/core/server/helmet.d.ts +4 -5
  110. package/dist/types/core/server/index.d.ts +2 -2
  111. package/dist/types/core/server/react/index.d.ts +2 -2
  112. package/dist/types/core/server/requestHandler.d.ts +3 -3
  113. package/dist/types/core/server/requestResponse.d.ts +3 -3
  114. package/dist/types/core/server/routerCleanup.d.ts +2 -2
  115. package/dist/types/core/server/server.d.ts +4 -4
  116. package/dist/types/core/server/shared.d.ts +25 -2
  117. package/dist/types/core/server/stream/afterTemplate.d.ts +5 -4
  118. package/dist/types/core/server/stream/beforeTemplate.d.ts +6 -3
  119. package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +6 -3
  120. package/dist/types/core/server/stream/createReadableStream.d.ts +1 -1
  121. package/dist/types/core/server/stream/createReadableStream.worker.d.ts +1 -1
  122. package/dist/types/core/server/stream/index.d.ts +1 -1
  123. package/dist/types/core/server/stream/shared.d.ts +5 -5
  124. package/dist/types/core/server/stream/template.d.ts +2 -2
  125. package/dist/types/core/server/string/index.d.ts +1 -1
  126. package/dist/types/core/server/string/loadable.d.ts +7 -4
  127. package/dist/types/core/server/string/ssrData.d.ts +5 -4
  128. package/dist/types/core/server/string/types.d.ts +2 -6
  129. package/dist/types/core/server/tracer.d.ts +1 -1
  130. package/dist/types/core/server/utils.d.ts +2 -2
  131. package/dist/types/core/types.d.ts +2 -3
  132. package/dist/types/document/index.d.ts +12 -12
  133. package/dist/types/exports/config-routes.d.ts +1 -1
  134. package/dist/types/exports/head.d.ts +2 -2
  135. package/dist/types/index.d.ts +9 -9
  136. package/dist/types/internal.d.ts +1 -1
  137. package/dist/types/react-server.d.ts +3 -3
  138. package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -1
  139. package/dist/types/router/cli/handler.d.ts +1 -1
  140. package/dist/types/router/cli/index.d.ts +3 -3
  141. package/dist/types/router/index.d.ts +1 -1
  142. package/dist/types/router/internal.d.ts +2 -2
  143. package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
  144. package/dist/types/router/runtime/hooks.d.ts +19 -2
  145. package/dist/types/router/runtime/index.d.ts +4 -4
  146. package/dist/types/router/runtime/internal.d.ts +5 -22
  147. package/dist/types/router/runtime/plugin.d.ts +3 -3
  148. package/dist/types/router/runtime/plugin.node.d.ts +3 -3
  149. package/dist/types/router/runtime/rsc-router.d.ts +3 -3
  150. package/dist/types/router/runtime/types.d.ts +2 -43
  151. package/dist/types/router/runtime/utils.d.ts +1 -1
  152. package/package.json +19 -47
  153. package/rstest.config.mts +32 -2
  154. package/dist/cjs/boundary-debugger/index.js +0 -317
  155. package/dist/cjs/core/context/extensions.js +0 -74
  156. package/dist/cjs/core/context/helmetContext.js +0 -54
  157. package/dist/cjs/core/server/federatedCss.js +0 -58
  158. package/dist/cjs/core/server/scriptOrder.js +0 -140
  159. package/dist/cjs/module-federation/consume-surface.js +0 -199
  160. package/dist/cjs/module-federation/distributed-ssr.js +0 -135
  161. package/dist/cjs/module-federation/index.js +0 -316
  162. package/dist/cjs/module-federation/last-known-good.js +0 -157
  163. package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
  164. package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
  165. package/dist/cjs/router/runtime/lifecycle.js +0 -167
  166. package/dist/cjs/router/runtime/provider.js +0 -153
  167. package/dist/esm/boundary-debugger/index.mjs +0 -277
  168. package/dist/esm/core/context/extensions.mjs +0 -33
  169. package/dist/esm/core/context/helmetContext.mjs +0 -13
  170. package/dist/esm/core/server/federatedCss.mjs +0 -20
  171. package/dist/esm/core/server/scriptOrder.mjs +0 -90
  172. package/dist/esm/module-federation/consume-surface.mjs +0 -158
  173. package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
  174. package/dist/esm/module-federation/index.mjs +0 -115
  175. package/dist/esm/module-federation/last-known-good.mjs +0 -113
  176. package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
  177. package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
  178. package/dist/esm/router/runtime/lifecycle.mjs +0 -105
  179. package/dist/esm/router/runtime/provider.mjs +0 -100
  180. package/dist/esm-node/boundary-debugger/index.mjs +0 -278
  181. package/dist/esm-node/core/context/extensions.mjs +0 -34
  182. package/dist/esm-node/core/context/helmetContext.mjs +0 -14
  183. package/dist/esm-node/core/server/federatedCss.mjs +0 -21
  184. package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
  185. package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
  186. package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
  187. package/dist/esm-node/module-federation/index.mjs +0 -116
  188. package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
  189. package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
  190. package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
  191. package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
  192. package/dist/esm-node/router/runtime/provider.mjs +0 -101
  193. package/dist/types/boundary-debugger/index.d.ts +0 -28
  194. package/dist/types/core/context/extensions.d.ts +0 -35
  195. package/dist/types/core/context/helmetContext.d.ts +0 -10
  196. package/dist/types/core/server/federatedCss.d.ts +0 -5
  197. package/dist/types/core/server/scriptOrder.d.ts +0 -25
  198. package/dist/types/module-federation/consume-surface.d.ts +0 -104
  199. package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
  200. package/dist/types/module-federation/index.d.ts +0 -71
  201. package/dist/types/module-federation/last-known-good.d.ts +0 -52
  202. package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
  203. package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
  204. package/dist/types/router/runtime/lifecycle.d.ts +0 -27
  205. package/dist/types/router/runtime/provider.d.ts +0 -78
  206. /package/dist/esm/{rslib-runtime.mjs → rslib-runtime~1.mjs} +0 -0
  207. /package/dist/esm-node/{rslib-runtime.mjs → rslib-runtime~0.mjs} +0 -0
@@ -63,7 +63,7 @@ function createRenderStreaming(createReadableStreamPromise) {
63
63
  const end = time();
64
64
  const { runtimeContext, config, resource } = options;
65
65
  const { onError, onTiming } = options;
66
- const { htmlTemplate, entryName, moduleFederationCssAssets } = resource;
66
+ const { htmlTemplate, entryName } = resource;
67
67
  const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
68
68
  const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ jsxs(Fragment, {
69
69
  children: [
@@ -83,7 +83,7 @@ function createRenderStreaming(createReadableStreamPromise) {
83
83
  runtimeContext,
84
84
  ssrConfig,
85
85
  entryName,
86
- moduleFederationCssAssets,
86
+ resource,
87
87
  rscClientManifest: options.rscClientManifest,
88
88
  rscSSRManifest: options.rscSSRManifest,
89
89
  rscServerManifest: options.rscServerManifest,
@@ -2,17 +2,15 @@ import { time } from "@modern-js/runtime-utils/time";
2
2
  import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
3
3
  import server from "react-dom/server";
4
4
  import { RenderLevel } from "../../constants.mjs";
5
- import { getGlobalInternalRuntimeContext } from "../../context/index.mjs";
6
- import { wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
7
- import { CHUNK_CSS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants.mjs";
5
+ import { getGlobalEnableRsc, getGlobalInternalRuntimeContext } from "../../context/index.mjs";
6
+ import { wrapRuntimeComponentResolver, wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
7
+ import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants.mjs";
8
8
  import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
9
- import { replaceChunkJsPlaceholder } from "../scriptOrder.mjs";
10
- import { buildHtml } from "../shared.mjs";
9
+ import { buildHtml, createSSRRenderLifecycle, replaceSSRTemplateChunk } from "../shared.mjs";
11
10
  import { SSRErrors, SSRTimings } from "../tracer.mjs";
12
11
  import { getSSRConfigByEntry, safeReplace } from "../utils.mjs";
13
12
  import { LoadableCollector } from "./loadable.mjs";
14
13
  import { SSRDataCollector } from "./ssrData.mjs";
15
- import * as __rspack_external__modern_js_runtime_extensions_ce611631 from "@modern-js/runtime-extensions";
16
14
  const renderString = async (request, serverRoot, options)=>{
17
15
  const { resource, runtimeContext, config, onError, onTiming } = options;
18
16
  const tracer = {
@@ -20,7 +18,7 @@ const renderString = async (request, serverRoot, options)=>{
20
18
  onTiming
21
19
  };
22
20
  const routerContext = runtimeContext.routerContext;
23
- const { htmlTemplate, entryName, loadableStats, routeManifest, moduleFederationCssAssets } = resource;
21
+ const { htmlTemplate, entryName, loadableStats, routeManifest } = resource;
24
22
  const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
25
23
  const chunkSet = {
26
24
  renderLevel: RenderLevel.CLIENT_RENDER,
@@ -28,83 +26,121 @@ const renderString = async (request, serverRoot, options)=>{
28
26
  jsChunk: '',
29
27
  cssChunk: ''
30
28
  };
31
- const collectors = [
32
- new LoadableCollector({
33
- stats: loadableStats,
34
- nonce: config.nonce,
35
- routeManifest,
36
- runtimeContext,
37
- template: htmlTemplate,
38
- entryName,
39
- moduleFederationCssAssets,
40
- chunkSet,
41
- config
42
- }),
43
- new SSRDataCollector({
44
- runtimeContext,
45
- request,
46
- ssrConfig,
47
- ssrContext: runtimeContext.ssrContext,
48
- chunkSet,
49
- routerContext,
50
- nonce: config.nonce,
51
- useJsonScript: config.useJsonScript
52
- })
53
- ];
29
+ const collectors = [];
30
+ const lifecycle = createSSRRenderLifecycle(collectors);
31
+ const loadableCollector = new LoadableCollector({
32
+ stats: loadableStats,
33
+ nonce: config.nonce,
34
+ routeManifest,
35
+ template: htmlTemplate,
36
+ entryName,
37
+ chunkSet,
38
+ config,
39
+ lifecycle
40
+ });
41
+ collectors.push(loadableCollector, new SSRDataCollector({
42
+ runtimeContext,
43
+ request,
44
+ ssrConfig,
45
+ ssrContext: runtimeContext.ssrContext,
46
+ chunkSet,
47
+ routerContext,
48
+ nonce: config.nonce,
49
+ useJsonScript: config.useJsonScript,
50
+ lifecycle
51
+ }));
54
52
  const internalRuntimeContext = getGlobalInternalRuntimeContext();
55
53
  const hooks = internalRuntimeContext.hooks;
56
54
  const extraCollectors = hooks.extendStringSSRCollectors.call({
57
- chunkSet
55
+ chunkSet,
56
+ render: {
57
+ runtimeContext,
58
+ request,
59
+ resource,
60
+ config,
61
+ platform: 'node',
62
+ mode: 'string',
63
+ isRsc: true === getGlobalEnableRsc()
64
+ }
58
65
  });
59
66
  for (const c of extraCollectors)if (c) collectors.unshift(c);
60
- const rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
67
+ let rootElement = wrapRuntimeContextProvider(serverRoot, Object.assign(runtimeContext, {
61
68
  ssr: true
62
69
  }));
63
- const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext.ssrContext?.htmlModifiers || [], runtimeContext, entryName, tracer);
70
+ if (true === getGlobalEnableRsc() && false === runtimeContext.isBrowser) rootElement = wrapRuntimeComponentResolver(rootElement, hooks);
71
+ const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext.ssrContext?.htmlModifiers || [], tracer, request.signal, lifecycle, loadableCollector.stylesheetInfo);
64
72
  return html;
65
73
  };
66
- async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, runtimeContext, entryName, { onError, onTiming }) {
74
+ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, { onError, onTiming }, signal, lifecycle, stylesheetInfo) {
67
75
  let html = '';
68
76
  let helmetData;
69
- const finalApp = collectors.reduce((pre, creator)=>creator.collect?.(pre) || pre, App);
70
- __rspack_external__modern_js_runtime_extensions_ce611631.beginHeadRender(runtimeContext);
71
77
  try {
72
- const end = time();
73
- html = server.renderToString(finalApp, {
74
- identifierPrefix: SSR_HYDRATION_ID_PREFIX
78
+ signal.throwIfAborted();
79
+ try {
80
+ const finalApp = collectors.reduce((pre, creator)=>creator.collect?.(pre) || pre, App);
81
+ lifecycle.beforeReact();
82
+ const end = time();
83
+ html = server.renderToString(finalApp, {
84
+ identifierPrefix: SSR_HYDRATION_ID_PREFIX
85
+ });
86
+ html = lifecycle.completedBody(html, 'complete');
87
+ chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
88
+ helmetData = getHelmetData(collectors);
89
+ const cost = end();
90
+ onTiming(SSRTimings.RENDER_HTML, cost);
91
+ } catch (error) {
92
+ lifecycle.finish({
93
+ status: 'fallback',
94
+ error
95
+ });
96
+ html = '';
97
+ chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
98
+ onError(error, SSRErrors.RENDER_HTML);
99
+ }
100
+ await Promise.all(collectors.map((component)=>component.effect()));
101
+ signal.throwIfAborted();
102
+ const { ssrScripts, cssChunk, jsChunk } = chunkSet;
103
+ const finalHtml = await buildHtml(htmlTemplate, [
104
+ createReplaceHtml(html),
105
+ (template)=>replaceSSRTemplateChunk({
106
+ name: "scripts",
107
+ template,
108
+ placeholder: CHUNK_JS_PLACEHOLDER,
109
+ content: jsChunk
110
+ }, lifecycle),
111
+ (template)=>replaceSSRTemplateChunk({
112
+ name: 'styles',
113
+ template,
114
+ placeholder: CHUNK_CSS_PLACEHOLDER,
115
+ content: cssChunk,
116
+ ...stylesheetInfo
117
+ }, lifecycle),
118
+ (template)=>replaceSSRTemplateChunk({
119
+ name: 'data',
120
+ template,
121
+ placeholder: SSR_DATA_PLACEHOLDER,
122
+ content: ssrScripts
123
+ }, lifecycle),
124
+ createReplaceHelemt(helmetData),
125
+ ...htmlModifiers
126
+ ]);
127
+ signal.throwIfAborted();
128
+ lifecycle.finish({
129
+ status: 'complete'
130
+ });
131
+ return finalHtml;
132
+ } catch (error) {
133
+ lifecycle.finish(signal.aborted ? {
134
+ status: 'cancelled',
135
+ reason: signal.reason
136
+ } : {
137
+ status: 'error',
138
+ error
75
139
  });
76
- html = __rspack_external__modern_js_runtime_extensions_ce611631.completeHeadRender(runtimeContext, html);
77
- chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
78
- helmetData = getHelmetData(runtimeContext);
79
- const cost = end();
80
- onTiming(SSRTimings.RENDER_HTML, cost);
81
- } catch (e) {
82
- __rspack_external__modern_js_runtime_extensions_ce611631.abortHeadRender(runtimeContext);
83
- chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
84
- onError(e, SSRErrors.RENDER_HTML);
140
+ throw error;
85
141
  }
86
- await Promise.all(collectors.map((component)=>component.effect()));
87
- const { ssrScripts, cssChunk, jsChunk } = chunkSet;
88
- const finalHtml = await buildHtml(htmlTemplate, [
89
- createReplaceHtml(html),
90
- createReplaceChunkJs(jsChunk, entryName),
91
- createReplaceChunkCss(cssChunk),
92
- createReplaceSSRDataScript(ssrScripts, entryName),
93
- createReplaceHelemt(helmetData),
94
- ...htmlModifiers
95
- ]);
96
- return finalHtml;
97
142
  }
98
143
  function createReplaceHtml(html) {
99
144
  return (template)=>safeReplace(template, HTML_PLACEHOLDER, html);
100
145
  }
101
- function createReplaceSSRDataScript(data, entryName) {
102
- return (template)=>replaceChunkJsPlaceholder(template, data, entryName, SSR_DATA_PLACEHOLDER);
103
- }
104
- function createReplaceChunkJs(js, entryName) {
105
- return (template)=>replaceChunkJsPlaceholder(template, js, entryName);
106
- }
107
- function createReplaceChunkCss(css) {
108
- return (template)=>safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
109
- }
110
146
  export { renderString };
@@ -1,13 +1,11 @@
1
1
  import { ChunkExtractor } from "@loadable/server";
2
- import { createFederatedCssLinks } from "../federatedCss.mjs";
3
- import { getMatchedRouteChunks, orderHydrationScriptChunks } from "../scriptOrder.mjs";
4
2
  import { attributesToString, checkIsNode, hasStylesheetLink } from "../utils.mjs";
5
3
  const extname = (uri)=>{
6
4
  if ('string' != typeof uri || !uri.includes('.')) return '';
7
5
  return `.${uri?.split('.').pop()}` || '';
8
6
  };
9
7
  const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
10
- const routeAssetToChunk = (asset)=>({
8
+ const assetToChunk = (asset)=>({
11
9
  chunk: asset,
12
10
  filename: asset.replace(/^\//, ''),
13
11
  linkType: 'preload',
@@ -53,16 +51,32 @@ class LoadableCollector {
53
51
  ]));
54
52
  } catch (e) {}
55
53
  const collectedChunks = extractor ? extractor.getChunkAssets(extractor.chunks) : [];
56
- const matchedRouteChunks = getMatchedRouteChunks(options.runtimeContext, options.routeManifest, routeAssetToChunk);
57
- const orderedScriptChunks = orderHydrationScriptChunks({
58
- asyncEntryChunks: asyncChunks,
59
- collectedChunks,
60
- matchedRouteChunks,
61
- entryName
62
- });
63
- const chunks = [].concat(asyncChunks).concat(collectedChunks).concat(matchedRouteChunks);
64
- const scriptChunks = generateChunks(orderedScriptChunks, 'js');
65
- const styleChunks = generateChunks(chunks, 'css');
54
+ const groups = [
55
+ {
56
+ name: 'async-entry',
57
+ assets: asyncChunks
58
+ },
59
+ {
60
+ name: 'loadable',
61
+ assets: collectedChunks
62
+ }
63
+ ];
64
+ const nativeChunks = [
65
+ ...asyncChunks,
66
+ ...collectedChunks
67
+ ];
68
+ const prepare = (kind)=>options.lifecycle?.transformAssets(groups, {
69
+ kind,
70
+ source: 'loadable',
71
+ template: options.template,
72
+ createAsset: assetToChunk
73
+ }) ?? nativeChunks;
74
+ const scriptChunks = generateChunks([
75
+ ...prepare("script")
76
+ ], 'js');
77
+ const styleChunks = generateChunks([
78
+ ...prepare('style')
79
+ ], 'css');
66
80
  if (extractor) {
67
81
  this.emitLoadableScripts(extractor);
68
82
  await this.emitScriptAssets(scriptChunks);
@@ -101,7 +115,7 @@ class LoadableCollector {
101
115
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
102
116
  }
103
117
  async emitStyleAssets(chunks) {
104
- const { template, chunkSet, config, moduleFederationCssAssets } = this.options;
118
+ const { template, chunkSet, config } = this.options;
105
119
  const { inlineStyles } = config;
106
120
  const atrributes = attributesToString(this.generateAttributes());
107
121
  const emittedAssetUrls = new Set();
@@ -116,11 +130,8 @@ class LoadableCollector {
116
130
  return link;
117
131
  }));
118
132
  chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
119
- chunkSet.cssChunk += createFederatedCssLinks(moduleFederationCssAssets, {
120
- template,
121
- attributes: this.generateAttributes(),
122
- existingAssets: emittedChunks.map((chunk)=>chunk.url)
123
- });
133
+ this.stylesheetInfo.emittedAssets = emittedChunks.map((chunk)=>chunk.url);
134
+ this.stylesheetInfo.attributes = this.generateAttributes();
124
135
  }
125
136
  generateAttributes(extraAtr = {}) {
126
137
  const { config } = this.options;
@@ -133,6 +144,10 @@ class LoadableCollector {
133
144
  };
134
145
  }
135
146
  constructor(options){
147
+ this.stylesheetInfo = {
148
+ emittedAssets: [],
149
+ attributes: {}
150
+ };
136
151
  this.options = options;
137
152
  }
138
153
  }
@@ -1,5 +1,4 @@
1
1
  import { serializeJson } from "@modern-js/runtime-utils/node";
2
- import { getRouterHydrationScripts, getRouterServerSnapshot } from "../../../router/runtime/lifecycle.mjs";
3
2
  import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants.mjs";
4
3
  import { attributesToString, serializeErrors } from "../utils.mjs";
5
4
  function _check_private_redeclaration(obj, privateCollection) {
@@ -88,20 +87,15 @@ function getSSRData() {
88
87
  };
89
88
  }
90
89
  function getRouterData() {
91
- const { routerContext, runtimeContext } = _class_private_field_get(this, _options);
92
- const snapshotRouterData = getRouterServerSnapshot(runtimeContext)?.routerData;
93
- if (snapshotRouterData) return {
94
- loaderData: snapshotRouterData.loaderData,
95
- errors: serializeErrors(snapshotRouterData.errors || null)
96
- };
97
- return routerContext ? {
98
- loaderData: routerContext.loaderData,
99
- errors: serializeErrors(routerContext.errors)
90
+ const { routerContext, lifecycle } = _class_private_field_get(this, _options);
91
+ const data = lifecycle?.getRouterData() ?? routerContext;
92
+ return data ? {
93
+ loaderData: data.loaderData,
94
+ errors: serializeErrors(data.errors || null)
100
95
  } : void 0;
101
96
  }
102
97
  function getSSRDataScripts(ssrData, routerData) {
103
98
  const { nonce, useJsonScript = false } = _class_private_field_get(this, _options);
104
- const hydrationScripts = getRouterHydrationScripts(_class_private_field_get(this, _options).runtimeContext);
105
99
  const serializeSSRData = serializeJson(ssrData);
106
100
  const attrsStr = attributesToString({
107
101
  nonce
@@ -111,7 +105,6 @@ function getSSRDataScripts(ssrData, routerData) {
111
105
  const serializedRouterData = serializeJson(routerData);
112
106
  ssrDataScripts += useJsonScript ? `\n<script type="application/json" id="${ROUTER_DATA_JSON_ID}">${serializedRouterData}</script>` : `\n<script${attrsStr}>window._ROUTER_DATA = ${serializedRouterData}</script>`;
113
107
  }
114
- if (hydrationScripts.length) ssrDataScripts += `\n${hydrationScripts.join('\n')}`;
115
108
  return ssrDataScripts;
116
109
  }
117
110
  export { SSRDataCollector };
@@ -1,7 +1,6 @@
1
- import { escapeHtmlAttribute, isSafeHtmlAttributeName } from "@modern-js/runtime-extensions";
2
1
  import { isRouteErrorResponse } from "../../router/runtime/routerHelper.mjs";
3
2
  function attributesToString(attributes) {
4
- return Object.entries(attributes).reduce((str, [key, value])=>void 0 !== value && isSafeHtmlAttributeName(key) ? `${str} ${key}="${escapeHtmlAttribute(value)}"` : str, '');
3
+ return Object.entries(attributes).reduce((str, [key, value])=>void 0 !== value && /^[^\u0000-\u0020"'<>/=]+$/u.test(key) ? `${str} ${key}="${String(value).replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')}"` : str, '');
5
4
  }
6
5
  function safeReplace(source, searchValue, replaceValue) {
7
6
  return source.replace(searchValue, ()=>replaceValue);
@@ -48,7 +48,7 @@ const processCommentPlaceholders = (html)=>{
48
48
  return html.replace(new RegExp(`${DOCUMENT_COMMENT_PLACEHOLDER_START}([\\s\\S]*?)${DOCUMENT_COMMENT_PLACEHOLDER_END}`, 'g'), (_scriptStr, $1)=>`${decodeHtmlEntities(decodeURIComponent($1))}`);
49
49
  };
50
50
  const requireFromString = (code, filename)=>{
51
- const m = new module_0.Module(filename, module.parent);
51
+ const m = new module_0.Module(filename, void 0);
52
52
  m.filename = filename;
53
53
  m.paths = module_0.Module._nodeModulePaths(path.dirname(filename));
54
54
  m._compile(code, filename);
@@ -101,8 +101,7 @@ const applyExternalsPlugin = (child, compiler)=>{
101
101
  ]).apply(child);
102
102
  };
103
103
  const generateEntryCode = (docPath, _entryName)=>{
104
- const runtimeAPI = require.resolve('../');
105
- const esmRuntimeAPI = runtimeAPI.replace("cjs", "esm").replace(/.js$/, '.mjs');
104
+ const esmRuntimeAPI = require.resolve('@modern-js/runtime/document');
106
105
  return `import React from 'react';
107
106
  import ReactDomServer from 'react-dom/server';
108
107
  import Document from ${JSON.stringify(docPath)};
@@ -1,21 +1,14 @@
1
1
  "use client";
2
2
  import react from "react";
3
3
  import { Helmet, HelmetData, HelmetProvider } from "react-helmet-async";
4
- import { InternalRuntimeContext } from "../core/context/index.mjs";
5
- import { ensureHelmetContext } from "../core/context/helmetContext.mjs";
6
- import * as __rspack_external__modern_js_runtime_extensions_ce611631 from "@modern-js/runtime-extensions";
7
- const collectServerHelmet = (runtimeContext, props)=>{
8
- const helmetContext = ensureHelmetContext(runtimeContext);
9
- const createRecord = ()=>__rspack_external__modern_js_runtime_extensions_ce611631.createHelmetRecord(react, props);
10
- const deriveState = (records)=>__rspack_external__modern_js_runtime_extensions_ce611631.deriveHelmetServerState(react, records);
11
- const marker = __rspack_external__modern_js_runtime_extensions_ce611631.collectHeadState(runtimeContext, createRecord, deriveState, helmetContext);
12
- if (void 0 !== marker) return marker;
13
- helmetContext.helmet = __rspack_external__modern_js_runtime_extensions_ce611631.collectImmediateHelmetState(react, helmetContext, createRecord());
14
- };
4
+ import { RuntimeComponentResolverContext } from "../core/context/runtime.mjs";
15
5
  const head_Helmet = (props)=>{
16
- const runtimeContext = react.useContext(InternalRuntimeContext);
17
- if (null !== runtimeContext && false === runtimeContext.isBrowser) return __rspack_external__modern_js_runtime_extensions_ce611631.renderHeadMarker(react, collectServerHelmet(runtimeContext, props));
18
- return react.createElement(Helmet, props);
6
+ const resolveComponent = react.useContext(RuntimeComponentResolverContext);
7
+ const Component = resolveComponent?.(Helmet, {
8
+ name: 'head.Helmet'
9
+ }) ?? Helmet;
10
+ if (Component === head_Helmet) throw new Error('A component resolver cannot resolve head.Helmet to itself.');
11
+ return react.createElement(Component, props);
19
12
  };
20
13
  const head = {
21
14
  Helmet: head_Helmet,