@ice/mf-runtime 0.0.7-beta.7 → 0.0.8-beta.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.
- package/es2017/RemoteModule.js +30 -33
- package/esm/RemoteModule.js +33 -43
- package/package.json +1 -1
package/es2017/RemoteModule.js
CHANGED
|
@@ -8,40 +8,39 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|
|
8
8
|
import { FallBack } from './FallBack';
|
|
9
9
|
import { setFederatedModulePublicPath } from './set-public-path';
|
|
10
10
|
export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, componentProps = {}, children = null })=>{
|
|
11
|
+
var _runtime, _runtime1;
|
|
11
12
|
if (publicPath) {
|
|
12
13
|
setFederatedModulePublicPath(scope, publicPath);
|
|
13
14
|
}
|
|
14
15
|
const Component = useMemo(()=>{
|
|
15
16
|
if (!module || !scope) return null;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
return /*#__PURE__*/ React.lazy(async ()=>{
|
|
18
|
+
var _remoteModule;
|
|
19
|
+
const remoteModule = await loadRemote(`${scope}/${module}`);
|
|
20
|
+
if (!((_remoteModule = remoteModule) === null || _remoteModule === void 0 ? void 0 : _remoteModule.default)) {
|
|
21
|
+
return {
|
|
22
|
+
default: remoteModule
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (runtime) {
|
|
26
|
+
const { react, reactDOM } = runtime;
|
|
27
|
+
return {
|
|
28
|
+
default: FallBack({
|
|
22
29
|
Original: remoteModule.default,
|
|
23
30
|
remoteReact: ()=>react,
|
|
24
31
|
remoteReactDOM: ()=>reactDOM
|
|
25
|
-
})
|
|
26
|
-
return {
|
|
27
|
-
default: wrappedComponent
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
default: remoteModule.default
|
|
32
|
+
})
|
|
32
33
|
};
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error(`Error loading remote module ${scope}/${module}:`, error);
|
|
35
|
-
throw error;
|
|
36
34
|
}
|
|
35
|
+
return {
|
|
36
|
+
default: remoteModule.default
|
|
37
|
+
};
|
|
37
38
|
});
|
|
38
|
-
console.log('icestark RemoteComponent', RemoteComponent);
|
|
39
|
-
return RemoteComponent;
|
|
40
39
|
}, [
|
|
41
40
|
module,
|
|
42
41
|
scope,
|
|
43
|
-
runtime.react,
|
|
44
|
-
runtime.reactDOM
|
|
42
|
+
(_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
|
|
43
|
+
(_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM
|
|
45
44
|
]);
|
|
46
45
|
const Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
|
|
47
46
|
children: "Loading..."
|
|
@@ -52,17 +51,15 @@ export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingCompon
|
|
|
52
51
|
error.message
|
|
53
52
|
]
|
|
54
53
|
});
|
|
55
|
-
if (Component)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
return Loading;
|
|
54
|
+
if (!Component) return Loading;
|
|
55
|
+
return /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
56
|
+
FallbackComponent: ErrorFallback,
|
|
57
|
+
onError: onError,
|
|
58
|
+
children: /*#__PURE__*/ _jsx(React.Suspense, {
|
|
59
|
+
fallback: Loading,
|
|
60
|
+
children: /*#__PURE__*/ _jsx(Component, _object_spread_props(_object_spread({}, componentProps), {
|
|
61
|
+
children: children
|
|
62
|
+
}))
|
|
63
|
+
})
|
|
64
|
+
});
|
|
68
65
|
};
|
package/esm/RemoteModule.js
CHANGED
|
@@ -11,43 +11,45 @@ import { FallBack } from "./FallBack";
|
|
|
11
11
|
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
12
12
|
export var RemoteModule = function(param) {
|
|
13
13
|
var module = param.module, scope = param.scope, runtime = param.runtime, publicPath = param.publicPath, LoadingComponent = param.LoadingComponent, ErrorComponent = param.ErrorComponent, onError = param.onError, _param_componentProps = param.componentProps, componentProps = _param_componentProps === void 0 ? {} : _param_componentProps, _param_children = param.children, children = _param_children === void 0 ? null : _param_children;
|
|
14
|
+
var _runtime, _runtime1;
|
|
14
15
|
if (publicPath) {
|
|
15
16
|
setFederatedModulePublicPath(scope, publicPath);
|
|
16
17
|
}
|
|
17
18
|
var Component = useMemo(function() {
|
|
18
19
|
if (!module || !scope) return null;
|
|
19
|
-
|
|
20
|
-
var remoteModule, react, reactDOM
|
|
20
|
+
return /*#__PURE__*/ React.lazy(/*#__PURE__*/ _async_to_generator(function() {
|
|
21
|
+
var _remoteModule, remoteModule, react, reactDOM;
|
|
21
22
|
return _ts_generator(this, function(_state) {
|
|
22
23
|
switch(_state.label){
|
|
23
24
|
case 0:
|
|
24
|
-
_state.trys.push([
|
|
25
|
-
0,
|
|
26
|
-
2,
|
|
27
|
-
,
|
|
28
|
-
3
|
|
29
|
-
]);
|
|
30
25
|
return [
|
|
31
26
|
4,
|
|
32
27
|
loadRemote("".concat(scope, "/").concat(module))
|
|
33
28
|
];
|
|
34
29
|
case 1:
|
|
35
30
|
remoteModule = _state.sent();
|
|
31
|
+
if (!((_remoteModule = remoteModule) === null || _remoteModule === void 0 ? void 0 : _remoteModule.default)) {
|
|
32
|
+
return [
|
|
33
|
+
2,
|
|
34
|
+
{
|
|
35
|
+
default: remoteModule
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
}
|
|
36
39
|
if (runtime) {
|
|
37
40
|
react = runtime.react, reactDOM = runtime.reactDOM;
|
|
38
|
-
wrappedComponent = FallBack({
|
|
39
|
-
Original: remoteModule.default,
|
|
40
|
-
remoteReact: function() {
|
|
41
|
-
return react;
|
|
42
|
-
},
|
|
43
|
-
remoteReactDOM: function() {
|
|
44
|
-
return reactDOM;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
41
|
return [
|
|
48
42
|
2,
|
|
49
43
|
{
|
|
50
|
-
default:
|
|
44
|
+
default: FallBack({
|
|
45
|
+
Original: remoteModule.default,
|
|
46
|
+
remoteReact: function() {
|
|
47
|
+
return react;
|
|
48
|
+
},
|
|
49
|
+
remoteReactDOM: function() {
|
|
50
|
+
return reactDOM;
|
|
51
|
+
}
|
|
52
|
+
})
|
|
51
53
|
}
|
|
52
54
|
];
|
|
53
55
|
}
|
|
@@ -57,24 +59,14 @@ export var RemoteModule = function(param) {
|
|
|
57
59
|
default: remoteModule.default
|
|
58
60
|
}
|
|
59
61
|
];
|
|
60
|
-
case 2:
|
|
61
|
-
error = _state.sent();
|
|
62
|
-
console.error("Error loading remote module ".concat(scope, "/").concat(module, ":"), error);
|
|
63
|
-
throw error;
|
|
64
|
-
case 3:
|
|
65
|
-
return [
|
|
66
|
-
2
|
|
67
|
-
];
|
|
68
62
|
}
|
|
69
63
|
});
|
|
70
64
|
}));
|
|
71
|
-
console.log("icestark RemoteComponent", RemoteComponent);
|
|
72
|
-
return RemoteComponent;
|
|
73
65
|
}, [
|
|
74
66
|
module,
|
|
75
67
|
scope,
|
|
76
|
-
runtime.react,
|
|
77
|
-
runtime.reactDOM
|
|
68
|
+
(_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
|
|
69
|
+
(_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM
|
|
78
70
|
]);
|
|
79
71
|
var Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
|
|
80
72
|
children: "Loading..."
|
|
@@ -88,17 +80,15 @@ export var RemoteModule = function(param) {
|
|
|
88
80
|
]
|
|
89
81
|
});
|
|
90
82
|
};
|
|
91
|
-
if (Component)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
return Loading;
|
|
83
|
+
if (!Component) return Loading;
|
|
84
|
+
return /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
85
|
+
FallbackComponent: ErrorFallback,
|
|
86
|
+
onError: onError,
|
|
87
|
+
children: /*#__PURE__*/ _jsx(React.Suspense, {
|
|
88
|
+
fallback: Loading,
|
|
89
|
+
children: /*#__PURE__*/ _jsx(Component, _object_spread_props(_object_spread({}, componentProps), {
|
|
90
|
+
children: children
|
|
91
|
+
}))
|
|
92
|
+
})
|
|
93
|
+
});
|
|
104
94
|
};
|