@hsu-react/ui 2.5.5 → 2.5.7
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/es/components/Chart/Bar/index.js +6 -1
- package/es/components/Chart/Bubble/index.js +6 -1
- package/es/components/Chart/Common/index.js +6 -1
- package/es/components/Chart/Gauge/index.js +6 -1
- package/es/components/Chart/Heatmap/index.js +9 -2
- package/es/components/Chart/Line/index.js +6 -1
- package/es/components/Chart/Pie/Pie3D/index.js +15 -7
- package/es/components/Chart/Pie/index.js +9 -2
- package/es/components/Chart/Polar/index.js +9 -2
- package/es/components/Chart/Radar/index.js +6 -1
- package/es/components/Checkbox/CheckboxGroup/index.js +4 -1
- package/es/components/FormItem/FormCodeMirror/index.js +3 -1
- package/es/components/FormItem/ItemContainer/index.js +15 -5
- package/es/components/Operate/index.js +4 -1
- package/es/components/Pagination/index.js +3 -1
- package/es/components/Search/_hooks/useSearchCommon.js +4 -1
- package/es/components/Select/AutoCompleteSelect/index.js +3 -1
- package/es/components/Spreadsheet/index.js +8 -2
- package/es/components/Table/_hooks/useTableColumns.js +4 -1
- package/es/components/Tree/_hooks/useTreeState.js +7 -4
- package/es/components/Tree/index.js +8 -2
- package/es/hooks/useShallowStable.d.ts +32 -0
- package/es/hooks/useShallowStable.js +54 -0
- package/lib/components/Chart/Bar/index.js +6 -1
- package/lib/components/Chart/Bubble/index.js +6 -1
- package/lib/components/Chart/Common/index.js +6 -1
- package/lib/components/Chart/Gauge/index.js +6 -1
- package/lib/components/Chart/Heatmap/index.js +9 -2
- package/lib/components/Chart/Line/index.js +6 -1
- package/lib/components/Chart/Pie/Pie3D/index.js +15 -7
- package/lib/components/Chart/Pie/index.js +9 -2
- package/lib/components/Chart/Polar/index.js +9 -2
- package/lib/components/Chart/Radar/index.js +6 -1
- package/lib/components/Checkbox/CheckboxGroup/index.js +4 -1
- package/lib/components/FormItem/FormCodeMirror/index.js +3 -1
- package/lib/components/FormItem/ItemContainer/index.js +16 -6
- package/lib/components/Operate/index.js +4 -1
- package/lib/components/Pagination/index.js +3 -1
- package/lib/components/Search/_hooks/useSearchCommon.js +4 -1
- package/lib/components/Select/AutoCompleteSelect/index.js +3 -1
- package/lib/components/Spreadsheet/index.js +8 -2
- package/lib/components/Table/_hooks/useTableColumns.js +4 -1
- package/lib/components/Tree/_hooks/useTreeState.js +6 -3
- package/lib/components/Tree/index.js +8 -2
- package/lib/hooks/useShallowStable.d.ts +32 -0
- package/lib/hooks/useShallowStable.js +59 -0
- package/package.json +1 -1
- package/src/__tests__/callbackDepsGuard.test.ts +4 -51
- package/src/__tests__/depsScan.ts +205 -0
- package/src/__tests__/freshObjectDeps.test.tsx +380 -0
- package/src/__tests__/freshObjectDepsGuard.test.ts +175 -0
- package/src/components/Chart/Bar/index.tsx +6 -1
- package/src/components/Chart/Bubble/index.tsx +6 -1
- package/src/components/Chart/Common/index.tsx +6 -1
- package/src/components/Chart/Gauge/index.tsx +6 -1
- package/src/components/Chart/Heatmap/index.tsx +20 -12
- package/src/components/Chart/Line/index.tsx +6 -1
- package/src/components/Chart/Pie/Pie3D/index.tsx +12 -3
- package/src/components/Chart/Pie/index.tsx +10 -2
- package/src/components/Chart/Polar/index.tsx +10 -2
- package/src/components/Chart/Radar/index.tsx +6 -1
- package/src/components/Chart/optionMemo.test.tsx +232 -0
- package/src/components/Checkbox/CheckboxGroup/index.tsx +4 -1
- package/src/components/FormItem/FormCodeMirror/index.tsx +4 -1
- package/src/components/FormItem/ItemContainer/index.tsx +21 -6
- package/src/components/Operate/index.tsx +4 -1
- package/src/components/Pagination/index.tsx +4 -1
- package/src/components/Search/_hooks/useSearchCommon.ts +4 -1
- package/src/components/Select/AutoCompleteSelect/index.tsx +4 -1
- package/src/components/Spreadsheet/depsMemo.test.tsx +95 -0
- package/src/components/Spreadsheet/index.tsx +9 -2
- package/src/components/Table/_hooks/useTableColumns.tsx +4 -1
- package/src/components/Tree/_hooks/useTreeState.ts +14 -8
- package/src/components/Tree/depsMemo.test.tsx +64 -0
- package/src/components/Tree/index.tsx +9 -2
- package/src/hooks/useShallowStable.ts +65 -0
|
@@ -14,6 +14,7 @@ var _cartesian = require("../_utils/cartesian");
|
|
|
14
14
|
var _chartTheme = require("../_utils/chartTheme");
|
|
15
15
|
var _useIsDark = _interopRequireDefault(require("../../../hooks/useIsDark"));
|
|
16
16
|
var _useLatestRef = _interopRequireDefault(require("../../../hooks/useLatestRef"));
|
|
17
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
17
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -43,8 +44,12 @@ const ChartBar = props => {
|
|
|
43
44
|
enableLegendAutoScroll = false,
|
|
44
45
|
legendVisibleCount = 8,
|
|
45
46
|
legendScrollInterval = 1500,
|
|
46
|
-
...
|
|
47
|
+
...restOption
|
|
47
48
|
} = props;
|
|
49
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
50
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
51
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
52
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
48
53
|
const chartRef = (0, _react.useRef)(null);
|
|
49
54
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
50
55
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -9,6 +9,7 @@ var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
|
9
9
|
var echarts = _interopRequireWildcard(require("echarts"));
|
|
10
10
|
var _bubble = require("../_utils/bubble");
|
|
11
11
|
var _useLatestRef = require("../../../hooks/useLatestRef");
|
|
12
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
12
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -28,8 +29,12 @@ const Bubble = props => {
|
|
|
28
29
|
title,
|
|
29
30
|
onChart,
|
|
30
31
|
onClick,
|
|
31
|
-
...
|
|
32
|
+
...restOption
|
|
32
33
|
} = props;
|
|
34
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
35
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
36
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
37
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
33
38
|
const chartRef = (0, _react.useRef)(null);
|
|
34
39
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
35
40
|
const resizeObserverRef = (0, _react.useRef)(null);
|
|
@@ -9,6 +9,7 @@ var _useContainerReady = _interopRequireDefault(require("../_hooks/useContainerR
|
|
|
9
9
|
var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
10
10
|
var echarts = _interopRequireWildcard(require("echarts"));
|
|
11
11
|
var _useLatestRef = require("../../../hooks/useLatestRef");
|
|
12
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
12
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -18,8 +19,12 @@ const Common = props => {
|
|
|
18
19
|
className,
|
|
19
20
|
style,
|
|
20
21
|
onChart,
|
|
21
|
-
...
|
|
22
|
+
...restOption
|
|
22
23
|
} = props;
|
|
24
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
25
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
26
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
27
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
23
28
|
const chartRef = (0, _react.useRef)(null);
|
|
24
29
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
25
30
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -8,6 +8,7 @@ var echarts = _interopRequireWildcard(require("echarts"));
|
|
|
8
8
|
var _useContainerReady = _interopRequireDefault(require("../_hooks/useContainerReady"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
11
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -29,8 +30,12 @@ const Gauge = props => {
|
|
|
29
30
|
axisLabel,
|
|
30
31
|
title,
|
|
31
32
|
color = "#1675FB",
|
|
32
|
-
...
|
|
33
|
+
...restSeries
|
|
33
34
|
} = series;
|
|
35
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
36
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
37
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
38
|
+
const coreSeries = (0, _useShallowStable.default)(restSeries);
|
|
34
39
|
const chartRef = (0, _react.useRef)(null);
|
|
35
40
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
36
41
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -12,10 +12,13 @@ var _heatmap = require("../_utils/heatmap");
|
|
|
12
12
|
var _chartTheme = require("../_utils/chartTheme");
|
|
13
13
|
var _useIsDark = _interopRequireDefault(require("../../../hooks/useIsDark"));
|
|
14
14
|
var _useLatestRef = require("../../../hooks/useLatestRef");
|
|
15
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
18
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
21
|
+
const DEFAULT_IN_RANGE_COLOR = ["#8BCCFB", "#75C3FB", "#5AB5F6", "#42AEFA", "#2DA1F5", "#0F89E1", "#056FBB", "#025794", "#0A4089"];
|
|
19
22
|
const Heatmap = props => {
|
|
20
23
|
const {
|
|
21
24
|
className,
|
|
@@ -34,9 +37,13 @@ const Heatmap = props => {
|
|
|
34
37
|
onChart,
|
|
35
38
|
onClick,
|
|
36
39
|
zeroColor,
|
|
37
|
-
inRangeColor =
|
|
38
|
-
...
|
|
40
|
+
inRangeColor = DEFAULT_IN_RANGE_COLOR,
|
|
41
|
+
...restOption
|
|
39
42
|
} = props;
|
|
43
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
44
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
45
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
46
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
40
47
|
const chartRef = (0, _react.useRef)(null);
|
|
41
48
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
42
49
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -14,6 +14,7 @@ var _cartesian = require("../_utils/cartesian");
|
|
|
14
14
|
var _chartTheme = require("../_utils/chartTheme");
|
|
15
15
|
var _useIsDark = _interopRequireDefault(require("../../../hooks/useIsDark"));
|
|
16
16
|
var _useLatestRef = _interopRequireDefault(require("../../../hooks/useLatestRef"));
|
|
17
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
17
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -43,8 +44,12 @@ const ChartLine = props => {
|
|
|
43
44
|
enableLegendAutoScroll = false,
|
|
44
45
|
legendVisibleCount = 8,
|
|
45
46
|
legendScrollInterval = 1500,
|
|
46
|
-
...
|
|
47
|
+
...restOption
|
|
47
48
|
} = props;
|
|
49
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
50
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
51
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
52
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
48
53
|
const chartRef = (0, _react.useRef)(null);
|
|
49
54
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
50
55
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -12,10 +12,18 @@ var _hooks = require("./_hooks");
|
|
|
12
12
|
var _option = require("./_utils/option");
|
|
13
13
|
var _indexModule = _interopRequireDefault(require("../../index.module.scss"));
|
|
14
14
|
var _useLatestRef = require("../../../../hooks/useLatestRef");
|
|
15
|
+
var _useShallowStable = _interopRequireDefault(require("../../../../hooks/useShallowStable"));
|
|
15
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
18
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
// 解构默认值写成字面量会每次渲染新建一个对象,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
21
|
+
const DEFAULT_TOOLTIP = {
|
|
22
|
+
show: false
|
|
23
|
+
};
|
|
24
|
+
const DEFAULT_LABEL = {
|
|
25
|
+
show: true
|
|
26
|
+
};
|
|
19
27
|
const ChartPie3D = props => {
|
|
20
28
|
const {
|
|
21
29
|
className,
|
|
@@ -30,17 +38,17 @@ const ChartPie3D = props => {
|
|
|
30
38
|
minHeight = 1,
|
|
31
39
|
maxHeight = 10,
|
|
32
40
|
yOffset = -0.2,
|
|
33
|
-
tooltip =
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
label = {
|
|
37
|
-
show: true
|
|
38
|
-
},
|
|
41
|
+
tooltip = DEFAULT_TOOLTIP,
|
|
42
|
+
label = DEFAULT_LABEL,
|
|
39
43
|
enableMouseControl = false,
|
|
40
44
|
onChart,
|
|
41
45
|
onClick,
|
|
42
|
-
...
|
|
46
|
+
...restOption
|
|
43
47
|
} = props;
|
|
48
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
49
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
50
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
51
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
44
52
|
const chartRef = (0, _react.useRef)(null);
|
|
45
53
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
46
54
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -11,10 +11,13 @@ var _chartUtils = require("../chartUtils");
|
|
|
11
11
|
var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
12
12
|
var _Pie3D = _interopRequireDefault(require("./Pie3D"));
|
|
13
13
|
var _useLatestRef = require("../../../hooks/useLatestRef");
|
|
14
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
20
|
+
const EMPTY_EXTEND_SERIES = [];
|
|
18
21
|
const ChartPie = props => {
|
|
19
22
|
const {
|
|
20
23
|
className,
|
|
@@ -26,7 +29,7 @@ const ChartPie = props => {
|
|
|
26
29
|
series,
|
|
27
30
|
title,
|
|
28
31
|
onChart,
|
|
29
|
-
extendSeries =
|
|
32
|
+
extendSeries = EMPTY_EXTEND_SERIES,
|
|
30
33
|
onClick,
|
|
31
34
|
enableLegendAutoScroll = false,
|
|
32
35
|
legendVisibleCount = 8,
|
|
@@ -36,8 +39,12 @@ const ChartPie = props => {
|
|
|
36
39
|
spanAngle = 180,
|
|
37
40
|
center,
|
|
38
41
|
radius,
|
|
39
|
-
...
|
|
42
|
+
...restOption
|
|
40
43
|
} = props;
|
|
44
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
45
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
46
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
47
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
41
48
|
const chartRef = (0, _react.useRef)(null);
|
|
42
49
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
43
50
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -8,10 +8,13 @@ var echarts = _interopRequireWildcard(require("echarts"));
|
|
|
8
8
|
var _useContainerReady = _interopRequireDefault(require("../_hooks/useContainerReady"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
11
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
17
|
+
const DEFAULT_COLOR = ["#00FFA3", "#00FFA3"];
|
|
15
18
|
const Polar = props => {
|
|
16
19
|
const {
|
|
17
20
|
className,
|
|
@@ -26,9 +29,13 @@ const Polar = props => {
|
|
|
26
29
|
title2Style,
|
|
27
30
|
textStyle,
|
|
28
31
|
seriesData,
|
|
29
|
-
color =
|
|
30
|
-
...
|
|
32
|
+
color = DEFAULT_COLOR,
|
|
33
|
+
...restOption
|
|
31
34
|
} = props;
|
|
35
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
36
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
37
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
38
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
32
39
|
const chartRef = (0, _react.useRef)(null);
|
|
33
40
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
34
41
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -8,6 +8,7 @@ var echarts = _interopRequireWildcard(require("echarts"));
|
|
|
8
8
|
var _useContainerReady = _interopRequireDefault(require("../_hooks/useContainerReady"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
11
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -30,8 +31,12 @@ const Radar = props => {
|
|
|
30
31
|
singleIndicatorTooltip: singleIndicatorTooltipProp = false,
|
|
31
32
|
singleIndicatorMode,
|
|
32
33
|
singleIndicatorHoverFill,
|
|
33
|
-
...
|
|
34
|
+
...restOption
|
|
34
35
|
} = props;
|
|
36
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
|
|
37
|
+
// 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
|
|
38
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
39
|
+
const coreOption = (0, _useShallowStable.default)(restOption);
|
|
35
40
|
const chartRef = (0, _react.useRef)(null);
|
|
36
41
|
const chartInstanceRef = (0, _react.useRef)(null);
|
|
37
42
|
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
@@ -13,12 +13,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
15
|
const Group = _antd.Checkbox.Group;
|
|
16
|
+
|
|
17
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
18
|
+
const EMPTY_OPTIONS = [];
|
|
16
19
|
const CheckboxGroup = props => {
|
|
17
20
|
const {
|
|
18
21
|
className,
|
|
19
22
|
outline,
|
|
20
23
|
hasAll,
|
|
21
|
-
options =
|
|
24
|
+
options = EMPTY_OPTIONS,
|
|
22
25
|
value,
|
|
23
26
|
onChange,
|
|
24
27
|
layout = "horizontal",
|
|
@@ -10,12 +10,14 @@ var _CodeMirror = _interopRequireDefault(require("../../CodeMirror"));
|
|
|
10
10
|
var _ItemContainer = _interopRequireDefault(require("../ItemContainer"));
|
|
11
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
14
|
+
const EMPTY_RULES = [];
|
|
13
15
|
const FormCodeMirror = props => {
|
|
14
16
|
const {
|
|
15
17
|
componentProps = {},
|
|
16
18
|
className: itemClassName,
|
|
17
19
|
disabled,
|
|
18
|
-
rules =
|
|
20
|
+
rules = EMPTY_RULES,
|
|
19
21
|
name,
|
|
20
22
|
...formItemProps
|
|
21
23
|
} = props;
|
|
@@ -14,11 +14,14 @@ var _usePermissions = _interopRequireDefault(require("../../../hooks/usePermissi
|
|
|
14
14
|
var _cssSupports = require("../../../utils/cssSupports");
|
|
15
15
|
var _hsuUtils = require("hsu-utils");
|
|
16
16
|
var _useLabelSize = _interopRequireDefault(require("./_hooks/useLabelSize"));
|
|
17
|
+
var _useShallowStable = _interopRequireDefault(require("../../../hooks/useShallowStable"));
|
|
17
18
|
var _useInputSize = _interopRequireDefault(require("./_hooks/useInputSize"));
|
|
18
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
22
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
23
|
+
// 解构默认值写成字面量会每次渲染新建一个对象,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
24
|
+
const EMPTY_TIPS = {};
|
|
22
25
|
const ItemContainer = props => {
|
|
23
26
|
const {
|
|
24
27
|
children,
|
|
@@ -42,7 +45,7 @@ const ItemContainer = props => {
|
|
|
42
45
|
colon,
|
|
43
46
|
label,
|
|
44
47
|
labelRender,
|
|
45
|
-
tips =
|
|
48
|
+
tips = EMPTY_TIPS,
|
|
46
49
|
horizontalAlignment = "start",
|
|
47
50
|
hideRequired = false,
|
|
48
51
|
labelClassName,
|
|
@@ -61,8 +64,15 @@ const ItemContainer = props => {
|
|
|
61
64
|
const {
|
|
62
65
|
icon = "material-symbols:help",
|
|
63
66
|
iconClassName,
|
|
64
|
-
...
|
|
67
|
+
...restTipsConfig
|
|
65
68
|
} = tips;
|
|
69
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 memo 恒不命中。
|
|
70
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
71
|
+
const tipsConfig = (0, _useShallowStable.default)(restTipsConfig);
|
|
72
|
+
// memo 只需要知道「有没有配 tips」,把对象本身放进依赖数组等于按引用比:
|
|
73
|
+
// 消费方写内联 `tips={{ ... }}`(最常见的写法)就让 label 的 memo 恒不命中。
|
|
74
|
+
// 拆成布尔量后依赖回到值语义。
|
|
75
|
+
const hasTips = Object.keys(tips).length > 0;
|
|
66
76
|
const {
|
|
67
77
|
permitted
|
|
68
78
|
} = (0, _usePermissions.default)(hasPermi);
|
|
@@ -72,7 +82,7 @@ const ItemContainer = props => {
|
|
|
72
82
|
if (hideLabel) {
|
|
73
83
|
return undefined;
|
|
74
84
|
}
|
|
75
|
-
return
|
|
85
|
+
return hasTips ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
76
86
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
77
87
|
className: (0, _classnames.default)(_indexModule.default.labelContent, labelClassName),
|
|
78
88
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
@@ -124,7 +134,7 @@ const ItemContainer = props => {
|
|
|
124
134
|
children: labelExtra
|
|
125
135
|
})]
|
|
126
136
|
}) : undefined;
|
|
127
|
-
}, [
|
|
137
|
+
}, [hasTips, labelClassName, label, tipsConfig, icon, iconClassName, labelExtra, labelExtraClassName, labelEllipsis, labelBreak, hideLabel]);
|
|
128
138
|
const {
|
|
129
139
|
width: _labelWidth,
|
|
130
140
|
height: _labelHeight,
|
|
@@ -165,9 +175,9 @@ const ItemContainer = props => {
|
|
|
165
175
|
[_indexModule.default[requiredPosition]]: requiredPosition,
|
|
166
176
|
[_indexModule.default.hideRequired]: hideRequired,
|
|
167
177
|
[_indexModule.default[horizontalAlignment]]: layout === "horizontal" && horizontalAlignment,
|
|
168
|
-
[_indexModule.default.hasLabelContent]:
|
|
178
|
+
[_indexModule.default.hasLabelContent]: hasTips,
|
|
169
179
|
[_indexModule.default.hideAdditiona]: hideAdditiona,
|
|
170
|
-
[_indexModule.default.legacyHasLabelExtra]: legacyHasSelector && layout === "vertical" && !hideLabel && !!label && !!labelExtra && !
|
|
180
|
+
[_indexModule.default.legacyHasLabelExtra]: legacyHasSelector && layout === "vertical" && !hideLabel && !!label && !!labelExtra && !hasTips
|
|
171
181
|
}),
|
|
172
182
|
colon: typeof colon === "boolean" ? colon : layout === "horizontal" && requiredPosition === "before",
|
|
173
183
|
label: labelRender ? labelRender(_label) : _label,
|
|
@@ -18,6 +18,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
18
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
22
|
+
const EMPTY_MENU = [];
|
|
23
|
+
|
|
21
24
|
/**
|
|
22
25
|
* Render an icon
|
|
23
26
|
* @param icon - Icon configuration
|
|
@@ -44,7 +47,7 @@ const Operate = props => {
|
|
|
44
47
|
const {
|
|
45
48
|
title,
|
|
46
49
|
className,
|
|
47
|
-
menu =
|
|
50
|
+
menu = EMPTY_MENU,
|
|
48
51
|
icon,
|
|
49
52
|
delete: isDelete,
|
|
50
53
|
popconfirm,
|
|
@@ -14,10 +14,12 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
18
|
+
const EMPTY_PAGE_SIZE_OPTIONS = [];
|
|
17
19
|
const Pagination = props => {
|
|
18
20
|
const {
|
|
19
21
|
simple,
|
|
20
|
-
pageSizeOptions =
|
|
22
|
+
pageSizeOptions = EMPTY_PAGE_SIZE_OPTIONS,
|
|
21
23
|
showSizeChanger,
|
|
22
24
|
onShowSizeChange,
|
|
23
25
|
onChange,
|
|
@@ -15,6 +15,9 @@ var _useSearchExpand = require("./useSearchExpand");
|
|
|
15
15
|
var _utils = require("../_utils");
|
|
16
16
|
var _indexModule = _interopRequireDefault(require("../index.module.scss"));
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
19
|
+
const EMPTY_SEARCH_ITEMS = [];
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* Extracts the common logic shared by all Search components
|
|
20
23
|
*/
|
|
@@ -22,7 +25,7 @@ const useSearchCommon = params => {
|
|
|
22
25
|
const {
|
|
23
26
|
form,
|
|
24
27
|
searchItems,
|
|
25
|
-
moreSearchItems =
|
|
28
|
+
moreSearchItems = EMPTY_SEARCH_ITEMS,
|
|
26
29
|
searchData,
|
|
27
30
|
hasPermi,
|
|
28
31
|
beforeButtonGroup,
|
|
@@ -19,6 +19,8 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
23
|
+
const EMPTY_OPTIONS = [];
|
|
22
24
|
const AutoCompleteSelect = props => {
|
|
23
25
|
const {
|
|
24
26
|
prefix,
|
|
@@ -32,7 +34,7 @@ const AutoCompleteSelect = props => {
|
|
|
32
34
|
popupClassName,
|
|
33
35
|
filterOption: customFilterOption,
|
|
34
36
|
onChange,
|
|
35
|
-
options =
|
|
37
|
+
options = EMPTY_OPTIONS,
|
|
36
38
|
placement = "bottomLeft",
|
|
37
39
|
onDropdownVisibleChange,
|
|
38
40
|
popupMatchSelectWidth,
|
|
@@ -11,20 +11,26 @@ var _hsuUtils = require("hsu-utils");
|
|
|
11
11
|
require("x-data-spreadsheet/dist/xspreadsheet.css");
|
|
12
12
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
13
|
var _xlsxspread = require("./xlsxspread");
|
|
14
|
+
var _useShallowStable = _interopRequireDefault(require("../../hooks/useShallowStable"));
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
|
+
// 解构默认值写成字面量会每次渲染新建一个对象,进依赖数组就让 effect 每渲染必重跑;提到模块级常量
|
|
20
|
+
const EMPTY_X_OPTIONS = {};
|
|
18
21
|
const Spreadsheet = props => {
|
|
19
22
|
const {
|
|
20
23
|
data,
|
|
21
|
-
xOptions =
|
|
24
|
+
xOptions = EMPTY_X_OPTIONS,
|
|
22
25
|
className
|
|
23
26
|
} = props;
|
|
24
27
|
const {
|
|
25
28
|
showBottomTool = true,
|
|
26
|
-
...
|
|
29
|
+
...restXOptions
|
|
27
30
|
} = xOptions;
|
|
31
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 memo 恒不命中。
|
|
32
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
33
|
+
const xOptionsRest = (0, _useShallowStable.default)(restXOptions);
|
|
28
34
|
const ref = (0, _react.useRef)(null);
|
|
29
35
|
const containerRef = (0, _react.useRef)(null);
|
|
30
36
|
const id = (0, _react.useMemo)(() => (0, _hsuUtils.generateRandomStr)(10), []);
|
|
@@ -15,6 +15,9 @@ var _tableUtils = require("../_utils/tableUtils");
|
|
|
15
15
|
var _usePermissions = _interopRequireDefault(require("../../../hooks/usePermissions"));
|
|
16
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
19
|
+
const EMPTY_COLUMNS = [];
|
|
20
|
+
|
|
18
21
|
// measureAlign columns: measured at 14px, consistent with the table body and autoWidth title measurement
|
|
19
22
|
const MEASURE_ALIGN_FONT_SIZE = 14;
|
|
20
23
|
// Canvas measureText only returns the advance width, about 1px narrower than the actual DOM rendering; add a 2px buffer to avoid squeezing the widest row
|
|
@@ -56,7 +59,7 @@ const getMeasureAlignWidth = (column, dataSource) => {
|
|
|
56
59
|
};
|
|
57
60
|
const useTableColumns = params => {
|
|
58
61
|
const {
|
|
59
|
-
columns =
|
|
62
|
+
columns = EMPTY_COLUMNS,
|
|
60
63
|
scroll,
|
|
61
64
|
autoWidth,
|
|
62
65
|
dataSource,
|
|
@@ -34,11 +34,14 @@ const useExpandedKeys = (expandedKeysProps, defaultExpandedKeys) => {
|
|
|
34
34
|
}
|
|
35
35
|
}, [defaultExpandedKeys, expandedKeysProps]);
|
|
36
36
|
|
|
37
|
-
// Wrap setExpandedKeys to mark that the user has manually interacted
|
|
38
|
-
|
|
37
|
+
// Wrap setExpandedKeys to mark that the user has manually interacted.
|
|
38
|
+
// 必须 useCallback:这个函数被 Tree 的 handleExpand 当依赖用,
|
|
39
|
+
// 每渲染新建一个就让那个 useCallback 恒不命中——展开回调每渲染换引用透给 antd Tree。
|
|
40
|
+
// 函数体只碰 ref 和状态 setter,两者都恒定,所以依赖数组是空的。
|
|
41
|
+
const handleSetExpandedKeys = (0, _react.useCallback)(keys => {
|
|
39
42
|
hasUserInteractedRef.current = true;
|
|
40
43
|
setExpandedKeys(keys);
|
|
41
|
-
};
|
|
44
|
+
}, []);
|
|
42
45
|
return [expandedKeys, handleSetExpandedKeys];
|
|
43
46
|
};
|
|
44
47
|
|
|
@@ -17,11 +17,14 @@ var _useClearNodeTitle = require("./_hooks/useClearNodeTitle");
|
|
|
17
17
|
var _utils = require("./_utils");
|
|
18
18
|
var _TextEllipsis = _interopRequireDefault(require("../TextEllipsis"));
|
|
19
19
|
var _usePermissions = _interopRequireDefault(require("../../hooks/usePermissions"));
|
|
20
|
+
var _useShallowStable = _interopRequireDefault(require("../../hooks/useShallowStable"));
|
|
20
21
|
var _cssSupports = require("../../utils/cssSupports");
|
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
24
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
24
25
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
26
|
+
// 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
|
|
27
|
+
const EMPTY_TREE_DATA = [];
|
|
25
28
|
const Tree = props => {
|
|
26
29
|
const {
|
|
27
30
|
title,
|
|
@@ -31,7 +34,7 @@ const Tree = props => {
|
|
|
31
34
|
titleClassName,
|
|
32
35
|
className,
|
|
33
36
|
search,
|
|
34
|
-
treeData =
|
|
37
|
+
treeData = EMPTY_TREE_DATA,
|
|
35
38
|
onChange,
|
|
36
39
|
onCheck,
|
|
37
40
|
onSelect,
|
|
@@ -52,8 +55,11 @@ const Tree = props => {
|
|
|
52
55
|
onSelectPath,
|
|
53
56
|
allowDeselect = true,
|
|
54
57
|
titleSearchBarClassName,
|
|
55
|
-
...
|
|
58
|
+
...restTreeConfig
|
|
56
59
|
} = props;
|
|
60
|
+
// rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 memo 恒不命中。
|
|
61
|
+
// useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
|
|
62
|
+
const treeConfig = (0, _useShallowStable.default)(restTreeConfig);
|
|
57
63
|
const {
|
|
58
64
|
permitted
|
|
59
65
|
} = (0, _usePermissions.default)(hasPermi);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把一个**内容没变、但每次渲染都新建**的对象收敛成**引用恒定**的对象:
|
|
3
|
+
* 浅比较(自有键 + `Object.is` 比值)相等就继续返回上一次那个引用。
|
|
4
|
+
*
|
|
5
|
+
* 用途只有一个:让它可以直接进 `useMemo` / `useEffect` 的依赖数组。
|
|
6
|
+
*
|
|
7
|
+
* React 的依赖数组按 `Object.is` 比引用,所以依赖里只要混进一个「每次渲染都新建
|
|
8
|
+
* 的对象」,memo 就**恒不命中**、effect 就**每渲染必重跑**。组件内部最容易出现
|
|
9
|
+
* 这种对象的地方是 rest 解构:
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { className, style, ...coreOption } = props; // coreOption 每次都是新对象
|
|
13
|
+
* const option = useMemo(() => ({ ...coreOption }), [coreOption]); // 永远不命中
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* 消费方就算把每一个 prop 都 memo 好,也躲不掉——新对象是组件自己建的。
|
|
17
|
+
* 正确写法是让这个对象回到值语义:
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { className, style, ...restOption } = props;
|
|
21
|
+
* const coreOption = useShallowStable(restOption); // 内容不变 → 引用不变
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* 注意这**不是**「缓存结果跳过副作用」:memo 该重算时照样重算、effect 该重跑时
|
|
25
|
+
* 照样重跑——只要 rest 里任何一个值真的变了,浅比较就不相等,新引用立刻透出去。
|
|
26
|
+
*
|
|
27
|
+
* 渲染期间读写 ref 的安全性:并发渲染下被丢弃的那次渲染可能已经把 ref 换成了它
|
|
28
|
+
* 自己的对象,但那个对象与当次 props 浅相等,所以后续渲染拿到的引用**内容永远
|
|
29
|
+
* 与当前 props 一致**,不会读到过期值。
|
|
30
|
+
*/
|
|
31
|
+
export declare function useShallowStable<T extends object>(value: T): T;
|
|
32
|
+
export default useShallowStable;
|