@modern-js/runtime 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/router/runtime/DeferredDataScripts.js +2 -140
  3. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +165 -0
  4. package/dist/cjs/ssr/serverRender/index.js +8 -0
  5. package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
  6. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +25 -9
  7. package/dist/cjs/ssr/serverRender/utils.js +3 -0
  8. package/dist/esm/router/runtime/DeferredDataScripts.js +2 -164
  9. package/dist/esm/router/runtime/DeferredDataScripts.node.js +166 -0
  10. package/dist/esm/ssr/serverRender/index.js +6 -1
  11. package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
  12. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +24 -11
  13. package/dist/esm/ssr/serverRender/utils.js +2 -1
  14. package/dist/esm-node/router/runtime/DeferredDataScripts.js +2 -144
  15. package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +148 -0
  16. package/dist/esm-node/ssr/serverRender/index.js +8 -0
  17. package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +1 -1
  18. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +25 -9
  19. package/dist/esm-node/ssr/serverRender/utils.js +2 -0
  20. package/dist/types/router/runtime/DeferredDataScripts.d.ts +2 -7
  21. package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +8 -0
  22. package/dist/types/router/runtime/index.d.ts +1 -1
  23. package/dist/types/ssr/serverRender/renderToStream/renderToPipe.worker.d.ts +1 -1
  24. package/dist/types/ssr/serverRender/utils.d.ts +1 -0
  25. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - e8c580125d: fix: remove `serialze-javascript` from client bundle
8
+ fix: 移除客户端构建产物中的 `serialze-javascript`
9
+ - 7035d5c22f: feat: support streaming ssr in worker
10
+
11
+ feat: worker 支持 streaming ssr
12
+
13
+ - 49bb8cd0ef: fix: move chunkmap.css comment to bottom of head
14
+ fix: 将 chunkmap.css 标记移动到 head 底部
15
+ - 755a053579: fix: export missing react-router types
16
+ fix: 导出缺少的 react-router 类型
17
+ - @modern-js/plugin@2.9.0
18
+ - @modern-js/types@2.9.0
19
+ - @modern-js/utils@2.9.0
20
+
3
21
  ## 2.8.0
4
22
 
5
23
  ### Patch Changes
@@ -20,146 +20,8 @@ __export(DeferredDataScripts_exports, {
20
20
  default: () => DeferredDataScripts_default
21
21
  });
22
22
  module.exports = __toCommonJS(DeferredDataScripts_exports);
23
- var import_jsx_runtime = require("react/jsx-runtime");
24
- var import_react = require("react");
25
- var import_react_router_dom = require("react-router-dom");
26
- var import_serialize = require("@modern-js/utils/serialize");
27
- var import_common = require("../../common");
28
- var import_utils = require("./utils");
29
- const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
30
- const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
31
- const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resovle(e)};`;
32
- const DeferredDataScripts = () => {
33
- const context = (0, import_react.useContext)(import_react_router_dom.UNSAFE_DataRouterContext);
34
- const { staticContext } = context || {};
35
- const hydratedRef = (0, import_react.useRef)(false);
36
- (0, import_react.useEffect)(() => {
37
- hydratedRef.current = true;
38
- }, []);
39
- const deferredScripts = (0, import_react.useMemo)(() => {
40
- if (!staticContext) {
41
- return null;
42
- }
43
- const activeDeferreds = staticContext.activeDeferreds || [];
44
- const _ROUTER_DATA = {
45
- loaderData: staticContext.loaderData,
46
- errors: (0, import_utils.serializeErrors)(staticContext.errors)
47
- };
48
- let initialScripts = [
49
- `_ROUTER_DATA = ${(0, import_serialize.serializeJson)(_ROUTER_DATA)};`,
50
- `_ROUTER_DATA.s = ${setupFnStr}`,
51
- `_ROUTER_DATA.r = ${resolveFnStr}`,
52
- `_ROUTER_DATA.p = ${preResolvedFnStr}`
53
- ].join("\n");
54
- const deferredDataScripts = [];
55
- initialScripts += Object.entries(activeDeferreds).map(([routeId, deferredData]) => {
56
- const pendingKeys = new Set(deferredData.pendingKeys);
57
- const { deferredKeys } = deferredData;
58
- const deferredKeyPromiseStr = deferredKeys.map((key) => {
59
- if (pendingKeys.has(key)) {
60
- deferredDataScripts.push(
61
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
62
- DeferredDataScript,
63
- {
64
- data: deferredData.data[key],
65
- dataKey: key,
66
- routeId
67
- },
68
- `${routeId} | ${key}`
69
- )
70
- );
71
- return `${JSON.stringify(key)}: _ROUTER_DATA.s(${JSON.stringify(
72
- routeId
73
- )},${JSON.stringify(key)}) `;
74
- } else {
75
- const trackedPromise = deferredData.data[key];
76
- if (typeof trackedPromise._error !== "undefined") {
77
- const error = {
78
- message: trackedPromise._error.message,
79
- stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
80
- };
81
- return `${JSON.stringify(
82
- key
83
- )}: _ROUTER_DATA.p(${void 0}, ${(0, import_serialize.serializeJson)(error)})`;
84
- } else {
85
- if (typeof trackedPromise._data === "undefined") {
86
- throw new Error(
87
- `The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`
88
- );
89
- }
90
- return `${JSON.stringify(key)}: _ROUTER_DATA.p(${(0, import_serialize.serializeJson)(
91
- trackedPromise._data
92
- )})`;
93
- }
94
- }
95
- }).join(",\n");
96
- return `Object.assign(_ROUTER_DATA.loaderData[${JSON.stringify(
97
- routeId
98
- )}], {${deferredKeyPromiseStr}});`;
99
- }).join("\n");
100
- return [initialScripts, deferredDataScripts];
101
- }, []);
102
- if (!deferredScripts) {
103
- return null;
104
- }
105
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
106
- !hydratedRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
- "script",
108
- {
109
- async: true,
110
- suppressHydrationWarning: true,
111
- dangerouslySetInnerHTML: { __html: deferredScripts[0] }
112
- }
113
- ),
114
- !hydratedRef.current && deferredScripts[1],
115
- import_common.JSX_SHELL_STREAM_END_MARK
116
- ] });
117
- };
118
- const DeferredDataScript = ({
119
- data,
120
- routeId,
121
- dataKey
122
- }) => {
123
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: typeof document === "undefined" && data && dataKey && routeId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
- import_react_router_dom.Await,
125
- {
126
- resolve: data,
127
- errorElement: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorDeferredDataScript, { routeId, dataKey }),
128
- children: (data2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
- "script",
130
- {
131
- async: true,
132
- suppressHydrationWarning: true,
133
- dangerouslySetInnerHTML: {
134
- __html: `_ROUTER_DATA.r(${JSON.stringify(
135
- routeId
136
- )}, ${JSON.stringify(dataKey)}, ${(0, import_serialize.serializeJson)(data2)});`
137
- }
138
- }
139
- )
140
- }
141
- ) : null });
142
- };
143
- const ErrorDeferredDataScript = ({
144
- routeId,
145
- dataKey
146
- }) => {
147
- const error = (0, import_react_router_dom.useAsyncError)();
148
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
149
- "script",
150
- {
151
- suppressHydrationWarning: true,
152
- dangerouslySetInnerHTML: {
153
- __html: `_ROUTER_DATA.r(${JSON.stringify(routeId)}, ${JSON.stringify(
154
- dataKey
155
- )}, ${void 0}, ${(0, import_serialize.serializeJson)({
156
- message: error.message,
157
- stack: error.stack
158
- })});`
159
- }
160
- }
161
- );
23
+ var DeferredDataScripts_default = () => {
24
+ return null;
162
25
  };
163
- var DeferredDataScripts_default = DeferredDataScripts;
164
26
  // Annotate the CommonJS export names for ESM import in node:
165
27
  0 && (module.exports = {});
@@ -0,0 +1,165 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var DeferredDataScripts_node_exports = {};
19
+ __export(DeferredDataScripts_node_exports, {
20
+ default: () => DeferredDataScripts_node_default
21
+ });
22
+ module.exports = __toCommonJS(DeferredDataScripts_node_exports);
23
+ var import_jsx_runtime = require("react/jsx-runtime");
24
+ var import_react = require("react");
25
+ var import_react_router_dom = require("react-router-dom");
26
+ var import_serialize = require("@modern-js/utils/serialize");
27
+ var import_common = require("../../common");
28
+ var import_utils = require("./utils");
29
+ const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
30
+ const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
31
+ const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resovle(e)};`;
32
+ const DeferredDataScripts = () => {
33
+ const context = (0, import_react.useContext)(import_react_router_dom.UNSAFE_DataRouterContext);
34
+ const { staticContext } = context || {};
35
+ const hydratedRef = (0, import_react.useRef)(false);
36
+ (0, import_react.useEffect)(() => {
37
+ hydratedRef.current = true;
38
+ }, []);
39
+ const deferredScripts = (0, import_react.useMemo)(() => {
40
+ if (!staticContext) {
41
+ return null;
42
+ }
43
+ const activeDeferreds = staticContext.activeDeferreds || [];
44
+ const _ROUTER_DATA = {
45
+ loaderData: staticContext.loaderData,
46
+ errors: (0, import_utils.serializeErrors)(staticContext.errors)
47
+ };
48
+ let initialScripts = [
49
+ `_ROUTER_DATA = ${(0, import_serialize.serializeJson)(_ROUTER_DATA)};`,
50
+ `_ROUTER_DATA.s = ${setupFnStr}`,
51
+ `_ROUTER_DATA.r = ${resolveFnStr}`,
52
+ `_ROUTER_DATA.p = ${preResolvedFnStr}`
53
+ ].join("\n");
54
+ const deferredDataScripts = [];
55
+ initialScripts += Object.entries(activeDeferreds).map(([routeId, deferredData]) => {
56
+ const pendingKeys = new Set(deferredData.pendingKeys);
57
+ const { deferredKeys } = deferredData;
58
+ const deferredKeyPromiseStr = deferredKeys.map((key) => {
59
+ if (pendingKeys.has(key)) {
60
+ deferredDataScripts.push(
61
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
62
+ DeferredDataScript,
63
+ {
64
+ data: deferredData.data[key],
65
+ dataKey: key,
66
+ routeId
67
+ },
68
+ `${routeId} | ${key}`
69
+ )
70
+ );
71
+ return `${JSON.stringify(key)}: _ROUTER_DATA.s(${JSON.stringify(
72
+ routeId
73
+ )},${JSON.stringify(key)}) `;
74
+ } else {
75
+ const trackedPromise = deferredData.data[key];
76
+ if (typeof trackedPromise._error !== "undefined") {
77
+ const error = {
78
+ message: trackedPromise._error.message,
79
+ stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
80
+ };
81
+ return `${JSON.stringify(
82
+ key
83
+ )}: _ROUTER_DATA.p(${void 0}, ${(0, import_serialize.serializeJson)(error)})`;
84
+ } else {
85
+ if (typeof trackedPromise._data === "undefined") {
86
+ throw new Error(
87
+ `The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`
88
+ );
89
+ }
90
+ return `${JSON.stringify(key)}: _ROUTER_DATA.p(${(0, import_serialize.serializeJson)(
91
+ trackedPromise._data
92
+ )})`;
93
+ }
94
+ }
95
+ }).join(",\n");
96
+ return `Object.assign(_ROUTER_DATA.loaderData[${JSON.stringify(
97
+ routeId
98
+ )}], {${deferredKeyPromiseStr}});`;
99
+ }).join("\n");
100
+ return [initialScripts, deferredDataScripts];
101
+ }, []);
102
+ if (!deferredScripts) {
103
+ return null;
104
+ }
105
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
106
+ !hydratedRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ "script",
108
+ {
109
+ async: true,
110
+ suppressHydrationWarning: true,
111
+ dangerouslySetInnerHTML: { __html: deferredScripts[0] }
112
+ }
113
+ ),
114
+ !hydratedRef.current && deferredScripts[1],
115
+ import_common.JSX_SHELL_STREAM_END_MARK
116
+ ] });
117
+ };
118
+ const DeferredDataScript = ({
119
+ data,
120
+ routeId,
121
+ dataKey
122
+ }) => {
123
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: typeof document === "undefined" && data && dataKey && routeId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ import_react_router_dom.Await,
125
+ {
126
+ resolve: data,
127
+ errorElement: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorDeferredDataScript, { routeId, dataKey }),
128
+ children: (data2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
+ "script",
130
+ {
131
+ async: true,
132
+ suppressHydrationWarning: true,
133
+ dangerouslySetInnerHTML: {
134
+ __html: `_ROUTER_DATA.r(${JSON.stringify(
135
+ routeId
136
+ )}, ${JSON.stringify(dataKey)}, ${(0, import_serialize.serializeJson)(data2)});`
137
+ }
138
+ }
139
+ )
140
+ }
141
+ ) : null });
142
+ };
143
+ const ErrorDeferredDataScript = ({
144
+ routeId,
145
+ dataKey
146
+ }) => {
147
+ const error = (0, import_react_router_dom.useAsyncError)();
148
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
149
+ "script",
150
+ {
151
+ suppressHydrationWarning: true,
152
+ dangerouslySetInnerHTML: {
153
+ __html: `_ROUTER_DATA.r(${JSON.stringify(routeId)}, ${JSON.stringify(
154
+ dataKey
155
+ )}, ${void 0}, ${(0, import_serialize.serializeJson)({
156
+ message: error.message,
157
+ stack: error.stack
158
+ })});`
159
+ }
160
+ }
161
+ );
162
+ };
163
+ var DeferredDataScripts_node_default = DeferredDataScripts;
164
+ // Annotate the CommonJS export names for ESM import in node:
165
+ 0 && (module.exports = {});
@@ -21,7 +21,15 @@ __export(serverRender_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(serverRender_exports);
23
23
  var import_utils = require("../utils");
24
+ var import_utils2 = require("./utils");
24
25
  async function serverRender(options) {
26
+ var _a, _b;
27
+ if ((_a = options.context.ssrContext) == null ? void 0 : _a.template) {
28
+ options.context.ssrContext.template = (_b = options.context.ssrContext) == null ? void 0 : _b.template.replace(
29
+ "</head>",
30
+ `${import_utils2.CSS_CHUNKS_PLACEHOLDER}</head>`
31
+ );
32
+ }
25
33
  if ((0, import_utils.isReact18)() && options.config.mode === "stream") {
26
34
  const pipe = await require("./renderToStream").render(options);
27
35
  return pipe;
@@ -33,8 +33,8 @@ module.exports = __toCommonJS(bulidTemplate_before_exports);
33
33
  var import_react_helmet = __toESM(require("react-helmet"));
34
34
  var import_react_router_dom = require("react-router-dom");
35
35
  var import_helmet = __toESM(require("../helmet"));
36
+ var import_utils = require("../utils");
36
37
  var import_buildTemplate = require("./buildTemplate.share");
37
- const CSS_CHUNKS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
38
38
  function getHeadTemplate(beforeEntryTemplate, context) {
39
39
  const callbacks = [
40
40
  (headTemplate2) => {
@@ -50,7 +50,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
50
50
  }
51
51
  return (0, import_buildTemplate.buildTemplate)(headTemplate, callbacks);
52
52
  function injectCss(headTemplate2) {
53
- return headTemplate2.replace(CSS_CHUNKS_PLACEHOLDER, getCssChunks());
53
+ return headTemplate2.replace(import_utils.CSS_CHUNKS_PLACEHOLDER, getCssChunks());
54
54
  function getCssChunks() {
55
55
  const { routeManifest, routerContext, routes } = context;
56
56
  if (!routeManifest || !routerContext || !routes) {
@@ -21,11 +21,18 @@ __export(renderToPipe_worker_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(renderToPipe_worker_exports);
23
23
  var import_types = require("../types");
24
+ var import_common = require("../../../common");
24
25
  var import_template = require("./template");
26
+ var ShellChunkStatus = /* @__PURE__ */ ((ShellChunkStatus2) => {
27
+ ShellChunkStatus2[ShellChunkStatus2["IDLE"] = 0] = "IDLE";
28
+ ShellChunkStatus2[ShellChunkStatus2["START"] = 1] = "START";
29
+ ShellChunkStatus2[ShellChunkStatus2["FINIESH"] = 2] = "FINIESH";
30
+ return ShellChunkStatus2;
31
+ })(ShellChunkStatus || {});
25
32
  function renderToPipe(rootElement, context, options) {
26
- let isShellStream = true;
33
+ let shellChunkStatus = 0 /* IDLE */;
27
34
  const { ssrContext } = context;
28
- const forUserPipe = async (stream) => {
35
+ const forUserPipe = async () => {
29
36
  let renderToReadableStream;
30
37
  try {
31
38
  ({ renderToReadableStream } = require("react-dom/server"));
@@ -57,11 +64,20 @@ function renderToPipe(rootElement, context, options) {
57
64
  controller.close();
58
65
  return;
59
66
  }
60
- if (isShellStream) {
61
- controller.enqueue(encodeForWebStream(shellBefore));
62
- controller.enqueue(value);
63
- controller.enqueue(encodeForWebStream(shellAfter));
64
- isShellStream = false;
67
+ if (shellChunkStatus !== 2 /* FINIESH */) {
68
+ let concatedChunk = new TextDecoder().decode(value);
69
+ if (shellChunkStatus === 0 /* IDLE */) {
70
+ concatedChunk = `${shellBefore}${concatedChunk}`;
71
+ shellChunkStatus = 1 /* START */;
72
+ }
73
+ if (shellChunkStatus === 1 /* START */ && concatedChunk.endsWith(import_common.ESCAPED_SHELL_STREAM_END_MARK)) {
74
+ concatedChunk = concatedChunk.replace(
75
+ import_common.ESCAPED_SHELL_STREAM_END_MARK,
76
+ shellAfter
77
+ );
78
+ shellChunkStatus = 2 /* FINIESH */;
79
+ }
80
+ controller.enqueue(encodeForWebStream(concatedChunk));
65
81
  } else {
66
82
  controller.enqueue(value);
67
83
  }
@@ -70,7 +86,7 @@ function renderToPipe(rootElement, context, options) {
70
86
  push();
71
87
  }
72
88
  });
73
- return readableOriginal(injectableStream).readableOriginal(stream);
89
+ return injectableStream;
74
90
  } catch (err) {
75
91
  ssrContext.metrics.emitCounter("app.render.streaming.shell.error", 1);
76
92
  const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = (0, import_template.getTemplates)(
@@ -81,7 +97,7 @@ function renderToPipe(rootElement, context, options) {
81
97
  return fallbackHtml;
82
98
  }
83
99
  };
84
- return forUserPipe;
100
+ return forUserPipe();
85
101
  }
86
102
  let encoder;
87
103
  function encodeForWebStream(thing) {
@@ -17,9 +17,11 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var utils_exports = {};
19
19
  __export(utils_exports, {
20
+ CSS_CHUNKS_PLACEHOLDER: () => CSS_CHUNKS_PLACEHOLDER,
20
21
  getLoadableScripts: () => getLoadableScripts
21
22
  });
22
23
  module.exports = __toCommonJS(utils_exports);
24
+ const CSS_CHUNKS_PLACEHOLDER = "<!--<?- chunksMap.css ?>-->";
23
25
  function getLoadableScripts(extractor) {
24
26
  const check = (scripts2) => (scripts2 || "").includes("__LOADABLE_REQUIRED_CHUNKS___ext");
25
27
  const scripts = extractor.getScriptTags();
@@ -30,5 +32,6 @@ function getLoadableScripts(extractor) {
30
32
  }
31
33
  // Annotate the CommonJS export names for ESM import in node:
32
34
  0 && (module.exports = {
35
+ CSS_CHUNKS_PLACEHOLDER,
33
36
  getLoadableScripts
34
37
  });
@@ -1,166 +1,4 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function _iterableToArrayLimit(arr, i) {
10
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
- if (_i == null) return;
12
- var _arr = [];
13
- var _n = true;
14
- var _d = false;
15
- var _s, _e;
16
- try {
17
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
- _arr.push(_s.value);
19
- if (i && _arr.length === i) break;
20
- }
21
- } catch (err) {
22
- _d = true;
23
- _e = err;
24
- } finally{
25
- try {
26
- if (!_n && _i["return"] != null) _i["return"]();
27
- } finally{
28
- if (_d) throw _e;
29
- }
30
- }
31
- return _arr;
32
- }
33
- function _nonIterableRest() {
34
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
- }
36
- function _slicedToArray(arr, i) {
37
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
38
- }
39
- function _unsupportedIterableToArray(o, minLen) {
40
- if (!o) return;
41
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
42
- var n = Object.prototype.toString.call(o).slice(8, -1);
43
- if (n === "Object" && o.constructor) n = o.constructor.name;
44
- if (n === "Map" || n === "Set") return Array.from(n);
45
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
46
- }
47
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
48
- import { Suspense, useEffect, useRef, useMemo, useContext } from "react";
49
- import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "react-router-dom";
50
- import { serializeJson } from "@modern-js/utils/serialize";
51
- import { JSX_SHELL_STREAM_END_MARK } from "../../common";
52
- import { serializeErrors } from "./utils";
53
- var setupFnStr = "function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};";
54
- var resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
55
- var preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resovle(e)};";
56
- var DeferredDataScripts = function() {
57
- var context = useContext(DataRouterContext);
58
- var staticContext = (context || {}).staticContext;
59
- var hydratedRef = useRef(false);
60
- useEffect(function() {
61
- hydratedRef.current = true;
62
- }, []);
63
- var deferredScripts = useMemo(function() {
64
- if (!staticContext) {
65
- return null;
66
- }
67
- var activeDeferreds = staticContext.activeDeferreds || [];
68
- var _ROUTER_DATA = {
69
- loaderData: staticContext.loaderData,
70
- errors: serializeErrors(staticContext.errors)
71
- };
72
- var initialScripts = [
73
- "_ROUTER_DATA = ".concat(serializeJson(_ROUTER_DATA), ";"),
74
- "_ROUTER_DATA.s = ".concat(setupFnStr),
75
- "_ROUTER_DATA.r = ".concat(resolveFnStr),
76
- "_ROUTER_DATA.p = ".concat(preResolvedFnStr)
77
- ].join("\n");
78
- var deferredDataScripts = [];
79
- initialScripts += Object.entries(activeDeferreds).map(function(param) {
80
- var _param = _slicedToArray(param, 2), routeId = _param[0], deferredData = _param[1];
81
- var pendingKeys = new Set(deferredData.pendingKeys);
82
- var deferredKeys = deferredData.deferredKeys;
83
- var deferredKeyPromiseStr = deferredKeys.map(function(key) {
84
- if (pendingKeys.has(key)) {
85
- deferredDataScripts.push(/* @__PURE__ */ jsx(DeferredDataScript, {
86
- data: deferredData.data[key],
87
- dataKey: key,
88
- routeId: routeId
89
- }, "".concat(routeId, " | ").concat(key)));
90
- return "".concat(JSON.stringify(key), ": _ROUTER_DATA.s(").concat(JSON.stringify(routeId), ",").concat(JSON.stringify(key), ") ");
91
- } else {
92
- var trackedPromise = deferredData.data[key];
93
- if (typeof trackedPromise._error !== "undefined") {
94
- var error = {
95
- message: trackedPromise._error.message,
96
- stack: process.env.NODE_ENV !== "production" ? trackedPromise._error.stack : void 0
97
- };
98
- return "".concat(JSON.stringify(key), ": _ROUTER_DATA.p(").concat(void 0, ", ").concat(serializeJson(error), ")");
99
- } else {
100
- if (typeof trackedPromise._data === "undefined") {
101
- throw new Error("The deferred data for ".concat(key, " was not resolved, did you forget to return data from a deferred promise"));
102
- }
103
- return "".concat(JSON.stringify(key), ": _ROUTER_DATA.p(").concat(serializeJson(trackedPromise._data), ")");
104
- }
105
- }
106
- }).join(",\n");
107
- return "Object.assign(_ROUTER_DATA.loaderData[".concat(JSON.stringify(routeId), "], {").concat(deferredKeyPromiseStr, "});");
108
- }).join("\n");
109
- return [
110
- initialScripts,
111
- deferredDataScripts
112
- ];
113
- }, []);
114
- if (!deferredScripts) {
115
- return null;
116
- }
117
- return /* @__PURE__ */ jsxs(Fragment, {
118
- children: [
119
- !hydratedRef.current && /* @__PURE__ */ jsx("script", {
120
- async: true,
121
- suppressHydrationWarning: true,
122
- dangerouslySetInnerHTML: {
123
- __html: deferredScripts[0]
124
- }
125
- }),
126
- !hydratedRef.current && deferredScripts[1],
127
- JSX_SHELL_STREAM_END_MARK
128
- ]
129
- });
1
+ var DeferredDataScripts_default = function() {
2
+ return null;
130
3
  };
131
- var DeferredDataScript = function(param) {
132
- var data = param.data, routeId = param.routeId, dataKey = param.dataKey;
133
- return /* @__PURE__ */ jsx(Suspense, {
134
- children: typeof document === "undefined" && data && dataKey && routeId ? /* @__PURE__ */ jsx(Await, {
135
- resolve: data,
136
- errorElement: /* @__PURE__ */ jsx(ErrorDeferredDataScript, {
137
- routeId: routeId,
138
- dataKey: dataKey
139
- }),
140
- children: function(data2) {
141
- return /* @__PURE__ */ jsx("script", {
142
- async: true,
143
- suppressHydrationWarning: true,
144
- dangerouslySetInnerHTML: {
145
- __html: "_ROUTER_DATA.r(".concat(JSON.stringify(routeId), ", ").concat(JSON.stringify(dataKey), ", ").concat(serializeJson(data2), ");")
146
- }
147
- });
148
- }
149
- }) : null
150
- });
151
- };
152
- var ErrorDeferredDataScript = function(param) {
153
- var routeId = param.routeId, dataKey = param.dataKey;
154
- var error = useAsyncError();
155
- return /* @__PURE__ */ jsx("script", {
156
- suppressHydrationWarning: true,
157
- dangerouslySetInnerHTML: {
158
- __html: "_ROUTER_DATA.r(".concat(JSON.stringify(routeId), ", ").concat(JSON.stringify(dataKey), ", ").concat(void 0, ", ").concat(serializeJson({
159
- message: error.message,
160
- stack: error.stack
161
- }), ");")
162
- }
163
- });
164
- };
165
- var DeferredDataScripts_default = DeferredDataScripts;
166
4
  export { DeferredDataScripts_default as default };