@ice/mf-runtime 0.0.2 → 0.0.3
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/README.md +2 -2
- package/es2017/RemoteModule.d.ts +5 -1
- package/es2017/RemoteModule.js +16 -5
- package/esm/RemoteModule.d.ts +5 -1
- package/esm/RemoteModule.js +19 -5
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -186,7 +186,6 @@ function App() {
|
|
|
186
186
|
);
|
|
187
187
|
}
|
|
188
188
|
```
|
|
189
|
-
|
|
190
189
|
## API
|
|
191
190
|
|
|
192
191
|
### init(options)
|
|
@@ -217,10 +216,11 @@ RemoteConfig 配置:
|
|
|
217
216
|
| runtime | React 运行时配置 | `{ react: React, reactDOM: ReactDOM }` | - |
|
|
218
217
|
| publicPath | 远程模块静态资源地址 | `string` | - |
|
|
219
218
|
| LoadingComponent | 加载状态组件 | `ReactNode` | `<div>Loading...</div>` |
|
|
219
|
+
| ErrorComponent | 错误回退组件 | `ReactNode` | `<div>远程模块加载失败: {error.message}</div>` |
|
|
220
|
+
| onError | 错误处理回调函数 | `(error: Error, info: { componentStack: string }) => void` | - |
|
|
220
221
|
|
|
221
222
|
|
|
222
223
|
## 注意事项
|
|
223
224
|
|
|
224
225
|
1. host name 请保证全局唯一。
|
|
225
226
|
2. remote name 的 package.json name 请保证全局唯一,否则会出现意料之外的缓存问题。
|
|
226
|
-
|
package/es2017/RemoteModule.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ interface RemoteModuleOptions {
|
|
|
8
8
|
};
|
|
9
9
|
publicPath?: string;
|
|
10
10
|
LoadingComponent?: React.ReactNode;
|
|
11
|
+
ErrorComponent?: React.ReactNode;
|
|
12
|
+
onError?: (error: Error, info: {
|
|
13
|
+
componentStack: string;
|
|
14
|
+
}) => void;
|
|
11
15
|
}
|
|
12
|
-
export declare const RemoteModule: ({ module, scope, runtime, publicPath, LoadingComponent, }: RemoteModuleOptions) => string | number | true | Iterable<React.ReactNode> | React.JSX.Element;
|
|
16
|
+
export declare const RemoteModule: ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, }: RemoteModuleOptions) => string | number | true | Iterable<React.ReactNode> | React.JSX.Element;
|
|
13
17
|
export {};
|
package/es2017/RemoteModule.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
|
|
2
2
|
import { loadRemote } from '@module-federation/runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useEffect, useState } from 'react';
|
|
5
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
5
6
|
import { FallBack } from './FallBack';
|
|
6
7
|
import { setFederatedModulePublicPath } from './set-public-path';
|
|
7
8
|
function useDynamicImport({ module, scope }) {
|
|
@@ -23,7 +24,7 @@ function useDynamicImport({ module, scope }) {
|
|
|
23
24
|
]);
|
|
24
25
|
return component;
|
|
25
26
|
}
|
|
26
|
-
export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingComponent })=>{
|
|
27
|
+
export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError })=>{
|
|
27
28
|
var _remoteModule;
|
|
28
29
|
if (publicPath) {
|
|
29
30
|
setFederatedModulePublicPath(scope, publicPath);
|
|
@@ -53,10 +54,20 @@ export const RemoteModule = ({ module, scope, runtime, publicPath, LoadingCompon
|
|
|
53
54
|
const Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
|
|
54
55
|
children: "Loading..."
|
|
55
56
|
});
|
|
57
|
+
const ErrorFallback = ({ error })=>ErrorComponent || /*#__PURE__*/ _jsxs("div", {
|
|
58
|
+
children: [
|
|
59
|
+
"远程模块加载失败: ",
|
|
60
|
+
error.message
|
|
61
|
+
]
|
|
62
|
+
});
|
|
56
63
|
if (Component) {
|
|
57
|
-
return /*#__PURE__*/ _jsx(
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
return /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
65
|
+
FallbackComponent: ErrorFallback,
|
|
66
|
+
onError: onError,
|
|
67
|
+
children: /*#__PURE__*/ _jsx(React.Suspense, {
|
|
68
|
+
fallback: Loading,
|
|
69
|
+
children: /*#__PURE__*/ _jsx(Component, {})
|
|
70
|
+
})
|
|
60
71
|
});
|
|
61
72
|
}
|
|
62
73
|
return Loading;
|
package/esm/RemoteModule.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ interface RemoteModuleOptions {
|
|
|
8
8
|
};
|
|
9
9
|
publicPath?: string;
|
|
10
10
|
LoadingComponent?: React.ReactNode;
|
|
11
|
+
ErrorComponent?: React.ReactNode;
|
|
12
|
+
onError?: (error: Error, info: {
|
|
13
|
+
componentStack: string;
|
|
14
|
+
}) => void;
|
|
11
15
|
}
|
|
12
|
-
export declare const RemoteModule: ({ module, scope, runtime, publicPath, LoadingComponent, }: RemoteModuleOptions) => string | number | true | Iterable<React.ReactNode> | React.JSX.Element;
|
|
16
|
+
export declare const RemoteModule: ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, }: RemoteModuleOptions) => string | number | true | Iterable<React.ReactNode> | React.JSX.Element;
|
|
13
17
|
export {};
|
package/esm/RemoteModule.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@ice/jsx-runtime/jsx-runtime";
|
|
5
5
|
import { loadRemote } from "@module-federation/runtime";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import { useEffect, useState } from "react";
|
|
8
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
8
9
|
import { FallBack } from "./FallBack";
|
|
9
10
|
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
10
11
|
function useDynamicImport(param) {
|
|
@@ -61,7 +62,7 @@ function useDynamicImport(param) {
|
|
|
61
62
|
return component;
|
|
62
63
|
}
|
|
63
64
|
export var RemoteModule = function(param) {
|
|
64
|
-
var module = param.module, scope = param.scope, runtime = param.runtime, publicPath = param.publicPath, LoadingComponent = param.LoadingComponent;
|
|
65
|
+
var module = param.module, scope = param.scope, runtime = param.runtime, publicPath = param.publicPath, LoadingComponent = param.LoadingComponent, ErrorComponent = param.ErrorComponent, onError = param.onError;
|
|
65
66
|
var _remoteModule;
|
|
66
67
|
if (publicPath) {
|
|
67
68
|
setFederatedModulePublicPath(scope, publicPath);
|
|
@@ -97,10 +98,23 @@ export var RemoteModule = function(param) {
|
|
|
97
98
|
var Loading = LoadingComponent || /*#__PURE__*/ _jsx("div", {
|
|
98
99
|
children: "Loading..."
|
|
99
100
|
});
|
|
101
|
+
var ErrorFallback = function(param) {
|
|
102
|
+
var error = param.error;
|
|
103
|
+
return ErrorComponent || /*#__PURE__*/ _jsxs("div", {
|
|
104
|
+
children: [
|
|
105
|
+
"远程模块加载失败: ",
|
|
106
|
+
error.message
|
|
107
|
+
]
|
|
108
|
+
});
|
|
109
|
+
};
|
|
100
110
|
if (Component) {
|
|
101
|
-
return /*#__PURE__*/ _jsx(
|
|
102
|
-
|
|
103
|
-
|
|
111
|
+
return /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
112
|
+
FallbackComponent: ErrorFallback,
|
|
113
|
+
onError: onError,
|
|
114
|
+
children: /*#__PURE__*/ _jsx(React.Suspense, {
|
|
115
|
+
fallback: Loading,
|
|
116
|
+
children: /*#__PURE__*/ _jsx(Component, {})
|
|
117
|
+
})
|
|
104
118
|
});
|
|
105
119
|
}
|
|
106
120
|
return Loading;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ice/mf-runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "ice mf runtime",
|
|
5
5
|
"files": [
|
|
6
6
|
"esm",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"@ice/jsx-runtime": "^0.2.0",
|
|
49
49
|
"@module-federation/runtime": "^0.11.2",
|
|
50
50
|
"@module-federation/runtime-core": "^0.11.2",
|
|
51
|
-
"@swc/helpers": "^0.5.1"
|
|
51
|
+
"@swc/helpers": "^0.5.1",
|
|
52
|
+
"react-error-boundary": "^5.0.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@ali/pkg-plugin-dev": "^1.0.0",
|