@luck-design-biz/luckda 1.0.2-3 → 1.0.2-4

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.
@@ -2,9 +2,14 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React, { Component } from 'react';
6
- var ErrorBoundary = /*#__PURE__*/function (_Component) {
7
- _inherits(ErrorBoundary, _Component);
5
+ import React, { PureComponent } from 'react';
6
+ import styled from 'styled-components';
7
+ var Wrapper = styled.div.withConfig({
8
+ displayName: "Wrapper",
9
+ componentId: "luckda-6530__sc-1ge5tx6-0"
10
+ })(["width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;"]);
11
+ var ErrorBoundary = /*#__PURE__*/function (_PureComponent) {
12
+ _inherits(ErrorBoundary, _PureComponent);
8
13
  var _super = _createSuper(ErrorBoundary);
9
14
  function ErrorBoundary(props) {
10
15
  var _this;
@@ -18,6 +23,18 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
18
23
  return _this;
19
24
  }
20
25
  _createClass(ErrorBoundary, [{
26
+ key: "componentDidUpdate",
27
+ value: function componentDidUpdate(prevProps) {
28
+ if (this.props.children !== prevProps.children && this.state.hasError) {
29
+ // 重置 hasError 为 false 以便重新渲染子组件
30
+ this.setState({
31
+ hasError: false,
32
+ error: '',
33
+ errorInfo: ''
34
+ });
35
+ }
36
+ }
37
+ }, {
21
38
  key: "componentDidCatch",
22
39
  value: function componentDidCatch(error, errorInfo) {
23
40
  var _this$props$onErrorCa, _this$props;
@@ -35,7 +52,7 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
35
52
  value: function render() {
36
53
  if (this.state.hasError) {
37
54
  // 如果有错误,显示备用 UI
38
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("h3", {
55
+ return /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement("h3", {
39
56
  style: {
40
57
  whiteSpace: 'pre-line',
41
58
  color: 'var(--luck-color-danger)',
@@ -58,5 +75,5 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
58
75
  }
59
76
  }]);
60
77
  return ErrorBoundary;
61
- }(Component);
78
+ }(PureComponent);
62
79
  export default ErrorBoundary;
@@ -11,8 +11,13 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
11
11
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
12
  var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
13
13
  var _react = _interopRequireWildcard(require("react"));
14
- var ErrorBoundary = /*#__PURE__*/function (_Component) {
15
- (0, _inherits2.default)(ErrorBoundary, _Component);
14
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
15
+ var Wrapper = _styledComponents.default.div.withConfig({
16
+ displayName: "Wrapper",
17
+ componentId: "luckda-6530__sc-1ge5tx6-0"
18
+ })(["width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;"]);
19
+ var ErrorBoundary = /*#__PURE__*/function (_PureComponent) {
20
+ (0, _inherits2.default)(ErrorBoundary, _PureComponent);
16
21
  var _super = (0, _createSuper2.default)(ErrorBoundary);
17
22
  function ErrorBoundary(props) {
18
23
  var _this;
@@ -26,6 +31,18 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
26
31
  return _this;
27
32
  }
28
33
  (0, _createClass2.default)(ErrorBoundary, [{
34
+ key: "componentDidUpdate",
35
+ value: function componentDidUpdate(prevProps) {
36
+ if (this.props.children !== prevProps.children && this.state.hasError) {
37
+ // 重置 hasError 为 false 以便重新渲染子组件
38
+ this.setState({
39
+ hasError: false,
40
+ error: '',
41
+ errorInfo: ''
42
+ });
43
+ }
44
+ }
45
+ }, {
29
46
  key: "componentDidCatch",
30
47
  value: function componentDidCatch(error, errorInfo) {
31
48
  var _this$props$onErrorCa, _this$props;
@@ -43,7 +60,7 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
43
60
  value: function render() {
44
61
  if (this.state.hasError) {
45
62
  // 如果有错误,显示备用 UI
46
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h3", {
63
+ return /*#__PURE__*/_react.default.createElement(Wrapper, null, /*#__PURE__*/_react.default.createElement("h3", {
47
64
  style: {
48
65
  whiteSpace: 'pre-line',
49
66
  color: 'var(--luck-color-danger)',
@@ -66,5 +83,5 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
66
83
  }
67
84
  }]);
68
85
  return ErrorBoundary;
69
- }(_react.Component);
86
+ }(_react.PureComponent);
70
87
  var _default = exports.default = ErrorBoundary;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luck-design-biz/luckda",
3
- "version": "1.0.2-3",
3
+ "version": "1.0.2-4",
4
4
  "description": "前端配置管理中心业务组件库",
5
5
  "scripts": {
6
6
  "start": "cross-env NODE_OPTIONS=--max-old-space-size=10240 USER_RUNTIME=SITE RUNTIME=dev umi dev",