@module-federation/modern-js 0.0.0-next-20250708121428 → 0.0.0-next-20250709032753
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.
- package/dist/cjs/cli/configPlugin.js +1 -0
- package/dist/cjs/cli/configPlugin.spec.js +2 -1
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +100 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +143 -2
- package/dist/cjs/constant.js +49 -2
- package/dist/cjs/interfaces/global.js +16 -0
- package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
- package/dist/cjs/runtime/createRemoteComponent.js +327 -0
- package/dist/cjs/runtime/index.js +28 -0
- package/dist/cjs/runtime/{plugin.js → wrapNoSSR.js} +12 -20
- package/dist/cjs/ssr-runtime/devPlugin.js +2 -2
- package/dist/cjs/ssr-runtime/downgrade.js +114 -0
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +102 -6
- package/dist/cjs/utils/dataFetch.js +211 -0
- package/dist/cjs/utils/index.js +54 -0
- package/dist/esm/cli/configPlugin.js +1 -0
- package/dist/esm/cli/configPlugin.spec.js +2 -1
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +76 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.js +219 -2
- package/dist/esm/constant.js +37 -1
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/runtime/AwaitDataFetch.js +131 -0
- package/dist/esm/runtime/createRemoteComponent.js +417 -0
- package/dist/esm/runtime/index.js +21 -0
- package/dist/esm/runtime/wrapNoSSR.js +12 -0
- package/dist/esm/ssr-runtime/devPlugin.js +1 -1
- package/dist/esm/ssr-runtime/downgrade.js +150 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +147 -4
- package/dist/esm/utils/dataFetch.js +237 -0
- package/dist/esm/utils/index.js +28 -0
- package/dist/esm-node/cli/configPlugin.js +1 -0
- package/dist/esm-node/cli/configPlugin.spec.js +2 -1
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +70 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +143 -2
- package/dist/esm-node/constant.js +37 -1
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
- package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
- package/dist/esm-node/runtime/index.js +21 -0
- package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
- package/dist/esm-node/ssr-runtime/devPlugin.js +1 -1
- package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +89 -4
- package/dist/esm-node/utils/dataFetch.js +166 -0
- package/dist/esm-node/utils/index.js +27 -0
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
- package/dist/types/constant.d.ts +23 -0
- package/dist/types/interfaces/global.d.ts +27 -0
- package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
- package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
- package/dist/types/runtime/index.d.ts +9 -0
- package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -1
- package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +3 -0
- package/dist/types/utils/dataFetch.d.ts +26 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/package.json +18 -23
- package/dist/cjs/react/index.js +0 -44
- package/dist/esm/react/index.js +0 -12
- package/dist/esm/runtime/plugin.js +0 -19
- package/dist/esm-node/react/index.js +0 -12
- package/dist/esm-node/runtime/plugin.js +0 -19
- package/dist/types/react/index.d.ts +0 -2
- package/dist/types/runtime/plugin.d.ts +0 -2
|
@@ -0,0 +1,131 @@
|
|
|
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(void 0);
|
|
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
|
+
};
|
|
@@ -0,0 +1,417 @@
|
|
|
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 +1,22 @@
|
|
|
1
1
|
export * from "@module-federation/enhanced/runtime";
|
|
2
|
+
import { ERROR_TYPE } from "../constant";
|
|
3
|
+
var kit = {
|
|
4
|
+
get createRemoteSSRComponent() {
|
|
5
|
+
return require("./createRemoteComponent").createRemoteSSRComponent;
|
|
6
|
+
},
|
|
7
|
+
get createRemoteComponent() {
|
|
8
|
+
return require("./createRemoteComponent").createRemoteComponent;
|
|
9
|
+
},
|
|
10
|
+
get collectSSRAssets() {
|
|
11
|
+
return require("./createRemoteComponent").collectSSRAssets;
|
|
12
|
+
},
|
|
13
|
+
get wrapNoSSR() {
|
|
14
|
+
return require("./wrapNoSSR").wrapNoSSR;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
import { setSSREnv } from "../ssr-runtime/injectDataFetchFunctionPlugin";
|
|
18
|
+
export {
|
|
19
|
+
ERROR_TYPE,
|
|
20
|
+
kit,
|
|
21
|
+
setSSREnv
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -3,7 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
6
|
-
import { flushDataFetch } from "
|
|
6
|
+
import { flushDataFetch } from "../utils";
|
|
7
7
|
var mfSSRDevPlugin = function() {
|
|
8
8
|
return {
|
|
9
9
|
name: "@module-federation/modern-js",
|