@modern-js/runtime 3.9.1 → 3.9.3

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 (45) hide show
  1. package/dist/cjs/cli/template.server.js +1 -2
  2. package/dist/cjs/core/browser/hydrate.js +13 -11
  3. package/dist/cjs/core/server/requestHandler.js +2 -0
  4. package/dist/cjs/core/server/stream/beforeTemplate.js +3 -3
  5. package/dist/cjs/core/server/stream/createReadableStream.js +51 -8
  6. package/dist/cjs/core/server/stream/createReadableStream.worker.js +37 -15
  7. package/dist/cjs/core/server/stream/deferredScript.js +12 -6
  8. package/dist/cjs/core/server/stream/deferredScriptOutputCoordinator.js +370 -0
  9. package/dist/cjs/core/server/string/loadable.js +4 -4
  10. package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
  11. package/dist/cjs/router/cli/code/templates.js +1 -1
  12. package/dist/cjs/router/cli/code/utils.js +2 -2
  13. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +13 -10
  14. package/dist/cjs/router/runtime/plugin.node.js +1 -1
  15. package/dist/esm/cli/template.server.mjs +1 -2
  16. package/dist/esm/core/browser/hydrate.mjs +13 -11
  17. package/dist/esm/core/server/requestHandler.mjs +2 -0
  18. package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
  19. package/dist/esm/core/server/stream/createReadableStream.mjs +51 -8
  20. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +37 -15
  21. package/dist/esm/core/server/stream/deferredScript.mjs +12 -6
  22. package/dist/esm/core/server/stream/deferredScriptOutputCoordinator.mjs +332 -0
  23. package/dist/esm/core/server/string/loadable.mjs +4 -4
  24. package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
  25. package/dist/esm/router/cli/code/templates.mjs +1 -1
  26. package/dist/esm/router/cli/code/utils.mjs +2 -2
  27. package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +13 -10
  28. package/dist/esm/router/runtime/plugin.node.mjs +1 -1
  29. package/dist/esm-node/cli/template.server.mjs +1 -2
  30. package/dist/esm-node/core/browser/hydrate.mjs +13 -11
  31. package/dist/esm-node/core/server/requestHandler.mjs +2 -0
  32. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
  33. package/dist/esm-node/core/server/stream/createReadableStream.mjs +51 -8
  34. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +37 -15
  35. package/dist/esm-node/core/server/stream/deferredScript.mjs +12 -6
  36. package/dist/esm-node/core/server/stream/deferredScriptOutputCoordinator.mjs +333 -0
  37. package/dist/esm-node/core/server/string/loadable.mjs +4 -4
  38. package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
  39. package/dist/esm-node/router/cli/code/templates.mjs +1 -1
  40. package/dist/esm-node/router/cli/code/utils.mjs +2 -2
  41. package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +13 -10
  42. package/dist/esm-node/router/runtime/plugin.node.mjs +1 -1
  43. package/dist/types/core/server/stream/deferredScript.d.ts +1 -1
  44. package/dist/types/core/server/stream/deferredScriptOutputCoordinator.d.ts +72 -0
  45. package/package.json +12 -12
@@ -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) {
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 (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 (!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 (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
+ });
@@ -39,8 +39,8 @@ const extname = (uri)=>{
39
39
  const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
40
40
  const checkIsInline = (chunk, enableInline)=>{
41
41
  if ('production' !== process.env.NODE_ENV) return false;
42
- if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
43
- return Boolean(enableInline);
42
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
43
+ else return Boolean(enableInline);
44
44
  };
45
45
  const readAsset = async (chunk)=>{
46
46
  const fs = await import("fs/promises");
@@ -108,7 +108,7 @@ class LoadableCollector {
108
108
  const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
109
109
  const script = `<script${attributes} src="${chunk.url}"></script>`;
110
110
  if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
111
- return script;
111
+ else return script;
112
112
  }));
113
113
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
114
114
  }
@@ -119,7 +119,7 @@ class LoadableCollector {
119
119
  const css = await Promise.all(chunks.filter((chunk)=>!(0, external_utils_js_namespaceObject.hasStylesheetLink)(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
120
120
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
121
121
  if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
122
- return link;
122
+ else return link;
123
123
  }));
124
124
  chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
125
125
  }
@@ -76,8 +76,7 @@ const optimizeRoute = (routeTree)=>{
76
76
  children: optimizedChildren
77
77
  }
78
78
  ];
79
- }
80
- {
79
+ } else {
81
80
  const newRoutes = children.map((child)=>{
82
81
  const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
83
82
  const newRoute = {
@@ -419,7 +419,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
419
419
  enableRsc: true,
420
420
  });
421
421
  `;
422
- return `${imports.join('\n')}
422
+ else return `${imports.join('\n')}
423
423
 
424
424
  import { routes } from './routes';
425
425
 
@@ -61,7 +61,7 @@ const walkDirectory = (dir)=>external_fs_default().readdirSync(dir).reduce((prev
61
61
  ...previous,
62
62
  ...walkDirectory(filePath)
63
63
  ];
64
- return [
64
+ else return [
65
65
  ...previous,
66
66
  filePath
67
67
  ];
@@ -78,7 +78,7 @@ const isPageComponentFile = (filePath)=>{
78
78
  };
79
79
  const replaceWithAlias = (base, filePath, alias)=>{
80
80
  if (filePath.includes(base)) return (0, utils_namespaceObject.normalizeToPosixPath)(external_path_default().join(alias, external_path_default().relative(base, filePath)));
81
- return filePath;
81
+ else return filePath;
82
82
  };
83
83
  const parseModule = async ({ source, filename })=>{
84
84
  let content = source;
@@ -45,7 +45,8 @@ const DeferredDataScripts = (props)=>{
45
45
  }, []);
46
46
  const deferredScripts = (0, external_react_namespaceObject.useMemo)(()=>{
47
47
  if (!staticContext) return null;
48
- const activeDeferreds = node_namespaceObject.storage.useContext().activeDeferreds;
48
+ const requestStorage = node_namespaceObject.storage.useContext();
49
+ const activeDeferreds = requestStorage.activeDeferreds;
49
50
  const _ROUTER_DATA = {
50
51
  loaderData: staticContext.loaderData,
51
52
  errors: (0, external_utils_js_namespaceObject.serializeErrors)(staticContext.errors)
@@ -58,6 +59,7 @@ const DeferredDataScripts = (props)=>{
58
59
  const deferredDataScripts = [];
59
60
  const initialScripts = Array.from(activeDeferreds.entries()).map(([routeId, deferredData])=>{
60
61
  const pendingKeys = new Set(deferredData.pendingKeys);
62
+ requestStorage.deferredScriptKeys?.set(routeId, Array.from(pendingKeys));
61
63
  const { deferredKeys } = deferredData;
62
64
  const deferredKeyPromiseManifests = deferredKeys.map((key)=>{
63
65
  if (pendingKeys.has(key)) return {
@@ -68,7 +70,7 @@ const DeferredDataScripts = (props)=>{
68
70
  (0, node_namespaceObject.serializeJson)(key)
69
71
  ]
70
72
  };
71
- {
73
+ else {
72
74
  const trackedPromise = deferredData.data[key];
73
75
  if (void 0 !== trackedPromise._error) {
74
76
  const error = {
@@ -83,15 +85,16 @@ const DeferredDataScripts = (props)=>{
83
85
  (0, node_namespaceObject.serializeJson)(error)
84
86
  ]
85
87
  };
88
+ } else {
89
+ if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
90
+ return {
91
+ key,
92
+ routerDataFnName: 'p',
93
+ routerDataFnArgs: [
94
+ (0, node_namespaceObject.serializeJson)(trackedPromise._data)
95
+ ]
96
+ };
86
97
  }
87
- if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
88
- return {
89
- key,
90
- routerDataFnName: 'p',
91
- routerDataFnArgs: [
92
- (0, node_namespaceObject.serializeJson)(trackedPromise._data)
93
- ]
94
- };
95
98
  }
96
99
  });
97
100
  return {
@@ -149,7 +149,7 @@ const routerPlugin = (userConfig = {})=>({
149
149
  }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rsc_router_js_namespaceObject.RSCStaticRouter, {
150
150
  basename: basename
151
151
  });
152
- {
152
+ else {
153
153
  const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
154
154
  children: [
155
155
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(router_namespaceObject.StaticRouterProvider, {
@@ -108,8 +108,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
108
108
  return `
109
109
  export * from '${realEntryPath}';
110
110
  export { default as requestHandler } from '${realEntryPath}'`;
111
- }
112
- {
111
+ } else {
113
112
  const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
114
113
  const serverEntry = transformServerEntry(entrySource, {
115
114
  metaName: metaName || 'modern-js',
@@ -26,7 +26,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
26
26
  if ('stream' === renderMode) return streamSSRHydrate();
27
27
  function streamSSRHydrate() {
28
28
  if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
29
- {
29
+ else {
30
30
  const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
31
31
  callback: callback,
32
32
  children: App
@@ -37,19 +37,21 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
37
37
  return stringSSRHydrate();
38
38
  function stringSSRHydrate() {
39
39
  if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
40
- if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
41
- loadableReady(()=>{
42
- const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
43
- callback: callback,
44
- children: App
40
+ else {
41
+ if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
42
+ loadableReady(()=>{
43
+ const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
44
+ callback: callback,
45
+ children: App
46
+ });
47
+ ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
48
+ resolve(root);
45
49
  });
46
- ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
47
- resolve(root);
48
50
  });
49
51
  });
50
- });
51
- console.warn(`unknow render level: ${renderLevel}, execute render()`);
52
- return ModernRender(wrapRuntimeContextProvider(App, context));
52
+ console.warn(`unknow render level: ${renderLevel}, execute render()`);
53
+ return ModernRender(wrapRuntimeContextProvider(App, context));
54
+ }
53
55
  }
54
56
  }
55
57
  export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
@@ -101,12 +101,14 @@ const createRequestHandler = async (handleRequest, createRequestOptions)=>{
101
101
  status: -1
102
102
  };
103
103
  const activeDeferreds = new Map();
104
+ const deferredScriptKeys = new Map();
104
105
  return storage.run({
105
106
  headers: headersData,
106
107
  request,
107
108
  monitors: options.monitors,
108
109
  responseProxy,
109
110
  activeDeferreds,
111
+ deferredScriptKeys,
110
112
  serverPayload: void 0
111
113
  }, async ()=>{
112
114
  const Root = createRoot();
@@ -12,8 +12,8 @@ const readAsset = async (chunk)=>{
12
12
  };
13
13
  const checkIsInline = (chunk, enableInline)=>{
14
14
  if ('production' !== process.env.NODE_ENV) return false;
15
- if (enableInline instanceof RegExp) return enableInline.test(chunk);
16
- return Boolean(enableInline);
15
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk);
16
+ else return Boolean(enableInline);
17
17
  };
18
18
  async function buildShellBeforeTemplate(beforeAppTemplate, options) {
19
19
  const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
@@ -54,7 +54,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
54
54
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
55
55
  const link = `<link href="${chunk}" rel="stylesheet" />`;
56
56
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
57
- return link;
57
+ else return link;
58
58
  }));
59
59
  return `${styles.join('')}`;
60
60
  }