@module-federation/modern-js 0.16.0 → 0.17.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 (65) hide show
  1. package/dist/cjs/cli/configPlugin.js +4 -3
  2. package/dist/cjs/cli/configPlugin.spec.js +1 -3
  3. package/dist/cjs/cli/server/data-fetch-server-plugin.js +2 -143
  4. package/dist/cjs/constant.js +2 -49
  5. package/dist/cjs/{runtime/wrapNoSSR.js → react/index.js} +22 -13
  6. package/dist/cjs/runtime/index.js +0 -28
  7. package/dist/cjs/ssr-runtime/devPlugin.js +2 -2
  8. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +6 -102
  9. package/dist/esm/cli/configPlugin.js +4 -3
  10. package/dist/esm/cli/configPlugin.spec.js +1 -3
  11. package/dist/esm/cli/server/data-fetch-server-plugin.js +2 -219
  12. package/dist/esm/constant.js +1 -37
  13. package/dist/esm/react/index.js +12 -0
  14. package/dist/esm/runtime/index.js +0 -21
  15. package/dist/esm/ssr-runtime/devPlugin.js +1 -1
  16. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +4 -147
  17. package/dist/esm-node/cli/configPlugin.js +4 -3
  18. package/dist/esm-node/cli/configPlugin.spec.js +1 -3
  19. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +2 -143
  20. package/dist/esm-node/constant.js +1 -37
  21. package/dist/esm-node/react/index.js +12 -0
  22. package/dist/esm-node/runtime/index.js +0 -21
  23. package/dist/esm-node/ssr-runtime/devPlugin.js +1 -1
  24. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +4 -89
  25. package/dist/types/cli/index.d.ts +1 -1
  26. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
  27. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +2 -2
  28. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +2 -2
  29. package/dist/types/constant.d.ts +0 -23
  30. package/dist/types/react/index.d.ts +2 -0
  31. package/dist/types/runtime/index.d.ts +0 -9
  32. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -3
  33. package/dist/types/types/index.d.ts +1 -3
  34. package/package.json +26 -24
  35. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -100
  36. package/dist/cjs/interfaces/global.js +0 -16
  37. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  38. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  39. package/dist/cjs/ssr-runtime/downgrade.js +0 -114
  40. package/dist/cjs/utils/dataFetch.js +0 -211
  41. package/dist/cjs/utils/index.js +0 -54
  42. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -76
  43. package/dist/esm/interfaces/global.js +0 -0
  44. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  45. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  46. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  47. package/dist/esm/ssr-runtime/downgrade.js +0 -150
  48. package/dist/esm/utils/dataFetch.js +0 -237
  49. package/dist/esm/utils/index.js +0 -28
  50. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -70
  51. package/dist/esm-node/interfaces/global.js +0 -0
  52. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  53. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  54. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  55. package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
  56. package/dist/esm-node/utils/dataFetch.js +0 -166
  57. package/dist/esm-node/utils/index.js +0 -27
  58. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  59. package/dist/types/interfaces/global.d.ts +0 -27
  60. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  61. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  62. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  63. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  64. package/dist/types/utils/dataFetch.d.ts +0 -26
  65. package/dist/types/utils/index.d.ts +0 -15
@@ -1,211 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var dataFetch_exports = {};
30
- __export(dataFetch_exports, {
31
- fetchData: () => fetchData,
32
- flushDataFetch: () => flushDataFetch,
33
- getDataFetchIdWithErrorMsgs: () => getDataFetchIdWithErrorMsgs,
34
- getDataFetchInfo: () => getDataFetchInfo,
35
- getDataFetchItem: () => getDataFetchItem,
36
- getDataFetchMap: () => getDataFetchMap,
37
- getDataFetchMapKey: () => getDataFetchMapKey,
38
- initDataFetchMap: () => initDataFetchMap,
39
- isDataLoaderExpose: () => isDataLoaderExpose,
40
- loadDataFetchModule: () => loadDataFetchModule,
41
- setDataFetchItemLoadedStatus: () => setDataFetchItemLoadedStatus,
42
- wrapDataFetchId: () => wrapDataFetchId
43
- });
44
- module.exports = __toCommonJS(dataFetch_exports);
45
- var import_sdk = require("@module-federation/sdk");
46
- var import_utils = require("../utils");
47
- var import_logger = __toESM(require("../logger"));
48
- var import_downgrade = require("../ssr-runtime/downgrade");
49
- var import_constant = require("../constant");
50
- var import_constant2 = require("@module-federation/rsbuild-plugin/constant");
51
- const getDataFetchInfo = ({ name, alias, id, remoteSnapshot }) => {
52
- if (!remoteSnapshot) {
53
- return;
54
- }
55
- if (!("modules" in remoteSnapshot)) {
56
- return;
57
- }
58
- const regex = new RegExp(`^${name}(/[^/].*|)$`);
59
- const nameOrAlias = regex.test(id) ? name : alias || name;
60
- const expose = id.replace(nameOrAlias, "");
61
- let dataFetchName = "";
62
- let dataFetchId = "";
63
- if (expose.startsWith("/")) {
64
- dataFetchName = `${expose.slice(1)}.${import_constant2.DATA_FETCH_IDENTIFIER}`;
65
- dataFetchId = `${id}.${import_constant2.DATA_FETCH_IDENTIFIER}`;
66
- } else if (expose === "") {
67
- dataFetchName = import_constant2.DATA_FETCH_IDENTIFIER;
68
- dataFetchId = `${id}/${import_constant2.DATA_FETCH_IDENTIFIER}`;
69
- } else {
70
- return;
71
- }
72
- if (!dataFetchName || !dataFetchId) {
73
- return;
74
- }
75
- if (!remoteSnapshot.modules.find((module2) => module2.moduleName === dataFetchName)) {
76
- return;
77
- }
78
- return {
79
- dataFetchName,
80
- dataFetchId
81
- };
82
- };
83
- function initDataFetchMap() {
84
- var _globalThis;
85
- (_globalThis = globalThis).__MF_DATA_FETCH_MAP__ || (_globalThis.__MF_DATA_FETCH_MAP__ = {});
86
- }
87
- function getDataFetchItem(id) {
88
- var _globalThis___MF_DATA_FETCH_MAP__;
89
- return (_globalThis___MF_DATA_FETCH_MAP__ = globalThis.__MF_DATA_FETCH_MAP__) === null || _globalThis___MF_DATA_FETCH_MAP__ === void 0 ? void 0 : _globalThis___MF_DATA_FETCH_MAP__[id];
90
- }
91
- function getDataFetchMap() {
92
- return globalThis.__MF_DATA_FETCH_MAP__;
93
- }
94
- const flushDataFetch = () => {
95
- globalThis.__MF_DATA_FETCH_MAP__ = {};
96
- globalThis[import_constant.DOWNGRADE_KEY] = void 0;
97
- };
98
- function setDataFetchItemLoadedStatus(id) {
99
- const dataFetchItem = getDataFetchItem(id);
100
- if (!dataFetchItem) {
101
- return;
102
- }
103
- dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.LOADED;
104
- }
105
- const wrapDataFetchId = (id) => {
106
- return `${import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER}${id}${import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER}`;
107
- };
108
- const getDataFetchIdWithErrorMsgs = (errMsgs) => {
109
- const firstIdentifierIndex = errMsgs.indexOf(import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER);
110
- if (firstIdentifierIndex === -1) {
111
- return void 0;
112
- }
113
- const secondIdentifierIndex = errMsgs.indexOf(import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER, firstIdentifierIndex + import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER.length);
114
- if (secondIdentifierIndex === -1) {
115
- return void 0;
116
- }
117
- return errMsgs.substring(firstIdentifierIndex + import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER.length, secondIdentifierIndex);
118
- };
119
- async function fetchData(id, params, remoteInfo) {
120
- const callFetchData = async () => {
121
- const item = getDataFetchItem(id);
122
- if (!item) {
123
- return;
124
- }
125
- const [fetchDataFnArr, ..._rest] = item;
126
- const fetchDataFn = await fetchDataFnArr[2];
127
- if (!fetchDataFn) {
128
- return;
129
- }
130
- return fetchDataFn(params);
131
- };
132
- if ((0, import_sdk.isBrowserEnv)()) {
133
- var _dataFetchItem_;
134
- const dataFetchItem = getDataFetchItem(id);
135
- if (!dataFetchItem) {
136
- throw new Error(`dataFetchItem not found, id: ${id}`);
137
- }
138
- if ((_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : _dataFetchItem_[0]) {
139
- return dataFetchItem[1][0];
140
- }
141
- if ((0, import_utils.isCSROnly)()) {
142
- import_logger.default.debug("==========csr only!");
143
- return callFetchData();
144
- }
145
- if (remoteInfo) {
146
- return (0, import_downgrade.callDowngrade)(id, params, remoteInfo);
147
- }
148
- const mfDowngrade = (0, import_downgrade.getDowngradeTag)();
149
- if (mfDowngrade) {
150
- if (typeof mfDowngrade === "boolean") {
151
- return (0, import_downgrade.callDowngrade)(id, {
152
- ...params,
153
- isDowngrade: true
154
- });
155
- }
156
- if (mfDowngrade.includes(id)) {
157
- return (0, import_downgrade.callDowngrade)(id, {
158
- ...params,
159
- isDowngrade: true
160
- });
161
- }
162
- }
163
- let res;
164
- let rej;
165
- const p = new Promise((resolve, reject) => {
166
- res = resolve;
167
- rej = reject;
168
- });
169
- dataFetchItem[1] = [
170
- p,
171
- res,
172
- rej
173
- ];
174
- dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.AWAIT;
175
- return dataFetchItem[1][0];
176
- }
177
- return callFetchData();
178
- }
179
- function getDataFetchMapKey(dataFetchInfo, hostInfo) {
180
- if (!dataFetchInfo || !hostInfo) {
181
- return;
182
- }
183
- const { dataFetchId } = dataFetchInfo;
184
- return (0, import_sdk.composeKeyWithSeparator)(dataFetchId, hostInfo.name, hostInfo.version);
185
- }
186
- async function loadDataFetchModule(instance, id) {
187
- return instance.loadRemote(id).then((m) => {
188
- if (m && typeof m === "object" && "fetchData" in m && typeof m.fetchData === "function") {
189
- return m.fetchData;
190
- }
191
- throw new Error(`fetchData not found in remote ${id}, ${JSON.stringify(m)}`);
192
- });
193
- }
194
- function isDataLoaderExpose(exposeKey) {
195
- return exposeKey.endsWith(import_constant2.DATA_FETCH_IDENTIFIER) || exposeKey.endsWith(import_constant2.DATA_FETCH_CLIENT_SUFFIX);
196
- }
197
- // Annotate the CommonJS export names for ESM import in node:
198
- 0 && (module.exports = {
199
- fetchData,
200
- flushDataFetch,
201
- getDataFetchIdWithErrorMsgs,
202
- getDataFetchInfo,
203
- getDataFetchItem,
204
- getDataFetchMap,
205
- getDataFetchMapKey,
206
- initDataFetchMap,
207
- isDataLoaderExpose,
208
- loadDataFetchModule,
209
- setDataFetchItemLoadedStatus,
210
- wrapDataFetchId
211
- });
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var utils_exports = {};
21
- __export(utils_exports, {
22
- getLoadedRemoteInfos: () => getLoadedRemoteInfos,
23
- isCSROnly: () => isCSROnly
24
- });
25
- module.exports = __toCommonJS(utils_exports);
26
- __reExport(utils_exports, require("./dataFetch"), module.exports);
27
- function getLoadedRemoteInfos(id, instance) {
28
- if (!instance) {
29
- return;
30
- }
31
- const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
32
- if (!name) {
33
- return;
34
- }
35
- const module2 = instance.moduleCache.get(name);
36
- if (!module2) {
37
- return;
38
- }
39
- const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module2.remoteInfo);
40
- return {
41
- ...module2.remoteInfo,
42
- snapshot: remoteSnapshot,
43
- expose
44
- };
45
- }
46
- function isCSROnly() {
47
- return window._SSR_DATA === void 0;
48
- }
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- getLoadedRemoteInfos,
52
- isCSROnly,
53
- ...require("./dataFetch")
54
- });
@@ -1,76 +0,0 @@
1
- import { getDataFetchInfo, initDataFetchMap, getDataFetchItem, getDataFetchMap, isCSROnly } from "../../utils";
2
- import logger from "../../logger";
3
- import { getDataFetchMapKey, isDataLoaderExpose, loadDataFetchModule } from "../../utils/dataFetch";
4
- import { MF_DATA_FETCH_TYPE, MF_DATA_FETCH_STATUS } from "../../constant";
5
- import { DATA_FETCH_CLIENT_SUFFIX } from "@module-federation/rsbuild-plugin/constant";
6
- var autoFetchData = function() {
7
- return {
8
- name: "auto-fetch-data-plugin",
9
- beforeInit: function beforeInit(args) {
10
- initDataFetchMap();
11
- return args;
12
- },
13
- afterLoadSnapshot: function afterLoadSnapshot(args) {
14
- var id = args.id, moduleInfo = args.moduleInfo, remoteSnapshot = args.remoteSnapshot, host = args.host;
15
- if (typeof id === "string" && isDataLoaderExpose(id)) {
16
- return args;
17
- }
18
- if (!remoteSnapshot || !id || !("modules" in remoteSnapshot)) {
19
- return args;
20
- }
21
- var name = moduleInfo.name, alias = moduleInfo.alias;
22
- var dataFetchInfo = getDataFetchInfo({
23
- name,
24
- alias,
25
- id,
26
- remoteSnapshot
27
- });
28
- if (!dataFetchInfo) {
29
- return args;
30
- }
31
- var dataFetchId = dataFetchInfo.dataFetchId, dataFetchName = dataFetchInfo.dataFetchName;
32
- var dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
33
- name: host.name,
34
- version: host.options.version
35
- });
36
- logger.debug("======= auto fetch plugin dataFetchMapKey: ", dataFetchMapKey);
37
- if (!dataFetchMapKey) {
38
- return args;
39
- }
40
- var dataFetchItem = getDataFetchItem(dataFetchMapKey);
41
- if (dataFetchItem) {
42
- return args;
43
- }
44
- var dataFetchMap = getDataFetchMap();
45
- var hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
46
- var hasDataFetchClient = Boolean(remoteSnapshot.modules.find(function(module) {
47
- return module.moduleName === "".concat(dataFetchName).concat(DATA_FETCH_CLIENT_SUFFIX);
48
- }));
49
- var downgradeType = hasDataFetchClient ? MF_DATA_FETCH_TYPE.FETCH_CLIENT : hasSSRAsset ? MF_DATA_FETCH_TYPE.FETCH_SERVER : MF_DATA_FETCH_TYPE.FETCH_CLIENT;
50
- var finalDataFetchId = dataFetchId;
51
- if (typeof window !== "undefined") {
52
- finalDataFetchId = downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT ? hasDataFetchClient ? "".concat(dataFetchId).concat(DATA_FETCH_CLIENT_SUFFIX) : dataFetchId : dataFetchId;
53
- }
54
- var getDataFetchGetter = function() {
55
- return loadDataFetchModule(host, finalDataFetchId);
56
- };
57
- var dataFetchFnItem = [
58
- getDataFetchGetter,
59
- downgradeType
60
- ];
61
- if (typeof window === "undefined" || isCSROnly()) {
62
- dataFetchFnItem.push(getDataFetchGetter());
63
- }
64
- dataFetchMap[dataFetchMapKey] = [
65
- dataFetchFnItem,
66
- void 0,
67
- MF_DATA_FETCH_STATUS.AWAIT
68
- ];
69
- return args;
70
- }
71
- };
72
- };
73
- var auto_fetch_data_default = autoFetchData;
74
- export {
75
- auto_fetch_data_default as default
76
- };
File without changes
@@ -1,131 +0,0 @@
1
- import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
2
- import { _ as _tagged_template_literal } from "@swc/helpers/_/_tagged_template_literal";
3
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
4
- function _templateObject() {
5
- var data = _tagged_template_literal([
6
- "\n globalThis['",
7
- "'] = globalThis['",
8
- "'] || []\n globalThis['",
9
- "'].push([",
10
- ",",
11
- ",true]);"
12
- ]);
13
- _templateObject = function _templateObject2() {
14
- return data;
15
- };
16
- return data;
17
- }
18
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
- import { Suspense, useRef } from "react";
20
- import logger from "../logger";
21
- import { DATA_FETCH_ERROR_PREFIX, LOAD_REMOTE_ERROR_PREFIX, ERROR_TYPE, DATA_FETCH_FUNCTION } from "../constant";
22
- import { getDataFetchIdWithErrorMsgs, wrapDataFetchId } from "../utils";
23
- function isPromise(obj) {
24
- return !!obj && ((typeof obj === "undefined" ? "undefined" : _type_of(obj)) === "object" || typeof obj === "function") && typeof obj.then === "function";
25
- }
26
- var AWAIT_ERROR_PREFIX = "<Await /> caught the following error during render: ";
27
- var transformError = function(err) {
28
- var errMsg = _instanceof(err, Error) ? err.message : err;
29
- var originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, "");
30
- var dataFetchMapKey = getDataFetchIdWithErrorMsgs(originalMsg);
31
- if (originalMsg.indexOf(DATA_FETCH_ERROR_PREFIX) === 0) {
32
- return {
33
- error: new Error(originalMsg.replace(DATA_FETCH_ERROR_PREFIX, "").replace(wrapDataFetchId(dataFetchMapKey), "")),
34
- errorType: ERROR_TYPE.DATA_FETCH,
35
- dataFetchMapKey
36
- };
37
- }
38
- if (originalMsg.indexOf(LOAD_REMOTE_ERROR_PREFIX) === 0) {
39
- return {
40
- error: new Error(originalMsg.replace(LOAD_REMOTE_ERROR_PREFIX, "").replace(wrapDataFetchId(dataFetchMapKey), "")),
41
- errorType: ERROR_TYPE.LOAD_REMOTE,
42
- dataFetchMapKey
43
- };
44
- }
45
- return {
46
- error: new Error(originalMsg.replace(wrapDataFetchId(dataFetchMapKey), "")),
47
- errorType: ERROR_TYPE.UNKNOWN,
48
- dataFetchMapKey
49
- };
50
- };
51
- var DefaultLoading = /* @__PURE__ */ _jsx(_Fragment, {});
52
- var DefaultErrorElement = function(_data) {
53
- return /* @__PURE__ */ _jsx("div", {
54
- children: "Error"
55
- });
56
- };
57
- function AwaitDataFetch(param) {
58
- var resolve = param.resolve, _param_loading = param.loading, loading = _param_loading === void 0 ? DefaultLoading : _param_loading, _param_errorElement = param.errorElement, errorElement = _param_errorElement === void 0 ? DefaultErrorElement : _param_errorElement, children = param.children, params = param.params;
59
- var dataRef = useRef();
60
- var data = dataRef.current || resolve;
61
- var getData = isPromise(data) ? fetchData(data, dataRef) : function() {
62
- return data;
63
- };
64
- return /* @__PURE__ */ _jsx(AwaitSuspense, {
65
- params,
66
- loading,
67
- errorElement,
68
- // @ts-ignore
69
- resolve: getData,
70
- children
71
- });
72
- }
73
- function AwaitSuspense(param) {
74
- var resolve = param.resolve, children = param.children, _param_loading = param.loading, loading = _param_loading === void 0 ? DefaultLoading : _param_loading, _param_errorElement = param.errorElement, errorElement = _param_errorElement === void 0 ? DefaultErrorElement : _param_errorElement;
75
- return /* @__PURE__ */ _jsx(Suspense, {
76
- fallback: loading,
77
- children: /* @__PURE__ */ _jsx(ResolveAwait, {
78
- resolve,
79
- errorElement,
80
- children
81
- })
82
- });
83
- }
84
- function ResolveAwait(param) {
85
- var children = param.children, resolve = param.resolve, errorElement = param.errorElement, params = param.params;
86
- var data = resolve();
87
- logger.debug("resolve data: ", data);
88
- if (typeof data === "string" && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
89
- var transformedError = transformError(data);
90
- return /* @__PURE__ */ _jsx(_Fragment, {
91
- children: typeof errorElement === "function" ? /* @__PURE__ */ _jsxs(_Fragment, {
92
- children: [
93
- globalThis.FEDERATION_SSR && /* @__PURE__ */ _jsx("script", {
94
- suppressHydrationWarning: true,
95
- dangerouslySetInnerHTML: {
96
- __html: String.raw(_templateObject(), DATA_FETCH_FUNCTION, DATA_FETCH_FUNCTION, DATA_FETCH_FUNCTION, transformedError.dataFetchMapKey ? "'".concat(transformedError.dataFetchMapKey, "'") : "", params ? JSON.stringify(params) : null)
97
- }
98
- }),
99
- errorElement(transformedError)
100
- ]
101
- }) : errorElement
102
- });
103
- }
104
- var toRender = typeof children === "function" ? children(data) : children;
105
- return /* @__PURE__ */ _jsx(_Fragment, {
106
- children: toRender
107
- });
108
- }
109
- var fetchData = function(promise, ref) {
110
- var data;
111
- var status = "pending";
112
- var suspender = promise.then(function(res) {
113
- status = "success";
114
- data = res;
115
- ref.current = res;
116
- }).catch(function(e) {
117
- status = "success";
118
- console.warn(e);
119
- data = AWAIT_ERROR_PREFIX + e;
120
- });
121
- return function() {
122
- if (status === "pending") {
123
- throw suspender;
124
- }
125
- return data;
126
- };
127
- };
128
- export {
129
- AwaitDataFetch,
130
- transformError
131
- };