@module-federation/modern-js 0.0.0-next-20250613153606 → 0.0.0-next-20250616091910

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 (57) hide show
  1. package/dist/cjs/cli/configPlugin.js +1 -1
  2. package/dist/cjs/cli/configPlugin.spec.js +2 -2
  3. package/dist/cjs/cli/server/data-fetch-server-plugin.js +9 -10
  4. package/dist/cjs/constant.js +2 -49
  5. package/dist/cjs/runtime/index.js +3 -20
  6. package/dist/cjs/ssr-runtime/devPlugin.js +2 -2
  7. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +6 -101
  8. package/dist/esm/cli/configPlugin.js +1 -1
  9. package/dist/esm/cli/configPlugin.spec.js +2 -2
  10. package/dist/esm/cli/server/data-fetch-server-plugin.js +3 -4
  11. package/dist/esm/constant.js +1 -37
  12. package/dist/esm/runtime/index.js +2 -18
  13. package/dist/esm/ssr-runtime/devPlugin.js +1 -1
  14. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +5 -147
  15. package/dist/esm-node/cli/configPlugin.js +1 -1
  16. package/dist/esm-node/cli/configPlugin.spec.js +2 -2
  17. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +3 -4
  18. package/dist/esm-node/constant.js +1 -37
  19. package/dist/esm-node/runtime/index.js +2 -18
  20. package/dist/esm-node/ssr-runtime/devPlugin.js +1 -1
  21. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +5 -89
  22. package/dist/types/constant.d.ts +0 -23
  23. package/dist/types/runtime/index.d.ts +2 -9
  24. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -3
  25. package/package.json +9 -16
  26. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -100
  27. package/dist/cjs/interfaces/global.js +0 -16
  28. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  29. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  30. package/dist/cjs/runtime/wrapNoSSR.js +0 -35
  31. package/dist/cjs/ssr-runtime/downgrade.js +0 -114
  32. package/dist/cjs/utils/dataFetch.js +0 -211
  33. package/dist/cjs/utils/index.js +0 -54
  34. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -76
  35. package/dist/esm/interfaces/global.js +0 -0
  36. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  37. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  38. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  39. package/dist/esm/ssr-runtime/downgrade.js +0 -150
  40. package/dist/esm/utils/dataFetch.js +0 -237
  41. package/dist/esm/utils/index.js +0 -28
  42. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -70
  43. package/dist/esm-node/interfaces/global.js +0 -0
  44. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  45. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  46. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  47. package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
  48. package/dist/esm-node/utils/dataFetch.js +0 -166
  49. package/dist/esm-node/utils/index.js +0 -27
  50. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  51. package/dist/types/interfaces/global.d.ts +0 -27
  52. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  53. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  54. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  55. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  56. package/dist/types/utils/dataFetch.d.ts +0 -26
  57. package/dist/types/utils/index.d.ts +0 -15
@@ -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
- };
@@ -1,417 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
5
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
6
- import { _ as _tagged_template_literal } from "@swc/helpers/_/_tagged_template_literal";
7
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
8
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
9
- function _templateObject() {
10
- var data = _tagged_template_literal([
11
- "\n globalThis['",
12
- "'] = globalThis['",
13
- "'] || [];\n globalThis['",
14
- "'].push(['",
15
- "',",
16
- "]);\n "
17
- ]);
18
- _templateObject = function _templateObject2() {
19
- return data;
20
- };
21
- return data;
22
- }
23
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
24
- import React, { useEffect, useState } from "react";
25
- import logger from "../logger";
26
- import { getInstance } from "@module-federation/enhanced/runtime";
27
- import { AwaitDataFetch, transformError } from "./AwaitDataFetch";
28
- import { fetchData, getDataFetchItem, getDataFetchMapKey } from "../utils/dataFetch";
29
- import { getDataFetchInfo, getLoadedRemoteInfos, setDataFetchItemLoadedStatus, wrapDataFetchId } from "../utils";
30
- import { DATA_FETCH_ERROR_PREFIX, DATA_FETCH_FUNCTION, FS_HREF, LOAD_REMOTE_ERROR_PREFIX, MF_DATA_FETCH_TYPE } from "../constant";
31
- function getTargetModuleInfo(id) {
32
- var instance = getInstance();
33
- if (!instance) {
34
- return;
35
- }
36
- var loadedRemoteInfo = getLoadedRemoteInfos(id, instance);
37
- if (!loadedRemoteInfo) {
38
- return;
39
- }
40
- var snapshot = loadedRemoteInfo.snapshot;
41
- if (!snapshot) {
42
- return;
43
- }
44
- var publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
45
- if (!publicPath) {
46
- return;
47
- }
48
- var modules = "modules" in snapshot ? snapshot.modules : [];
49
- var targetModule = modules.find(function(m) {
50
- return m.modulePath === loadedRemoteInfo.expose;
51
- });
52
- if (!targetModule) {
53
- return;
54
- }
55
- var remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
56
- if (!remoteEntry) {
57
- return;
58
- }
59
- return {
60
- module: targetModule,
61
- publicPath,
62
- remoteEntry
63
- };
64
- }
65
- function collectSSRAssets(options) {
66
- var _ref = typeof options === "string" ? {
67
- id: options
68
- } : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? false : _ref_injectScript;
69
- var links = [];
70
- var scripts = [];
71
- var instance = getInstance();
72
- if (!instance || !injectLink && !injectScript) {
73
- return _to_consumable_array(scripts).concat(_to_consumable_array(links));
74
- }
75
- var moduleAndPublicPath = getTargetModuleInfo(id);
76
- if (!moduleAndPublicPath) {
77
- return _to_consumable_array(scripts).concat(_to_consumable_array(links));
78
- }
79
- var targetModule = moduleAndPublicPath.module, publicPath = moduleAndPublicPath.publicPath, remoteEntry = moduleAndPublicPath.remoteEntry;
80
- if (injectLink) {
81
- _to_consumable_array(targetModule.assets.css.sync).concat(_to_consumable_array(targetModule.assets.css.async)).sort().forEach(function(file, index) {
82
- links.push(/* @__PURE__ */ _jsx("link", {
83
- href: "".concat(publicPath).concat(file),
84
- rel: "stylesheet",
85
- type: "text/css"
86
- }, "".concat(file.split(".")[0], "_").concat(index)));
87
- });
88
- }
89
- if (injectScript) {
90
- scripts.push(/* @__PURE__ */ _jsx("script", {
91
- async: true,
92
- src: "".concat(publicPath).concat(remoteEntry),
93
- crossOrigin: "anonymous"
94
- }, remoteEntry.split(".")[0]));
95
- _to_consumable_array(targetModule.assets.js.sync).sort().forEach(function(file, index) {
96
- scripts.push(/* @__PURE__ */ _jsx("script", {
97
- async: true,
98
- src: "".concat(publicPath).concat(file),
99
- crossOrigin: "anonymous"
100
- }, "".concat(file.split(".")[0], "_").concat(index)));
101
- });
102
- }
103
- return _to_consumable_array(scripts).concat(_to_consumable_array(links));
104
- }
105
- function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
106
- if (noSSR || typeof window !== "undefined" && window.location.href !== window[FS_HREF]) {
107
- var _dataFetchItem_;
108
- if (!(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.version)) {
109
- throw new Error("".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " version is empty"));
110
- }
111
- var snapshot = loadedRemoteInfo.snapshot;
112
- if (!snapshot) {
113
- throw new Error("".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " snapshot is empty"));
114
- }
115
- var dataFetchItem = getDataFetchItem(id);
116
- var isFetchServer = (dataFetchItem === null || dataFetchItem === void 0 ? void 0 : (_dataFetchItem_ = dataFetchItem[0]) === null || _dataFetchItem_ === void 0 ? void 0 : _dataFetchItem_[1]) === MF_DATA_FETCH_TYPE.FETCH_SERVER;
117
- if (isFetchServer && (!("ssrPublicPath" in snapshot) || !snapshot.ssrPublicPath)) {
118
- throw new Error("ssrPublicPath is required while fetching ".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " data in SSR project!"));
119
- }
120
- if (isFetchServer && (!("ssrRemoteEntry" in snapshot) || !snapshot.ssrRemoteEntry)) {
121
- throw new Error("ssrRemoteEntry is required while loading ".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " data loader in SSR project!"));
122
- }
123
- return {
124
- name: loadedRemoteInfo.name,
125
- version: loadedRemoteInfo.version,
126
- ssrPublicPath: "ssrPublicPath" in snapshot ? snapshot.ssrPublicPath || "" : "",
127
- ssrRemoteEntry: "ssrRemoteEntry" in snapshot ? snapshot.ssrRemoteEntry || "" : "",
128
- globalName: loadedRemoteInfo.entryGlobalName
129
- };
130
- }
131
- return;
132
- }
133
- function createRemoteComponent(options) {
134
- var exportName = (options === null || options === void 0 ? void 0 : options.export) || "default";
135
- var callLoader = function() {
136
- var _ref = _async_to_generator(function() {
137
- var m;
138
- return _ts_generator(this, function(_state) {
139
- switch (_state.label) {
140
- case 0:
141
- logger.debug("callLoader start", Date.now());
142
- return [
143
- 4,
144
- options.loader()
145
- ];
146
- case 1:
147
- m = _state.sent();
148
- logger.debug("callLoader end", Date.now());
149
- if (!m) {
150
- throw new Error("load remote failed");
151
- }
152
- return [
153
- 2,
154
- m
155
- ];
156
- }
157
- });
158
- });
159
- return function callLoader2() {
160
- return _ref.apply(this, arguments);
161
- };
162
- }();
163
- var getData = function() {
164
- var _ref = _async_to_generator(function(noSSR) {
165
- var loadedRemoteInfo, moduleId, instance, m, e, errMsg, dataFetchMapKey, data, err, errMsg1;
166
- return _ts_generator(this, function(_state) {
167
- switch (_state.label) {
168
- case 0:
169
- instance = getInstance();
170
- _state.label = 1;
171
- case 1:
172
- _state.trys.push([
173
- 1,
174
- 3,
175
- ,
176
- 4
177
- ]);
178
- return [
179
- 4,
180
- callLoader()
181
- ];
182
- case 2:
183
- m = _state.sent();
184
- moduleId = m && m[Symbol.for("mf_module_id")];
185
- if (!moduleId) {
186
- throw new Error("moduleId is empty");
187
- }
188
- loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
189
- if (!loadedRemoteInfo) {
190
- throw new Error("can not find loaded remote('".concat(moduleId, "') info!"));
191
- }
192
- return [
193
- 3,
194
- 4
195
- ];
196
- case 3:
197
- e = _state.sent();
198
- errMsg = "".concat(LOAD_REMOTE_ERROR_PREFIX).concat(e);
199
- logger.debug(e);
200
- throw new Error(errMsg);
201
- case 4:
202
- _state.trys.push([
203
- 4,
204
- 6,
205
- ,
206
- 7
207
- ]);
208
- dataFetchMapKey = getDataFetchMapKey(getDataFetchInfo({
209
- name: loadedRemoteInfo.name,
210
- alias: loadedRemoteInfo.alias,
211
- id: moduleId,
212
- remoteSnapshot: loadedRemoteInfo.snapshot
213
- }), {
214
- name: instance.name,
215
- version: instance === null || instance === void 0 ? void 0 : instance.options.version
216
- });
217
- logger.debug("getData dataFetchMapKey: ", dataFetchMapKey);
218
- if (!dataFetchMapKey) {
219
- return [
220
- 2
221
- ];
222
- }
223
- return [
224
- 4,
225
- fetchData(dataFetchMapKey, _object_spread_props(_object_spread({}, options.dataFetchParams), {
226
- isDowngrade: false
227
- }), getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR))
228
- ];
229
- case 5:
230
- data = _state.sent();
231
- setDataFetchItemLoadedStatus(dataFetchMapKey);
232
- logger.debug("get data res: \n", data);
233
- return [
234
- 2,
235
- data
236
- ];
237
- case 6:
238
- err = _state.sent();
239
- errMsg1 = "".concat(DATA_FETCH_ERROR_PREFIX).concat(wrapDataFetchId(dataFetchMapKey)).concat(err);
240
- logger.debug(errMsg1);
241
- throw new Error(errMsg1);
242
- case 7:
243
- return [
244
- 2
245
- ];
246
- }
247
- });
248
- });
249
- return function getData2(noSSR) {
250
- return _ref.apply(this, arguments);
251
- };
252
- }();
253
- var LazyComponent = /* @__PURE__ */ React.lazy(/* @__PURE__ */ _async_to_generator(function() {
254
- var m, moduleId, instance, loadedRemoteInfo, dataFetchMapKey, assets, Com;
255
- return _ts_generator(this, function(_state) {
256
- switch (_state.label) {
257
- case 0:
258
- return [
259
- 4,
260
- callLoader()
261
- ];
262
- case 1:
263
- m = _state.sent();
264
- moduleId = m && m[Symbol.for("mf_module_id")];
265
- instance = getInstance();
266
- loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
267
- loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.snapshot;
268
- dataFetchMapKey = loadedRemoteInfo ? getDataFetchMapKey(getDataFetchInfo({
269
- name: loadedRemoteInfo.name,
270
- alias: loadedRemoteInfo.alias,
271
- id: moduleId,
272
- remoteSnapshot: loadedRemoteInfo.snapshot
273
- }), {
274
- name: instance.name,
275
- version: instance === null || instance === void 0 ? void 0 : instance.options.version
276
- }) : void 0;
277
- logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
278
- assets = collectSSRAssets({
279
- id: moduleId
280
- });
281
- Com = m[exportName];
282
- if (exportName in m && typeof Com === "function") {
283
- return [
284
- 2,
285
- {
286
- default: function(props) {
287
- return /* @__PURE__ */ _jsxs(_Fragment, {
288
- children: [
289
- globalThis.FEDERATION_SSR && dataFetchMapKey && /* @__PURE__ */ _jsx("script", {
290
- suppressHydrationWarning: true,
291
- dangerouslySetInnerHTML: {
292
- __html: String.raw(_templateObject(), DATA_FETCH_FUNCTION, DATA_FETCH_FUNCTION, DATA_FETCH_FUNCTION, dataFetchMapKey, JSON.stringify(props.mfData))
293
- }
294
- }),
295
- globalThis.FEDERATION_SSR && assets,
296
- /* @__PURE__ */ _jsx(Com, _object_spread({}, props))
297
- ]
298
- });
299
- }
300
- }
301
- ];
302
- } else {
303
- throw Error("Make sure that ".concat(moduleId, " has the correct export when export is ").concat(String(exportName)));
304
- }
305
- return [
306
- 2
307
- ];
308
- }
309
- });
310
- }));
311
- return function(props) {
312
- var key = props.key, args = _object_without_properties(props, [
313
- "key"
314
- ]);
315
- if (globalThis.FEDERATION_SSR && !options.noSSR) {
316
- var key1 = props.key, args1 = _object_without_properties(props, [
317
- "key"
318
- ]);
319
- return /* @__PURE__ */ _jsx(AwaitDataFetch, {
320
- resolve: getData(options.noSSR),
321
- loading: options.loading,
322
- errorElement: options.fallback,
323
- children: function(data2) {
324
- return /* @__PURE__ */ _jsx(LazyComponent, _object_spread_props(_object_spread({}, args1), {
325
- mfData: data2
326
- }));
327
- }
328
- });
329
- } else {
330
- var _useState = _sliced_to_array(useState(null), 2), data = _useState[0], setData = _useState[1];
331
- var _useState1 = _sliced_to_array(useState(true), 2), loading = _useState1[0], setLoading = _useState1[1];
332
- var _useState2 = _sliced_to_array(useState(null), 2), error = _useState2[0], setError = _useState2[1];
333
- useEffect(function() {
334
- var isMounted = true;
335
- var fetchDataAsync = function() {
336
- var _ref = _async_to_generator(function() {
337
- var result, e;
338
- return _ts_generator(this, function(_state) {
339
- switch (_state.label) {
340
- case 0:
341
- _state.trys.push([
342
- 0,
343
- 2,
344
- 3,
345
- 4
346
- ]);
347
- setLoading(true);
348
- return [
349
- 4,
350
- getData(options.noSSR)
351
- ];
352
- case 1:
353
- result = _state.sent();
354
- if (isMounted) {
355
- setData(result);
356
- }
357
- return [
358
- 3,
359
- 4
360
- ];
361
- case 2:
362
- e = _state.sent();
363
- if (isMounted) {
364
- setError(transformError(e));
365
- }
366
- return [
367
- 3,
368
- 4
369
- ];
370
- case 3:
371
- if (isMounted) {
372
- setLoading(false);
373
- }
374
- return [
375
- 7
376
- ];
377
- case 4:
378
- return [
379
- 2
380
- ];
381
- }
382
- });
383
- });
384
- return function fetchDataAsync2() {
385
- return _ref.apply(this, arguments);
386
- };
387
- }();
388
- fetchDataAsync();
389
- return function() {
390
- isMounted = false;
391
- };
392
- }, []);
393
- if (loading) {
394
- return /* @__PURE__ */ _jsx(_Fragment, {
395
- children: options.loading
396
- });
397
- }
398
- if (error) {
399
- return /* @__PURE__ */ _jsx(_Fragment, {
400
- children: typeof options.fallback === "function" ? options.fallback(error) : options.fallback
401
- });
402
- }
403
- return /* @__PURE__ */ _jsx(LazyComponent, _object_spread_props(_object_spread({}, args), {
404
- mfData: data
405
- }));
406
- }
407
- };
408
- }
409
- function createRemoteSSRComponent(options) {
410
- logger.warn("createRemoteSSRComponent is deprecated, please use createRemoteComponent instead!");
411
- return createRemoteComponent(options);
412
- }
413
- export {
414
- collectSSRAssets,
415
- createRemoteComponent,
416
- createRemoteSSRComponent
417
- };
@@ -1,12 +0,0 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
- function wrapNoSSR(createComponentFn) {
4
- return function(options) {
5
- return createComponentFn(_object_spread_props(_object_spread({}, options), {
6
- noSSR: true
7
- }));
8
- };
9
- }
10
- export {
11
- wrapNoSSR
12
- };