@bleedingdev/modern-js-runtime 3.9.0-ultramodern.9 → 3.9.3-ultramodern.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 (130) hide show
  1. package/dist/cjs/cli/code.js +2 -2
  2. package/dist/cjs/cli/index.js +0 -7
  3. package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +2 -0
  4. package/dist/cjs/cli/template.server.js +1 -2
  5. package/dist/cjs/core/browser/hydrate.js +3 -9
  6. package/dist/cjs/core/browser/index.js +4 -5
  7. package/dist/cjs/core/context/index.js +8 -2
  8. package/dist/cjs/core/context/public.js +4 -4
  9. package/dist/cjs/core/context/runtime.js +3 -9
  10. package/dist/cjs/core/index.js +3 -3
  11. package/dist/cjs/core/plugin/index.js +2 -2
  12. package/dist/cjs/core/react/index.js +3 -3
  13. package/dist/cjs/core/react/wrapper.js +7 -8
  14. package/dist/cjs/core/server/requestHandler.js +253 -25
  15. package/dist/cjs/core/server/stream/beforeTemplate.js +3 -3
  16. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +2 -2
  17. package/dist/cjs/core/server/stream/createReadableStream.js +51 -19
  18. package/dist/cjs/core/server/stream/createReadableStream.worker.js +54 -27
  19. package/dist/cjs/core/server/stream/deferredScript.js +12 -6
  20. package/dist/cjs/core/server/stream/deferredScriptOutputCoordinator.js +370 -0
  21. package/dist/cjs/core/server/stream/shared.js +4 -0
  22. package/dist/cjs/core/server/string/index.js +6 -4
  23. package/dist/cjs/core/server/string/loadable.js +4 -4
  24. package/dist/cjs/document/cli/index.js +14 -5
  25. package/dist/cjs/exports/head.js +2 -2
  26. package/dist/cjs/internal.js +2 -2
  27. package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
  28. package/dist/cjs/router/cli/code/templates.js +2 -2
  29. package/dist/cjs/router/cli/code/utils.js +5 -4
  30. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +13 -10
  31. package/dist/cjs/router/runtime/PrefetchLink.js +4 -4
  32. package/dist/cjs/router/runtime/hooks.js +6 -7
  33. package/dist/cjs/router/runtime/plugin.js +22 -27
  34. package/dist/cjs/router/runtime/plugin.node.js +8 -9
  35. package/dist/esm/cli/code.mjs +2 -2
  36. package/dist/esm/cli/index.mjs +0 -7
  37. package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +2 -0
  38. package/dist/esm/cli/template.server.mjs +1 -2
  39. package/dist/esm/core/browser/hydrate.mjs +3 -9
  40. package/dist/esm/core/browser/index.mjs +1 -2
  41. package/dist/esm/core/context/index.mjs +1 -1
  42. package/dist/esm/core/context/public.mjs +1 -1
  43. package/dist/esm/core/context/runtime.mjs +3 -9
  44. package/dist/esm/core/index.mjs +1 -1
  45. package/dist/esm/core/plugin/index.mjs +1 -1
  46. package/dist/esm/core/react/index.mjs +1 -1
  47. package/dist/esm/core/react/wrapper.mjs +1 -2
  48. package/dist/esm/core/server/requestHandler.mjs +223 -19
  49. package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
  50. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +2 -2
  51. package/dist/esm/core/server/stream/createReadableStream.mjs +48 -16
  52. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +53 -26
  53. package/dist/esm/core/server/stream/deferredScript.mjs +12 -6
  54. package/dist/esm/core/server/stream/deferredScriptOutputCoordinator.mjs +332 -0
  55. package/dist/esm/core/server/stream/shared.mjs +2 -1
  56. package/dist/esm/core/server/string/index.mjs +3 -1
  57. package/dist/esm/core/server/string/loadable.mjs +4 -4
  58. package/dist/esm/document/cli/index.mjs +12 -6
  59. package/dist/esm/exports/head.mjs +1 -1
  60. package/dist/esm/internal.mjs +1 -1
  61. package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
  62. package/dist/esm/router/cli/code/templates.mjs +2 -2
  63. package/dist/esm/router/cli/code/utils.mjs +6 -5
  64. package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +13 -10
  65. package/dist/esm/router/runtime/PrefetchLink.mjs +1 -1
  66. package/dist/esm/router/runtime/hooks.mjs +6 -7
  67. package/dist/esm/router/runtime/plugin.mjs +14 -19
  68. package/dist/esm/router/runtime/plugin.node.mjs +3 -4
  69. package/dist/esm-node/cli/code.mjs +2 -2
  70. package/dist/esm-node/cli/index.mjs +1 -9
  71. package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +2 -0
  72. package/dist/esm-node/cli/template.server.mjs +1 -2
  73. package/dist/esm-node/core/browser/hydrate.mjs +3 -9
  74. package/dist/esm-node/core/browser/index.mjs +1 -2
  75. package/dist/esm-node/core/context/index.mjs +1 -1
  76. package/dist/esm-node/core/context/public.mjs +1 -1
  77. package/dist/esm-node/core/context/runtime.mjs +3 -9
  78. package/dist/esm-node/core/index.mjs +1 -1
  79. package/dist/esm-node/core/plugin/index.mjs +1 -1
  80. package/dist/esm-node/core/react/index.mjs +1 -1
  81. package/dist/esm-node/core/react/wrapper.mjs +1 -2
  82. package/dist/esm-node/core/server/requestHandler.mjs +223 -19
  83. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
  84. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +2 -2
  85. package/dist/esm-node/core/server/stream/createReadableStream.mjs +48 -16
  86. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +53 -26
  87. package/dist/esm-node/core/server/stream/deferredScript.mjs +12 -6
  88. package/dist/esm-node/core/server/stream/deferredScriptOutputCoordinator.mjs +333 -0
  89. package/dist/esm-node/core/server/stream/shared.mjs +2 -1
  90. package/dist/esm-node/core/server/string/index.mjs +3 -1
  91. package/dist/esm-node/core/server/string/loadable.mjs +4 -4
  92. package/dist/esm-node/document/cli/index.mjs +12 -6
  93. package/dist/esm-node/exports/head.mjs +1 -1
  94. package/dist/esm-node/internal.mjs +1 -1
  95. package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
  96. package/dist/esm-node/router/cli/code/templates.mjs +2 -2
  97. package/dist/esm-node/router/cli/code/utils.mjs +6 -5
  98. package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +13 -10
  99. package/dist/esm-node/router/runtime/PrefetchLink.mjs +1 -1
  100. package/dist/esm-node/router/runtime/hooks.mjs +6 -7
  101. package/dist/esm-node/router/runtime/plugin.mjs +14 -19
  102. package/dist/esm-node/router/runtime/plugin.node.mjs +3 -4
  103. package/dist/types/common.d.ts +2 -8
  104. package/dist/types/core/context/index.d.ts +1 -1
  105. package/dist/types/core/context/public.d.ts +1 -1
  106. package/dist/types/core/index.d.ts +1 -1
  107. package/dist/types/core/react/wrapper.d.ts +1 -1
  108. package/dist/types/core/server/requestHandler.d.ts +30 -1
  109. package/dist/types/core/server/stream/deferredScript.d.ts +1 -1
  110. package/dist/types/core/server/stream/deferredScriptOutputCoordinator.d.ts +72 -0
  111. package/dist/types/core/server/stream/shared.d.ts +14 -0
  112. package/dist/types/document/cli/index.d.ts +1 -0
  113. package/dist/types/internal.d.ts +1 -1
  114. package/dist/types/router/cli/code/utils.d.ts +1 -1
  115. package/dist/types/router/runtime/hooks.d.ts +12 -16
  116. package/package.json +32 -26
  117. package/rslib.config.mts +3 -0
  118. package/rstest.config.mts +0 -4
  119. package/dist/cjs/core/server/requestResponse.js +0 -107
  120. package/dist/cjs/core/server/routerCleanup.js +0 -129
  121. package/dist/cjs/rsc/server.worker.js +0 -62
  122. package/dist/esm/core/server/requestResponse.mjs +0 -63
  123. package/dist/esm/core/server/routerCleanup.mjs +0 -82
  124. package/dist/esm/rsc/server.worker.mjs +0 -1
  125. package/dist/esm-node/core/server/requestResponse.mjs +0 -64
  126. package/dist/esm-node/core/server/routerCleanup.mjs +0 -83
  127. package/dist/esm-node/rsc/server.worker.mjs +0 -2
  128. package/dist/types/core/server/requestResponse.d.ts +0 -15
  129. package/dist/types/core/server/routerCleanup.d.ts +0 -31
  130. package/dist/types/rsc/server.worker.d.ts +0 -1
@@ -40,22 +40,24 @@ __webpack_require__.d(__webpack_exports__, {
40
40
  createReadableStreamFromElement: ()=>createReadableStreamFromElement
41
41
  });
42
42
  const ssr_namespaceObject = require("@modern-js/render/ssr");
43
+ const context_namespaceObject = require("@modern-js/runtime/context");
43
44
  const node_namespaceObject = require("@modern-js/runtime-utils/node");
44
45
  const external_react_namespaceObject = require("react");
45
46
  var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
46
47
  const external_common_js_namespaceObject = require("../../../common.js");
47
48
  const external_constants_js_namespaceObject = require("../../constants.js");
48
- const index_js_namespaceObject = require("../../context/index.js");
49
+ const index_js_namespaceObject = require("../../context/monitors/index.js");
49
50
  const wrapper_js_namespaceObject = require("../../react/wrapper.js");
50
51
  const external_helmet_js_namespaceObject = require("../helmet.js");
51
52
  const external_shared_js_namespaceObject = require("../shared.js");
52
53
  const external_deferredScript_js_namespaceObject = require("./deferredScript.js");
54
+ const external_deferredScriptOutputCoordinator_js_namespaceObject = require("./deferredScriptOutputCoordinator.js");
53
55
  const external_shared_js_namespaceObject_1 = require("./shared.js");
54
56
  const external_template_js_namespaceObject = require("./template.js");
55
57
  const createReadableStreamFromElement = async (request, rootElement, options)=>{
56
58
  const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, resource, rscManifest, rscRoot } = options;
57
- const hooks = (0, index_js_namespaceObject.getGlobalInternalRuntimeContext)().hooks;
58
- const isRsc = true === (0, index_js_namespaceObject.getGlobalEnableRsc)();
59
+ const hooks = (0, context_namespaceObject.getGlobalInternalRuntimeContext)().hooks;
60
+ const isRsc = true === (0, context_namespaceObject.getGlobalEnableRsc)();
59
61
  const extenders = hooks.extendStreamSSR.call({
60
62
  runtimeContext,
61
63
  request,
@@ -63,6 +65,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
63
65
  config,
64
66
  platform: 'web',
65
67
  mode: 'stream',
68
+ monitors: (0, index_js_namespaceObject.getMonitors)(),
66
69
  isRsc,
67
70
  terminalMarker: external_common_js_namespaceObject.ESCAPED_SHELL_STREAM_END_MARK
68
71
  }) || [];
@@ -75,6 +78,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
75
78
  let pendingSource;
76
79
  let bodyOpen = true;
77
80
  let bodyPipe;
81
+ let coordinator;
78
82
  const templateOptions = {
79
83
  runtimeContext,
80
84
  ssrConfig,
@@ -93,6 +97,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
93
97
  request,
94
98
  signal: request.signal,
95
99
  nonce: config.nonce,
100
+ progressiveChunkSize: external_shared_js_namespaceObject_1.SHELL_PROGRESSIVE_CHUNK_SIZE,
96
101
  rscManifest,
97
102
  rscRoot: rscRoot,
98
103
  routes: runtimeContext.routes,
@@ -121,66 +126,87 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
121
126
  const decoder = new TextDecoder();
122
127
  const encoder = new TextEncoder();
123
128
  const pendingScripts = [];
124
- let buffered = '';
129
+ const buffered = [];
130
+ let bufferedLength = 0;
131
+ let markerTail = '';
125
132
  let shellChunkStatus = external_shared_js_namespaceObject_1.ShellChunkStatus.START;
126
133
  let bodyController;
127
- const emit = (chunk, controller)=>{
134
+ let deferredResolversComplete = Promise.resolve();
135
+ coordinator = new external_deferredScriptOutputCoordinator_js_namespaceObject.DeferredScriptOutputCoordinator((content)=>{
136
+ if (!bodyOpen) return;
137
+ try {
138
+ bodyController.enqueue(encoder.encode(content));
139
+ } catch {
140
+ bodyOpen = false;
141
+ }
142
+ });
143
+ const emit = (chunk)=>{
128
144
  if (shellChunkStatus === external_shared_js_namespaceObject_1.ShellChunkStatus.FINISH) {
129
- if (chunk.length > 0) controller.enqueue(encoder.encode(chunk));
145
+ if (chunk.length > 0) coordinator?.writeReact(chunk);
146
+ return;
147
+ }
148
+ const window = markerTail + chunk;
149
+ const windowIndex = window.indexOf(external_common_js_namespaceObject.ESCAPED_SHELL_STREAM_END_MARK);
150
+ const markerIndex = bufferedLength - markerTail.length + windowIndex;
151
+ buffered.push(chunk);
152
+ bufferedLength += chunk.length;
153
+ if (-1 === windowIndex) {
154
+ markerTail = window.slice(Math.max(0, window.length - external_common_js_namespaceObject.ESCAPED_SHELL_STREAM_END_MARK.length + 1));
130
155
  return;
131
156
  }
132
- buffered += chunk;
133
- const markerIndex = buffered.indexOf(external_common_js_namespaceObject.ESCAPED_SHELL_STREAM_END_MARK);
134
- if (-1 === markerIndex) return;
135
- const beforeMark = lifecycle.completedBody(buffered.slice(0, markerIndex), 'shell');
136
- const afterMark = buffered.slice(markerIndex + external_common_js_namespaceObject.ESCAPED_SHELL_STREAM_END_MARK.length);
157
+ const shell = buffered.join('');
158
+ const beforeMark = lifecycle.completedBody(shell.slice(0, markerIndex), 'shell');
159
+ const afterMark = shell.slice(markerIndex + external_common_js_namespaceObject.ESCAPED_SHELL_STREAM_END_MARK.length);
137
160
  const completedShellBefore = (0, external_helmet_js_namespaceObject.createReplaceHelemt)((0, external_helmet_js_namespaceObject.getHelmetData)(extenders))(shellBefore);
138
161
  shellChunkStatus = external_shared_js_namespaceObject_1.ShellChunkStatus.FINISH;
139
- buffered = '';
140
- controller.enqueue(encoder.encode(`${completedShellBefore}${beforeMark}${shellAfter}`));
141
- if (afterMark.length > 0) controller.enqueue(encoder.encode(afterMark));
142
- for (const script of pendingScripts)controller.enqueue(encoder.encode(script));
162
+ buffered.length = 0;
163
+ coordinator?.writeReact(`${completedShellBefore}${beforeMark}${shellAfter}`);
164
+ if (afterMark.length > 0) coordinator?.writeReact(afterMark);
165
+ coordinator?.markShellFinished();
166
+ for (const script of pendingScripts)coordinator?.enqueueResolver(script);
143
167
  pendingScripts.length = 0;
144
168
  };
145
169
  const body = new TransformStream({
146
170
  start (controller) {
147
171
  bodyController = controller;
148
172
  },
149
- transform (chunk, controller) {
173
+ transform (chunk) {
150
174
  emit(decoder.decode(chunk, {
151
175
  stream: true
152
- }), controller);
176
+ }));
153
177
  },
154
- flush (controller) {
155
- bodyOpen = false;
156
- emit(decoder.decode(), controller);
178
+ async flush () {
179
+ emit(decoder.decode());
157
180
  if (shellChunkStatus !== external_shared_js_namespaceObject_1.ShellChunkStatus.FINISH) throw new Error('React SSR stream ended before the shell marker');
181
+ await deferredResolversComplete;
182
+ coordinator?.finish();
183
+ bodyOpen = false;
158
184
  }
159
185
  });
160
186
  bodyPipe = pendingSource.pipeTo(body.writable);
161
187
  bodyPipe.catch(()=>{});
162
188
  pendingSource = body.readable;
163
- const activeDeferreds = node_namespaceObject.storage.useContext?.()?.activeDeferreds;
189
+ const storageContext = node_namespaceObject.storage.useContext?.();
190
+ const activeDeferreds = storageContext?.activeDeferreds;
191
+ const deferredScriptKeys = storageContext?.deferredScriptKeys;
164
192
  const entries = activeDeferreds instanceof Map ? Array.from(activeDeferreds.entries()) : [];
165
- (0, external_deferredScript_js_namespaceObject.enqueueFromEntries)(entries, config.nonce, (script)=>{
193
+ if (entries.length > 0) deferredResolversComplete = (0, external_deferredScript_js_namespaceObject.enqueueFromEntries)(entries, deferredScriptKeys, config.nonce, (script)=>{
166
194
  if (!bodyOpen) return;
167
- if (shellChunkStatus === external_shared_js_namespaceObject_1.ShellChunkStatus.FINISH) try {
168
- bodyController.enqueue(encoder.encode(script));
169
- } catch {
170
- bodyOpen = false;
171
- }
195
+ if (shellChunkStatus === external_shared_js_namespaceObject_1.ShellChunkStatus.FINISH) coordinator?.enqueueResolver(script);
172
196
  else pendingScripts.push(script);
173
197
  });
174
198
  return (0, external_shared_js_namespaceObject.observeSSRStream)(pendingSource, {
175
199
  lifecycle,
176
200
  async onError (error) {
177
201
  bodyOpen = false;
202
+ coordinator?.abort();
178
203
  await bodyPipe?.catch(()=>{});
179
204
  reportError(error);
180
205
  },
181
206
  signal: request.signal,
182
207
  async onCancel (reason) {
183
208
  bodyOpen = false;
209
+ coordinator?.abort();
184
210
  await bodyPipe?.catch((error)=>{
185
211
  if (error !== reason) throw error;
186
212
  });
@@ -189,6 +215,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
189
215
  });
190
216
  } catch (error) {
191
217
  bodyOpen = false;
218
+ coordinator?.abort();
192
219
  if (void 0 !== pendingSource) try {
193
220
  await pendingSource.cancel(error);
194
221
  await bodyPipe?.catch(()=>{});
@@ -82,24 +82,30 @@ function buildDeferredDataScript(nonce, args) {
82
82
  const nonceAttr = void 0 !== nonce && '' !== nonce ? ` nonce="${nonce}"` : '';
83
83
  return `<script async${nonceAttr} data-fn-name="r" data-script-src="modern-run-router-data-fn" data-fn-args='${escaped}' suppressHydrationWarning>${constants_js_namespaceObject.runRouterDataFnStr}</script>`;
84
84
  }
85
- function enqueueFromEntries(entries, nonce, emit) {
85
+ function enqueueFromEntries(entries, deferredScriptKeys, nonce, emit) {
86
+ const pendingResolvers = [];
86
87
  entries.forEach(([routeId, value])=>{
87
88
  if (!isDeferredDataLike(value)) return;
88
- const pendingKeys = new Set(value.pendingKeys ?? []);
89
- pendingKeys.forEach((key)=>{
89
+ const serializedKeys = void 0 !== deferredScriptKeys ? deferredScriptKeys.get(routeId) ?? [] : value.pendingKeys ?? [];
90
+ serializedKeys.forEach((key)=>{
90
91
  const tracked = value.data?.[key];
91
- if (isPromiseLike(tracked)) tracked.then((val)=>emit(buildDeferredDataScript(nonce, [
92
+ if (isPromiseLike(tracked)) pendingResolvers.push(Promise.resolve(tracked).then((val)=>{
93
+ emit(buildDeferredDataScript(nonce, [
92
94
  routeId,
93
95
  key,
94
96
  val
95
- ])), (err)=>emit(buildDeferredDataScript(nonce, [
97
+ ]));
98
+ }, (err)=>{
99
+ emit(buildDeferredDataScript(nonce, [
96
100
  routeId,
97
101
  key,
98
102
  void 0,
99
103
  toErrorInfo(err)
100
- ])));
104
+ ]));
105
+ }));
101
106
  });
102
107
  });
108
+ return Promise.all(pendingResolvers).then(()=>void 0);
103
109
  }
104
110
  exports.buildDeferredDataScript = __webpack_exports__.buildDeferredDataScript;
105
111
  exports.enqueueFromEntries = __webpack_exports__.enqueueFromEntries;
@@ -0,0 +1,370 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ DeferredScriptOutputCoordinator: ()=>DeferredScriptOutputCoordinator
32
+ });
33
+ const constants_namespaceObject = require("@modern-js/utils/universal/constants");
34
+ const VOID_ELEMENTS = new Set([
35
+ 'area',
36
+ 'base',
37
+ 'br',
38
+ 'col',
39
+ 'embed',
40
+ 'hr',
41
+ 'img',
42
+ 'input',
43
+ 'link',
44
+ 'meta',
45
+ 'param',
46
+ 'source',
47
+ 'track',
48
+ 'wbr'
49
+ ]);
50
+ const RAW_TEXT_ELEMENTS = new Set([
51
+ 'iframe',
52
+ 'noembed',
53
+ 'noframes',
54
+ "script",
55
+ 'style',
56
+ 'textarea',
57
+ 'title',
58
+ 'xmp'
59
+ ]);
60
+ const REACT_SEGMENT_ID_PATTERN = new RegExp(`^${constants_namespaceObject.SSR_HYDRATION_ID_PREFIX}S:[0-9a-f]+$`);
61
+ const TABLE_SEGMENT_CHILDREN = new Set([
62
+ 'tbody',
63
+ 'tr',
64
+ 'colgroup'
65
+ ]);
66
+ function isAsciiAlpha(char) {
67
+ return /[A-Za-z]/.test(char);
68
+ }
69
+ function isWhitespace(char) {
70
+ return /[\t\n\f\r ]/.test(char);
71
+ }
72
+ function getSuffix(value, pattern) {
73
+ const start = Math.max(0, value.length - pattern.length);
74
+ for(let index = start; index < value.length; index++){
75
+ const suffix = value.slice(index);
76
+ if (pattern.startsWith(suffix)) return suffix;
77
+ }
78
+ return '';
79
+ }
80
+ class DeferredScriptOutputCoordinator {
81
+ enqueueResolver(script) {
82
+ if (this.closed) return;
83
+ this.pendingResolvers.push(script);
84
+ this.flushResolvers();
85
+ }
86
+ markShellFinished() {
87
+ if (this.closed) return;
88
+ this.shellFinished = true;
89
+ this.flushResolvers();
90
+ }
91
+ writeReact(chunk) {
92
+ if (this.closed || '' === chunk) return;
93
+ this.flushResolvers();
94
+ let emittedUntil = 0;
95
+ for(let index = 0; index < chunk.length; index++){
96
+ const wasSafe = this.isSafeBoundary();
97
+ this.consume(chunk[index]);
98
+ if (!wasSafe && this.isSafeBoundary() && this.pendingResolvers.length > 0) {
99
+ this.emit(chunk.slice(emittedUntil, index + 1));
100
+ emittedUntil = index + 1;
101
+ this.flushResolvers();
102
+ }
103
+ }
104
+ if (emittedUntil < chunk.length) this.emit(chunk.slice(emittedUntil));
105
+ }
106
+ finish() {
107
+ if (this.closed) return;
108
+ this.flushResolvers();
109
+ this.closed = true;
110
+ if (this.pendingResolvers.length > 0) throw new Error("Cannot emit deferred resolver scripts because the React stream ended outside a safe HTML boundary.");
111
+ }
112
+ abort() {
113
+ this.closed = true;
114
+ this.pendingResolvers.length = 0;
115
+ }
116
+ isSafeBoundary() {
117
+ return this.shellFinished && 'data' === this.state && 0 === this.openElements.length && !this.awaitingContinuationProtocol;
118
+ }
119
+ flushResolvers() {
120
+ if (!this.isSafeBoundary() || 0 === this.pendingResolvers.length) return;
121
+ while(this.pendingResolvers.length > 0){
122
+ const resolver = this.pendingResolvers.shift();
123
+ if (void 0 !== resolver) this.emit(resolver);
124
+ }
125
+ }
126
+ consume(char) {
127
+ switch(this.state){
128
+ case 'data':
129
+ if ('<' === char) this.state = 'tag-open';
130
+ return;
131
+ case 'tag-open':
132
+ if ('/' === char) {
133
+ this.currentTagName = '';
134
+ this.state = 'end-tag-name';
135
+ } else if ('!' === char) {
136
+ this.declarationPrefix = '';
137
+ this.state = 'markup-declaration';
138
+ } else if ('?' === char) this.state = 'bogus-comment';
139
+ else if (isAsciiAlpha(char)) {
140
+ this.startTag(char);
141
+ this.state = 'start-tag-name';
142
+ } else this.state = 'data';
143
+ return;
144
+ case 'start-tag-name':
145
+ if (isWhitespace(char)) this.state = 'before-attribute-name';
146
+ else if ('/' === char) this.state = 'self-closing-start-tag';
147
+ else if ('>' === char) this.completeStartTag(false);
148
+ else this.currentTagName += char.toLowerCase();
149
+ return;
150
+ case 'before-attribute-name':
151
+ if (isWhitespace(char)) return;
152
+ if ('/' === char) this.state = 'self-closing-start-tag';
153
+ else if ('>' === char) this.completeStartTag(false);
154
+ else {
155
+ this.startAttribute(char);
156
+ this.state = 'attribute-name';
157
+ }
158
+ return;
159
+ case 'attribute-name':
160
+ if (isWhitespace(char)) this.state = 'after-attribute-name';
161
+ else if ('=' === char) {
162
+ this.currentAttributeHasValue = true;
163
+ this.state = 'before-attribute-value';
164
+ } else if ('/' === char) {
165
+ this.completeAttribute();
166
+ this.state = 'self-closing-start-tag';
167
+ } else if ('>' === char) this.completeStartTag(false);
168
+ else this.currentAttributeName += char.toLowerCase();
169
+ return;
170
+ case 'after-attribute-name':
171
+ if (isWhitespace(char)) return;
172
+ if ('=' === char) {
173
+ this.currentAttributeHasValue = true;
174
+ this.state = 'before-attribute-value';
175
+ } else if ('/' === char) {
176
+ this.completeAttribute();
177
+ this.state = 'self-closing-start-tag';
178
+ } else if ('>' === char) this.completeStartTag(false);
179
+ else {
180
+ this.completeAttribute();
181
+ this.startAttribute(char);
182
+ this.state = 'attribute-name';
183
+ }
184
+ return;
185
+ case 'before-attribute-value':
186
+ if (isWhitespace(char)) return;
187
+ if ('"' === char) this.state = 'attribute-value-double-quoted';
188
+ else if ("'" === char) this.state = 'attribute-value-single-quoted';
189
+ else if ('>' === char) this.completeStartTag(false);
190
+ else {
191
+ this.currentAttributeValue += char;
192
+ this.state = 'attribute-value-unquoted';
193
+ }
194
+ return;
195
+ case 'attribute-value-double-quoted':
196
+ if ('"' === char) {
197
+ this.completeAttribute();
198
+ this.state = 'before-attribute-name';
199
+ } else this.currentAttributeValue += char;
200
+ return;
201
+ case 'attribute-value-single-quoted':
202
+ if ("'" === char) {
203
+ this.completeAttribute();
204
+ this.state = 'before-attribute-name';
205
+ } else this.currentAttributeValue += char;
206
+ return;
207
+ case 'attribute-value-unquoted':
208
+ if (isWhitespace(char)) {
209
+ this.completeAttribute();
210
+ this.state = 'before-attribute-name';
211
+ } else if ('>' === char) this.completeStartTag(false);
212
+ else this.currentAttributeValue += char;
213
+ return;
214
+ case 'self-closing-start-tag':
215
+ if ('>' === char) this.completeStartTag(true);
216
+ else if (!isWhitespace(char)) {
217
+ this.startAttribute(char);
218
+ this.state = 'attribute-name';
219
+ }
220
+ return;
221
+ case 'end-tag-name':
222
+ if (isWhitespace(char)) this.state = 'after-end-tag-name';
223
+ else if ('>' === char) this.completeEndTag();
224
+ else this.currentTagName += char.toLowerCase();
225
+ return;
226
+ case 'after-end-tag-name':
227
+ if ('>' === char) this.completeEndTag();
228
+ return;
229
+ case 'markup-declaration':
230
+ if (this.declarationPrefix.length < 2 && '-' === char) {
231
+ this.declarationPrefix += char;
232
+ if ('--' === this.declarationPrefix) {
233
+ this.commentTail = '';
234
+ this.state = 'comment';
235
+ }
236
+ } else this.state = '>' === char ? 'data' : 'declaration';
237
+ return;
238
+ case 'declaration':
239
+ if ('>' === char) this.state = 'data';
240
+ return;
241
+ case 'comment':
242
+ this.commentTail = `${this.commentTail}${char}`.slice(-3);
243
+ if ('-->' === this.commentTail) this.state = 'data';
244
+ return;
245
+ case 'bogus-comment':
246
+ if ('>' === char) this.state = 'data';
247
+ return;
248
+ case 'raw-text':
249
+ this.consumeRawText(char);
250
+ return;
251
+ case 'raw-end-tag':
252
+ if ('>' === char) this.completeRawTextEndTag();
253
+ else if (!isWhitespace(char)) {
254
+ this.state = 'raw-text';
255
+ this.rawTextSearch = getSuffix(`${this.rawTextSearch}${char.toLowerCase()}`, `</${this.rawTextElement}`);
256
+ }
257
+ }
258
+ }
259
+ startTag(char) {
260
+ this.currentTagName = char.toLowerCase();
261
+ this.currentAttributes = new Map();
262
+ this.currentAttributeName = '';
263
+ this.currentAttributeValue = '';
264
+ this.currentAttributeHasValue = false;
265
+ }
266
+ startAttribute(char) {
267
+ this.currentAttributeName = char.toLowerCase();
268
+ this.currentAttributeValue = '';
269
+ this.currentAttributeHasValue = false;
270
+ }
271
+ completeAttribute() {
272
+ if ('' === this.currentAttributeName) return;
273
+ this.currentAttributes.set(this.currentAttributeName, this.currentAttributeHasValue ? this.currentAttributeValue : true);
274
+ this.currentAttributeName = '';
275
+ this.currentAttributeValue = '';
276
+ this.currentAttributeHasValue = false;
277
+ }
278
+ completeStartTag(selfClosing) {
279
+ this.completeAttribute();
280
+ const tagName = this.currentTagName;
281
+ const id = this.currentAttributes.get('id');
282
+ const hasReactSegmentId = 'string' == typeof id && REACT_SEGMENT_ID_PATTERN.test(id);
283
+ const hasHiddenAttribute = this.currentAttributes.has('hidden');
284
+ const isHiddenSegmentTable = 'table' === tagName && hasHiddenAttribute && !hasReactSegmentId;
285
+ const isTableSegmentChild = hasReactSegmentId && TABLE_SEGMENT_CHILDREN.has(tagName) && this.openElements[this.openElements.length - 1]?.isSegmentTableWrapper === true;
286
+ const isContinuationContainer = hasReactSegmentId && ('div' === tagName && hasHiddenAttribute || ('svg' === tagName || 'math' === tagName) && void 0 !== id && 'true' === this.currentAttributes.get('aria-hidden') && 'display:none' === this.currentAttributes.get('style') || 'table' === tagName && hasHiddenAttribute || isTableSegmentChild);
287
+ this.continuationProtocolScript = "script" === tagName && this.awaitingContinuationProtocol;
288
+ this.continuationProtocolTail = '';
289
+ this.hasContinuationProtocolCall = false;
290
+ if (!selfClosing && !VOID_ELEMENTS.has(tagName)) this.openElements.push({
291
+ tagName,
292
+ isContinuationContainer,
293
+ isSegmentTableWrapper: isHiddenSegmentTable
294
+ });
295
+ this.currentTagName = '';
296
+ this.currentAttributes = new Map();
297
+ this.currentAttributeName = '';
298
+ this.currentAttributeValue = '';
299
+ this.currentAttributeHasValue = false;
300
+ if (!selfClosing && RAW_TEXT_ELEMENTS.has(tagName)) {
301
+ this.rawTextElement = tagName;
302
+ this.rawTextSearch = '';
303
+ this.state = 'raw-text';
304
+ } else this.state = 'data';
305
+ }
306
+ completeEndTag() {
307
+ this.closeOpenElement(this.currentTagName);
308
+ this.currentTagName = '';
309
+ this.state = 'data';
310
+ }
311
+ consumeRawText(char) {
312
+ const rawTextElement = this.rawTextElement;
313
+ if (void 0 === rawTextElement) {
314
+ this.state = 'data';
315
+ return;
316
+ }
317
+ const endTagPrefix = `</${rawTextElement}`;
318
+ if (this.continuationProtocolScript) {
319
+ this.continuationProtocolTail = `${this.continuationProtocolTail}${char}`.slice(-4);
320
+ if (/\$(?:RC|RS|RX|RB|RR)\b/.test(this.continuationProtocolTail)) this.hasContinuationProtocolCall = true;
321
+ }
322
+ this.rawTextSearch = getSuffix(`${this.rawTextSearch}${char.toLowerCase()}`, endTagPrefix);
323
+ if (this.rawTextSearch === endTagPrefix) this.state = 'raw-end-tag';
324
+ }
325
+ completeRawTextEndTag() {
326
+ const rawTextElement = this.rawTextElement;
327
+ if (void 0 !== rawTextElement) this.closeOpenElement(rawTextElement);
328
+ if ("script" === rawTextElement && this.continuationProtocolScript && this.hasContinuationProtocolCall) this.awaitingContinuationProtocol = false;
329
+ this.rawTextElement = void 0;
330
+ this.rawTextSearch = '';
331
+ this.continuationProtocolScript = false;
332
+ this.continuationProtocolTail = '';
333
+ this.hasContinuationProtocolCall = false;
334
+ this.state = 'data';
335
+ }
336
+ closeOpenElement(tagName) {
337
+ const matchingIndex = this.openElements.map((element)=>element.tagName).lastIndexOf(tagName);
338
+ if (-1 === matchingIndex) return;
339
+ const closedElements = this.openElements.splice(matchingIndex);
340
+ const closedContinuation = closedElements.some((element)=>element.isContinuationContainer);
341
+ if (closedContinuation) this.awaitingContinuationProtocol = true;
342
+ }
343
+ constructor(emit){
344
+ this.emit = emit;
345
+ this.pendingResolvers = [];
346
+ this.openElements = [];
347
+ this.shellFinished = false;
348
+ this.closed = false;
349
+ this.state = 'data';
350
+ this.currentTagName = '';
351
+ this.currentAttributes = new Map();
352
+ this.currentAttributeName = '';
353
+ this.currentAttributeValue = '';
354
+ this.currentAttributeHasValue = false;
355
+ this.declarationPrefix = '';
356
+ this.commentTail = '';
357
+ this.rawTextSearch = '';
358
+ this.continuationProtocolScript = false;
359
+ this.continuationProtocolTail = '';
360
+ this.hasContinuationProtocolCall = false;
361
+ this.awaitingContinuationProtocol = false;
362
+ }
363
+ }
364
+ exports.DeferredScriptOutputCoordinator = __webpack_exports__.DeferredScriptOutputCoordinator;
365
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
366
+ "DeferredScriptOutputCoordinator"
367
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
368
+ Object.defineProperty(exports, '__esModule', {
369
+ value: true
370
+ });
@@ -28,6 +28,7 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
+ SHELL_PROGRESSIVE_CHUNK_SIZE: ()=>SHELL_PROGRESSIVE_CHUNK_SIZE,
31
32
  ShellChunkStatus: ()=>shared_ShellChunkStatus,
32
33
  createRenderStreaming: ()=>createRenderStreaming,
33
34
  encodeForWebStream: ()=>encodeForWebStream,
@@ -46,6 +47,7 @@ var shared_ShellChunkStatus = /*#__PURE__*/ function(ShellChunkStatus) {
46
47
  ShellChunkStatus[ShellChunkStatus["FINISH"] = 1] = "FINISH";
47
48
  return ShellChunkStatus;
48
49
  }({});
50
+ const SHELL_PROGRESSIVE_CHUNK_SIZE = Number.MAX_SAFE_INTEGER;
49
51
  const SHOULD_STREAM_ALL_HEADER = 'x-should-stream-all';
50
52
  function parseShouldStreamAllFlag(value) {
51
53
  if (!value) return;
@@ -143,12 +145,14 @@ function createRenderStreaming(createReadableStreamPromise) {
143
145
  return stream;
144
146
  };
145
147
  }
148
+ exports.SHELL_PROGRESSIVE_CHUNK_SIZE = __webpack_exports__.SHELL_PROGRESSIVE_CHUNK_SIZE;
146
149
  exports.ShellChunkStatus = __webpack_exports__.ShellChunkStatus;
147
150
  exports.createRenderStreaming = __webpack_exports__.createRenderStreaming;
148
151
  exports.encodeForWebStream = __webpack_exports__.encodeForWebStream;
149
152
  exports.getReadableStreamFromString = __webpack_exports__.getReadableStreamFromString;
150
153
  exports.resolveStreamingMode = __webpack_exports__.resolveStreamingMode;
151
154
  for(var __rspack_i in __webpack_exports__)if (-1 === [
155
+ "SHELL_PROGRESSIVE_CHUNK_SIZE",
152
156
  "ShellChunkStatus",
153
157
  "createRenderStreaming",
154
158
  "encodeForWebStream",
@@ -39,12 +39,13 @@ __webpack_require__.r(__webpack_exports__);
39
39
  __webpack_require__.d(__webpack_exports__, {
40
40
  renderString: ()=>renderString
41
41
  });
42
+ const context_namespaceObject = require("@modern-js/runtime/context");
42
43
  const time_namespaceObject = require("@modern-js/runtime-utils/time");
43
44
  const constants_namespaceObject = require("@modern-js/utils/universal/constants");
44
45
  const server_namespaceObject = require("react-dom/server");
45
46
  var server_default = /*#__PURE__*/ __webpack_require__.n(server_namespaceObject);
46
47
  const external_constants_js_namespaceObject = require("../../constants.js");
47
- const index_js_namespaceObject = require("../../context/index.js");
48
+ const index_js_namespaceObject = require("../../context/monitors/index.js");
48
49
  const wrapper_js_namespaceObject = require("../../react/wrapper.js");
49
50
  const external_constants_js_namespaceObject_1 = require("../constants.js");
50
51
  const external_helmet_js_namespaceObject = require("../helmet.js");
@@ -91,7 +92,7 @@ const renderString = async (request, serverRoot, options)=>{
91
92
  useJsonScript: config.useJsonScript,
92
93
  lifecycle
93
94
  }));
94
- const internalRuntimeContext = (0, index_js_namespaceObject.getGlobalInternalRuntimeContext)();
95
+ const internalRuntimeContext = (0, context_namespaceObject.getGlobalInternalRuntimeContext)();
95
96
  const hooks = internalRuntimeContext.hooks;
96
97
  const extraCollectors = hooks.extendStringSSRCollectors.call({
97
98
  chunkSet,
@@ -102,14 +103,15 @@ const renderString = async (request, serverRoot, options)=>{
102
103
  config,
103
104
  platform: 'node',
104
105
  mode: 'string',
105
- isRsc: true === (0, index_js_namespaceObject.getGlobalEnableRsc)()
106
+ monitors: (0, index_js_namespaceObject.getMonitors)(),
107
+ isRsc: true === (0, context_namespaceObject.getGlobalEnableRsc)()
106
108
  }
107
109
  });
108
110
  for (const c of extraCollectors)if (c) collectors.unshift(c);
109
111
  let rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(serverRoot, Object.assign(runtimeContext, {
110
112
  ssr: true
111
113
  }));
112
- if (true === (0, index_js_namespaceObject.getGlobalEnableRsc)() && false === runtimeContext.isBrowser) rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeComponentResolver)(rootElement, hooks);
114
+ if (true === (0, context_namespaceObject.getGlobalEnableRsc)() && false === runtimeContext.isBrowser) rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeComponentResolver)(rootElement, hooks);
113
115
  const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext.ssrContext?.htmlModifiers || [], tracer, request.signal, lifecycle, loadableCollector.stylesheetInfo);
114
116
  return html;
115
117
  };