@arcblock/ux 2.4.56 → 2.4.58
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.
@@ -83,18 +83,27 @@ function WebWalletSWKeeper(_ref) {
|
|
83
83
|
webWalletUrl,
|
84
84
|
maxIdleTime
|
85
85
|
} = _ref;
|
86
|
-
|
86
|
+
// 渲染前先记录是否已经存在一个 WebWalletSWKeeper 实例
|
87
|
+
const instanceExists = (0, _react.useRef)(!!id);
|
88
|
+
const isIdle = (0, _useIdle.default)(maxIdleTime); // 如果已经存在一个 WebWalletSWKeeper 实例, cleanup 的时机应该由该实例控制
|
89
|
+
|
90
|
+
const _cleanup = () => {
|
91
|
+
if (!instanceExists.current) {
|
92
|
+
cleanup();
|
93
|
+
}
|
94
|
+
}; // 用户操作空闲时间超过 maxIdleTime 时禁用, 活跃时启用
|
95
|
+
|
87
96
|
|
88
97
|
(0, _react.useEffect)(() => {
|
89
98
|
if (isIdle) {
|
90
|
-
|
99
|
+
_cleanup();
|
91
100
|
} else {
|
92
101
|
enable(webWalletUrl);
|
93
102
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
94
103
|
|
95
104
|
}, [isIdle]); // 组件销毁时自动清理
|
96
105
|
|
97
|
-
(0, _react.useEffect)(() => () =>
|
106
|
+
(0, _react.useEffect)(() => () => _cleanup(), []);
|
98
107
|
return null;
|
99
108
|
}
|
100
109
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.4.
|
3
|
+
"version": "2.4.58",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -47,11 +47,11 @@
|
|
47
47
|
"react": ">=18.1.0",
|
48
48
|
"react-ga": "^2.7.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "5072377a5337b718e239ba1f94e97147e64451f6",
|
51
51
|
"dependencies": {
|
52
52
|
"@arcblock/did-motif": "^1.1.10",
|
53
|
-
"@arcblock/icons": "^2.4.
|
54
|
-
"@arcblock/react-hooks": "^2.4.
|
53
|
+
"@arcblock/icons": "^2.4.58",
|
54
|
+
"@arcblock/react-hooks": "^2.4.58",
|
55
55
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
56
56
|
"@emotion/react": "^11.10.4",
|
57
57
|
"@emotion/styled": "^11.10.4",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useEffect } from 'react';
|
1
|
+
import { useEffect, useRef } from 'react';
|
2
2
|
import PropTypes from 'prop-types';
|
3
3
|
import useIdle from 'react-use/lib/useIdle';
|
4
4
|
import useLocalStorage from 'react-use/lib/useLocalStorage';
|
@@ -50,18 +50,26 @@ const enable = (webWalletUrl) => {
|
|
50
50
|
|
51
51
|
// 该组件通过嵌入一个 web wallet iframe 帮助 web wallet service worker 延最大空闲时间
|
52
52
|
function WebWalletSWKeeper({ webWalletUrl, maxIdleTime }) {
|
53
|
+
// 渲染前先记录是否已经存在一个 WebWalletSWKeeper 实例
|
54
|
+
const instanceExists = useRef(!!id);
|
53
55
|
const isIdle = useIdle(maxIdleTime);
|
56
|
+
// 如果已经存在一个 WebWalletSWKeeper 实例, cleanup 的时机应该由该实例控制
|
57
|
+
const _cleanup = () => {
|
58
|
+
if (!instanceExists.current) {
|
59
|
+
cleanup();
|
60
|
+
}
|
61
|
+
};
|
54
62
|
// 用户操作空闲时间超过 maxIdleTime 时禁用, 活跃时启用
|
55
63
|
useEffect(() => {
|
56
64
|
if (isIdle) {
|
57
|
-
|
65
|
+
_cleanup();
|
58
66
|
} else {
|
59
67
|
enable(webWalletUrl);
|
60
68
|
}
|
61
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
62
70
|
}, [isIdle]);
|
63
71
|
// 组件销毁时自动清理
|
64
|
-
useEffect(() => () =>
|
72
|
+
useEffect(() => () => _cleanup(), []);
|
65
73
|
return null;
|
66
74
|
}
|
67
75
|
|