@ice/mf-runtime 0.0.6 → 0.0.7-beta.2
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 +24 -18
- package/esm/RemoteModule.js +30 -24
- package/package.json +1 -1
package/es2017/RemoteModule.js
CHANGED
|
@@ -3,7 +3,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
|
|
4
4
|
import { loadRemote } from '@module-federation/runtime';
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
6
|
+
import { useEffect, useState, useMemo } from 'react';
|
|
7
7
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
8
8
|
import { FallBack } from './FallBack';
|
|
9
9
|
import { setFederatedModulePublicPath } from './set-public-path';
|
|
@@ -27,7 +27,6 @@ function useDynamicImport({ module, scope }) {
|
|
|
27
27
|
return component;
|
|
28
28
|
}
|
|
29
29
|
export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, componentProps = {}, children = null })=>{
|
|
30
|
-
var _remoteModule;
|
|
31
30
|
if (publicPath) {
|
|
32
31
|
setFederatedModulePublicPath(scope, publicPath);
|
|
33
32
|
}
|
|
@@ -35,24 +34,31 @@ export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingCompon
|
|
|
35
34
|
module,
|
|
36
35
|
scope
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
const Component = useMemo(()=>{
|
|
38
|
+
var _remoteModule;
|
|
39
|
+
let Component = null;
|
|
40
|
+
if ((_remoteModule = remoteModule) === null || _remoteModule === void 0 ? void 0 : _remoteModule.default) {
|
|
41
|
+
if (runtime) {
|
|
42
|
+
const { react, reactDOM } = runtime;
|
|
43
|
+
const w = FallBack({
|
|
44
|
+
Original: remoteModule.default,
|
|
45
|
+
remoteReact: ()=>react,
|
|
46
|
+
remoteReactDOM: ()=>reactDOM
|
|
47
|
+
});
|
|
48
|
+
Component = w;
|
|
49
|
+
} else {
|
|
50
|
+
Component = /*#__PURE__*/ React.lazy(()=>Promise.resolve({
|
|
51
|
+
default: remoteModule.default
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
48
54
|
} else {
|
|
49
|
-
Component =
|
|
50
|
-
default: remoteModule.default
|
|
51
|
-
}));
|
|
55
|
+
Component = remoteModule;
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
return Component;
|
|
58
|
+
}, [
|
|
59
|
+
remoteModule,
|
|
60
|
+
runtime
|
|
61
|
+
]);
|
|
56
62
|
const Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
|
|
57
63
|
children: "Loading..."
|
|
58
64
|
});
|
package/esm/RemoteModule.js
CHANGED
|
@@ -6,7 +6,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
|
|
7
7
|
import { loadRemote } from "@module-federation/runtime";
|
|
8
8
|
import * as React from "react";
|
|
9
|
-
import { useEffect, useState } from "react";
|
|
9
|
+
import { useEffect, useState, useMemo } from "react";
|
|
10
10
|
import { ErrorBoundary } from "react-error-boundary";
|
|
11
11
|
import { FallBack } from "./FallBack";
|
|
12
12
|
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
@@ -65,7 +65,6 @@ function useDynamicImport(param) {
|
|
|
65
65
|
}
|
|
66
66
|
export var RemoteModule = function(param) {
|
|
67
67
|
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;
|
|
68
|
-
var _remoteModule;
|
|
69
68
|
if (publicPath) {
|
|
70
69
|
setFederatedModulePublicPath(scope, publicPath);
|
|
71
70
|
}
|
|
@@ -73,30 +72,37 @@ export var RemoteModule = function(param) {
|
|
|
73
72
|
module: module,
|
|
74
73
|
scope: scope
|
|
75
74
|
});
|
|
76
|
-
var Component =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} else {
|
|
91
|
-
Component = /*#__PURE__*/ React.lazy(function() {
|
|
92
|
-
return Promise.resolve({
|
|
93
|
-
default: remoteModule.default
|
|
75
|
+
var Component = useMemo(function() {
|
|
76
|
+
var _remoteModule;
|
|
77
|
+
var Component = null;
|
|
78
|
+
if ((_remoteModule = remoteModule) === null || _remoteModule === void 0 ? void 0 : _remoteModule.default) {
|
|
79
|
+
if (runtime) {
|
|
80
|
+
var react = runtime.react, reactDOM = runtime.reactDOM;
|
|
81
|
+
var w = FallBack({
|
|
82
|
+
Original: remoteModule.default,
|
|
83
|
+
remoteReact: function() {
|
|
84
|
+
return react;
|
|
85
|
+
},
|
|
86
|
+
remoteReactDOM: function() {
|
|
87
|
+
return reactDOM;
|
|
88
|
+
}
|
|
94
89
|
});
|
|
95
|
-
|
|
90
|
+
Component = w;
|
|
91
|
+
} else {
|
|
92
|
+
Component = /*#__PURE__*/ React.lazy(function() {
|
|
93
|
+
return Promise.resolve({
|
|
94
|
+
default: remoteModule.default
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
Component = remoteModule;
|
|
96
100
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
return Component;
|
|
102
|
+
}, [
|
|
103
|
+
remoteModule,
|
|
104
|
+
runtime
|
|
105
|
+
]);
|
|
100
106
|
var Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
|
|
101
107
|
children: "Loading..."
|
|
102
108
|
});
|