@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.
Files changed (76) hide show
  1. package/es/components/Chart/Bar/index.js +6 -1
  2. package/es/components/Chart/Bubble/index.js +6 -1
  3. package/es/components/Chart/Common/index.js +6 -1
  4. package/es/components/Chart/Gauge/index.js +6 -1
  5. package/es/components/Chart/Heatmap/index.js +9 -2
  6. package/es/components/Chart/Line/index.js +6 -1
  7. package/es/components/Chart/Pie/Pie3D/index.js +15 -7
  8. package/es/components/Chart/Pie/index.js +9 -2
  9. package/es/components/Chart/Polar/index.js +9 -2
  10. package/es/components/Chart/Radar/index.js +6 -1
  11. package/es/components/Checkbox/CheckboxGroup/index.js +4 -1
  12. package/es/components/FormItem/FormCodeMirror/index.js +3 -1
  13. package/es/components/FormItem/ItemContainer/index.js +15 -5
  14. package/es/components/Operate/index.js +4 -1
  15. package/es/components/Pagination/index.js +3 -1
  16. package/es/components/Search/_hooks/useSearchCommon.js +4 -1
  17. package/es/components/Select/AutoCompleteSelect/index.js +3 -1
  18. package/es/components/Spreadsheet/index.js +8 -2
  19. package/es/components/Table/_hooks/useTableColumns.js +4 -1
  20. package/es/components/Tree/_hooks/useTreeState.js +7 -4
  21. package/es/components/Tree/index.js +8 -2
  22. package/es/hooks/useShallowStable.d.ts +32 -0
  23. package/es/hooks/useShallowStable.js +54 -0
  24. package/lib/components/Chart/Bar/index.js +6 -1
  25. package/lib/components/Chart/Bubble/index.js +6 -1
  26. package/lib/components/Chart/Common/index.js +6 -1
  27. package/lib/components/Chart/Gauge/index.js +6 -1
  28. package/lib/components/Chart/Heatmap/index.js +9 -2
  29. package/lib/components/Chart/Line/index.js +6 -1
  30. package/lib/components/Chart/Pie/Pie3D/index.js +15 -7
  31. package/lib/components/Chart/Pie/index.js +9 -2
  32. package/lib/components/Chart/Polar/index.js +9 -2
  33. package/lib/components/Chart/Radar/index.js +6 -1
  34. package/lib/components/Checkbox/CheckboxGroup/index.js +4 -1
  35. package/lib/components/FormItem/FormCodeMirror/index.js +3 -1
  36. package/lib/components/FormItem/ItemContainer/index.js +16 -6
  37. package/lib/components/Operate/index.js +4 -1
  38. package/lib/components/Pagination/index.js +3 -1
  39. package/lib/components/Search/_hooks/useSearchCommon.js +4 -1
  40. package/lib/components/Select/AutoCompleteSelect/index.js +3 -1
  41. package/lib/components/Spreadsheet/index.js +8 -2
  42. package/lib/components/Table/_hooks/useTableColumns.js +4 -1
  43. package/lib/components/Tree/_hooks/useTreeState.js +6 -3
  44. package/lib/components/Tree/index.js +8 -2
  45. package/lib/hooks/useShallowStable.d.ts +32 -0
  46. package/lib/hooks/useShallowStable.js +59 -0
  47. package/package.json +1 -1
  48. package/src/__tests__/callbackDepsGuard.test.ts +4 -51
  49. package/src/__tests__/depsScan.ts +205 -0
  50. package/src/__tests__/freshObjectDeps.test.tsx +380 -0
  51. package/src/__tests__/freshObjectDepsGuard.test.ts +175 -0
  52. package/src/components/Chart/Bar/index.tsx +6 -1
  53. package/src/components/Chart/Bubble/index.tsx +6 -1
  54. package/src/components/Chart/Common/index.tsx +6 -1
  55. package/src/components/Chart/Gauge/index.tsx +6 -1
  56. package/src/components/Chart/Heatmap/index.tsx +20 -12
  57. package/src/components/Chart/Line/index.tsx +6 -1
  58. package/src/components/Chart/Pie/Pie3D/index.tsx +12 -3
  59. package/src/components/Chart/Pie/index.tsx +10 -2
  60. package/src/components/Chart/Polar/index.tsx +10 -2
  61. package/src/components/Chart/Radar/index.tsx +6 -1
  62. package/src/components/Chart/optionMemo.test.tsx +232 -0
  63. package/src/components/Checkbox/CheckboxGroup/index.tsx +4 -1
  64. package/src/components/FormItem/FormCodeMirror/index.tsx +4 -1
  65. package/src/components/FormItem/ItemContainer/index.tsx +21 -6
  66. package/src/components/Operate/index.tsx +4 -1
  67. package/src/components/Pagination/index.tsx +4 -1
  68. package/src/components/Search/_hooks/useSearchCommon.ts +4 -1
  69. package/src/components/Select/AutoCompleteSelect/index.tsx +4 -1
  70. package/src/components/Spreadsheet/depsMemo.test.tsx +95 -0
  71. package/src/components/Spreadsheet/index.tsx +9 -2
  72. package/src/components/Table/_hooks/useTableColumns.tsx +4 -1
  73. package/src/components/Tree/_hooks/useTreeState.ts +14 -8
  74. package/src/components/Tree/depsMemo.test.tsx +64 -0
  75. package/src/components/Tree/index.tsx +9 -2
  76. package/src/hooks/useShallowStable.ts +65 -0
@@ -17,6 +17,7 @@ import { buildCartesianSeriesOptions, createDefaultCategoryXAxis, createDefaultV
17
17
  import { resolveChartChrome } from "../_utils/chartTheme";
18
18
  import useIsDark from "../../../hooks/useIsDark";
19
19
  import useLatestRef from "../../../hooks/useLatestRef";
20
+ import useShallowStable from "../../../hooks/useShallowStable";
20
21
  import { jsx as _jsx } from "react/jsx-runtime";
21
22
  var ChartBar = function ChartBar(props) {
22
23
  var className = props.className,
@@ -45,7 +46,11 @@ var ChartBar = function ChartBar(props) {
45
46
  legendVisibleCount = _props$legendVisibleC === void 0 ? 8 : _props$legendVisibleC,
46
47
  _props$legendScrollIn = props.legendScrollInterval,
47
48
  legendScrollInterval = _props$legendScrollIn === void 0 ? 1500 : _props$legendScrollIn,
48
- coreOption = _objectWithoutProperties(props, _excluded);
49
+ restOption = _objectWithoutProperties(props, _excluded);
50
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
51
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
52
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
53
+ var coreOption = useShallowStable(restOption);
49
54
  var chartRef = useRef(null);
50
55
  var chartInstanceRef = useRef(null);
51
56
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -22,6 +22,7 @@ import styles from "../index.module.scss";
22
22
  import * as echarts from "echarts";
23
23
  import { defaultBubbleColorList, drawCircles } from "../_utils/bubble";
24
24
  import { useLatestRef } from "../../../hooks/useLatestRef";
25
+ import useShallowStable from "../../../hooks/useShallowStable";
25
26
 
26
27
  // Extended data item type containing all properties the chart needs
27
28
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -38,7 +39,11 @@ var Bubble = function Bubble(props) {
38
39
  title = props.title,
39
40
  onChart = props.onChart,
40
41
  onClick = props.onClick,
41
- coreOption = _objectWithoutProperties(props, _excluded);
42
+ restOption = _objectWithoutProperties(props, _excluded);
43
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
44
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
45
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
46
+ var coreOption = useShallowStable(restOption);
42
47
  var chartRef = useRef(null);
43
48
  var chartInstanceRef = useRef(null);
44
49
  var resizeObserverRef = useRef(null);
@@ -12,12 +12,17 @@ import useContainerReady from "../_hooks/useContainerReady";
12
12
  import styles from "../index.module.scss";
13
13
  import * as echarts from "echarts";
14
14
  import { useLatestRef } from "../../../hooks/useLatestRef";
15
+ import useShallowStable from "../../../hooks/useShallowStable";
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  var Common = function Common(props) {
17
18
  var className = props.className,
18
19
  style = props.style,
19
20
  onChart = props.onChart,
20
- coreOption = _objectWithoutProperties(props, _excluded);
21
+ restOption = _objectWithoutProperties(props, _excluded);
22
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
23
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
24
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
25
+ var coreOption = useShallowStable(restOption);
21
26
  var chartRef = useRef(null);
22
27
  var chartInstanceRef = useRef(null);
23
28
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -11,6 +11,7 @@ import * as echarts from "echarts";
11
11
  import useContainerReady from "../_hooks/useContainerReady";
12
12
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
13
13
  import styles from "../index.module.scss";
14
+ import useShallowStable from "../../../hooks/useShallowStable";
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  var Gauge = function Gauge(props) {
16
17
  var className = props.className,
@@ -29,7 +30,11 @@ var Gauge = function Gauge(props) {
29
30
  title = _ref.title,
30
31
  _ref$color = _ref.color,
31
32
  color = _ref$color === void 0 ? "#1675FB" : _ref$color,
32
- coreSeries = _objectWithoutProperties(_ref, _excluded);
33
+ restSeries = _objectWithoutProperties(_ref, _excluded);
34
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
35
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
36
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
37
+ var coreSeries = useShallowStable(restSeries);
33
38
  var chartRef = useRef(null);
34
39
  var chartInstanceRef = useRef(null);
35
40
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -21,7 +21,10 @@ import { createDefaultHeatmapXAxis, createDefaultHeatmapYAxis } from "../_utils/
21
21
  import { resolveChartChrome } from "../_utils/chartTheme";
22
22
  import useIsDark from "../../../hooks/useIsDark";
23
23
  import { useLatestRef } from "../../../hooks/useLatestRef";
24
+ import useShallowStable from "../../../hooks/useShallowStable";
24
25
  import { jsx as _jsx } from "react/jsx-runtime";
26
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
27
+ var DEFAULT_IN_RANGE_COLOR = ["#8BCCFB", "#75C3FB", "#5AB5F6", "#42AEFA", "#2DA1F5", "#0F89E1", "#056FBB", "#025794", "#0A4089"];
25
28
  var Heatmap = function Heatmap(props) {
26
29
  var className = props.className,
27
30
  style = props.style,
@@ -40,8 +43,12 @@ var Heatmap = function Heatmap(props) {
40
43
  onClick = props.onClick,
41
44
  zeroColor = props.zeroColor,
42
45
  _props$inRangeColor = props.inRangeColor,
43
- inRangeColor = _props$inRangeColor === void 0 ? ["#8BCCFB", "#75C3FB", "#5AB5F6", "#42AEFA", "#2DA1F5", "#0F89E1", "#056FBB", "#025794", "#0A4089"] : _props$inRangeColor,
44
- coreOption = _objectWithoutProperties(props, _excluded);
46
+ inRangeColor = _props$inRangeColor === void 0 ? DEFAULT_IN_RANGE_COLOR : _props$inRangeColor,
47
+ restOption = _objectWithoutProperties(props, _excluded);
48
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
49
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
50
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
51
+ var coreOption = useShallowStable(restOption);
45
52
  var chartRef = useRef(null);
46
53
  var chartInstanceRef = useRef(null);
47
54
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -17,6 +17,7 @@ import { buildCartesianSeriesOptions, createDefaultCategoryXAxis, createDefaultV
17
17
  import { resolveChartChrome } from "../_utils/chartTheme";
18
18
  import useIsDark from "../../../hooks/useIsDark";
19
19
  import useLatestRef from "../../../hooks/useLatestRef";
20
+ import useShallowStable from "../../../hooks/useShallowStable";
20
21
  import { jsx as _jsx } from "react/jsx-runtime";
21
22
  var ChartLine = function ChartLine(props) {
22
23
  var className = props.className,
@@ -45,7 +46,11 @@ var ChartLine = function ChartLine(props) {
45
46
  legendVisibleCount = _props$legendVisibleC === void 0 ? 8 : _props$legendVisibleC,
46
47
  _props$legendScrollIn = props.legendScrollInterval,
47
48
  legendScrollInterval = _props$legendScrollIn === void 0 ? 1500 : _props$legendScrollIn,
48
- coreOption = _objectWithoutProperties(props, _excluded);
49
+ restOption = _objectWithoutProperties(props, _excluded);
50
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
51
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
52
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
53
+ var coreOption = useShallowStable(restOption);
49
54
  var chartRef = useRef(null);
50
55
  var chartInstanceRef = useRef(null);
51
56
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -9,7 +9,15 @@ import { useMouseOverHandler, useGlobalOutHandler } from "./_hooks";
9
9
  import { getPie3DOption } from "./_utils/option";
10
10
  import styles from "../../index.module.scss";
11
11
  import { useLatestRef } from "../../../../hooks/useLatestRef";
12
+ import useShallowStable from "../../../../hooks/useShallowStable";
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
+ // 解构默认值写成字面量会每次渲染新建一个对象,进依赖数组就让 memo 恒不命中;提到模块级常量
15
+ var DEFAULT_TOOLTIP = {
16
+ show: false
17
+ };
18
+ var DEFAULT_LABEL = {
19
+ show: true
20
+ };
13
21
  var ChartPie3D = function ChartPie3D(props) {
14
22
  var className = props.className,
15
23
  style = props.style,
@@ -33,18 +41,18 @@ var ChartPie3D = function ChartPie3D(props) {
33
41
  _props$yOffset = props.yOffset,
34
42
  yOffset = _props$yOffset === void 0 ? -0.2 : _props$yOffset,
35
43
  _props$tooltip = props.tooltip,
36
- tooltip = _props$tooltip === void 0 ? {
37
- show: false
38
- } : _props$tooltip,
44
+ tooltip = _props$tooltip === void 0 ? DEFAULT_TOOLTIP : _props$tooltip,
39
45
  _props$label = props.label,
40
- label = _props$label === void 0 ? {
41
- show: true
42
- } : _props$label,
46
+ label = _props$label === void 0 ? DEFAULT_LABEL : _props$label,
43
47
  _props$enableMouseCon = props.enableMouseControl,
44
48
  enableMouseControl = _props$enableMouseCon === void 0 ? false : _props$enableMouseCon,
45
49
  onChart = props.onChart,
46
50
  onClick = props.onClick,
47
- coreOption = _objectWithoutProperties(props, _excluded);
51
+ restOption = _objectWithoutProperties(props, _excluded);
52
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
53
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
54
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
55
+ var coreOption = useShallowStable(restOption);
48
56
  var chartRef = useRef(null);
49
57
  var chartInstanceRef = useRef(null);
50
58
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -20,7 +20,10 @@ import { autoScrollLegend } from "../chartUtils";
20
20
  import styles from "../index.module.scss";
21
21
  import ChartPie3D from "./Pie3D";
22
22
  import { useLatestRef } from "../../../hooks/useLatestRef";
23
+ import useShallowStable from "../../../hooks/useShallowStable";
23
24
  import { jsx as _jsx } from "react/jsx-runtime";
25
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
26
+ var EMPTY_EXTEND_SERIES = [];
24
27
  var ChartPie = function ChartPie(props) {
25
28
  var className = props.className,
26
29
  style = props.style,
@@ -32,7 +35,7 @@ var ChartPie = function ChartPie(props) {
32
35
  title = props.title,
33
36
  onChart = props.onChart,
34
37
  _props$extendSeries = props.extendSeries,
35
- extendSeries = _props$extendSeries === void 0 ? [] : _props$extendSeries,
38
+ extendSeries = _props$extendSeries === void 0 ? EMPTY_EXTEND_SERIES : _props$extendSeries,
36
39
  onClick = props.onClick,
37
40
  _props$enableLegendAu = props.enableLegendAutoScroll,
38
41
  enableLegendAutoScroll = _props$enableLegendAu === void 0 ? false : _props$enableLegendAu,
@@ -48,7 +51,11 @@ var ChartPie = function ChartPie(props) {
48
51
  spanAngle = _props$spanAngle === void 0 ? 180 : _props$spanAngle,
49
52
  center = props.center,
50
53
  radius = props.radius,
51
- coreOption = _objectWithoutProperties(props, _excluded);
54
+ restOption = _objectWithoutProperties(props, _excluded);
55
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
56
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
57
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
58
+ var coreOption = useShallowStable(restOption);
52
59
  var chartRef = useRef(null);
53
60
  var chartInstanceRef = useRef(null);
54
61
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -11,7 +11,10 @@ import * as echarts from "echarts";
11
11
  import useContainerReady from "../_hooks/useContainerReady";
12
12
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
13
13
  import styles from "../index.module.scss";
14
+ import useShallowStable from "../../../hooks/useShallowStable";
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
17
+ var DEFAULT_COLOR = ["#00FFA3", "#00FFA3"];
15
18
  var Polar = function Polar(props) {
16
19
  var className = props.className,
17
20
  style = props.style,
@@ -26,8 +29,12 @@ var Polar = function Polar(props) {
26
29
  textStyle = props.textStyle,
27
30
  seriesData = props.seriesData,
28
31
  _props$color = props.color,
29
- color = _props$color === void 0 ? ["#00FFA3", "#00FFA3"] : _props$color,
30
- coreOption = _objectWithoutProperties(props, _excluded);
32
+ color = _props$color === void 0 ? DEFAULT_COLOR : _props$color,
33
+ restOption = _objectWithoutProperties(props, _excluded);
34
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
35
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
36
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
37
+ var coreOption = useShallowStable(restOption);
31
38
  var chartRef = useRef(null);
32
39
  var chartInstanceRef = useRef(null);
33
40
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -17,6 +17,7 @@ import * as echarts from "echarts";
17
17
  import useContainerReady from "../_hooks/useContainerReady";
18
18
  import React, { useCallback, useEffect, useMemo, useRef } from "react";
19
19
  import styles from "../index.module.scss";
20
+ import useShallowStable from "../../../hooks/useShallowStable";
20
21
 
21
22
  /** Single-indicator tooltip trigger mode
22
23
  * - `point` triggers only when hovering data points/lines (native echarts item trigger)
@@ -38,7 +39,11 @@ var Radar = function Radar(props) {
38
39
  singleIndicatorTooltipProp = _props$singleIndicato === void 0 ? false : _props$singleIndicato,
39
40
  singleIndicatorMode = props.singleIndicatorMode,
40
41
  singleIndicatorHoverFill = props.singleIndicatorHoverFill,
41
- coreOption = _objectWithoutProperties(props, _excluded);
42
+ restOption = _objectWithoutProperties(props, _excluded);
43
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 chartOption 的 memo
44
+ // 恒不命中 —— 父组件每渲染一次就重跑一次 setOption(notMerge),动画重播、悬浮态被清掉。
45
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
46
+ var coreOption = useShallowStable(restOption);
42
47
  var chartRef = useRef(null);
43
48
  var chartInstanceRef = useRef(null);
44
49
  // Defers `echarts.init` until the container has a box — see the hook for why
@@ -14,12 +14,15 @@ import styles from "./index.module.scss";
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
16
  var Group = Checkbox.Group;
17
+
18
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
19
+ var EMPTY_OPTIONS = [];
17
20
  var CheckboxGroup = function CheckboxGroup(props) {
18
21
  var className = props.className,
19
22
  outline = props.outline,
20
23
  hasAll = props.hasAll,
21
24
  _props$options = props.options,
22
- options = _props$options === void 0 ? [] : _props$options,
25
+ options = _props$options === void 0 ? EMPTY_OPTIONS : _props$options,
23
26
  value = props.value,
24
27
  onChange = props.onChange,
25
28
  _props$layout = props.layout,
@@ -22,6 +22,8 @@ import { Form } from "antd";
22
22
  import CodeMirror from "../../CodeMirror";
23
23
  import ItemContainer from "../ItemContainer";
24
24
  import { jsx as _jsx } from "react/jsx-runtime";
25
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
26
+ var EMPTY_RULES = [];
25
27
  var FormCodeMirror = function FormCodeMirror(props) {
26
28
  var _componentProps$readO;
27
29
  var _props$componentProps = props.componentProps,
@@ -29,7 +31,7 @@ var FormCodeMirror = function FormCodeMirror(props) {
29
31
  itemClassName = props.className,
30
32
  disabled = props.disabled,
31
33
  _props$rules = props.rules,
32
- rules = _props$rules === void 0 ? [] : _props$rules,
34
+ rules = _props$rules === void 0 ? EMPTY_RULES : _props$rules,
33
35
  name = props.name,
34
36
  formItemProps = _objectWithoutProperties(props, _excluded);
35
37
  var enableLint = componentProps.enableLint !== false;
@@ -24,10 +24,13 @@ import usePermissions from "../../../hooks/usePermissions";
24
24
  import { isLegacyHasSelectorBrowser } from "../../../utils/cssSupports";
25
25
  import { generateRandomStr } from "hsu-utils";
26
26
  import useLabelSize from "./_hooks/useLabelSize";
27
+ import useShallowStable from "../../../hooks/useShallowStable";
27
28
  import useInputSize from "./_hooks/useInputSize";
28
29
  import { jsx as _jsx } from "react/jsx-runtime";
29
30
  import { Fragment as _Fragment } from "react/jsx-runtime";
30
31
  import { jsxs as _jsxs } from "react/jsx-runtime";
32
+ // 解构默认值写成字面量会每次渲染新建一个对象,进依赖数组就让 memo 恒不命中;提到模块级常量
33
+ var EMPTY_TIPS = {};
31
34
  var ItemContainer = function ItemContainer(props) {
32
35
  var children = props.children,
33
36
  className = props.className,
@@ -55,7 +58,7 @@ var ItemContainer = function ItemContainer(props) {
55
58
  label = props.label,
56
59
  labelRender = props.labelRender,
57
60
  _props$tips = props.tips,
58
- tips = _props$tips === void 0 ? {} : _props$tips,
61
+ tips = _props$tips === void 0 ? EMPTY_TIPS : _props$tips,
59
62
  _props$horizontalAlig = props.horizontalAlignment,
60
63
  horizontalAlignment = _props$horizontalAlig === void 0 ? "start" : _props$horizontalAlig,
61
64
  _props$hideRequired = props.hideRequired,
@@ -80,7 +83,14 @@ var ItemContainer = function ItemContainer(props) {
80
83
  var _tips$icon = tips.icon,
81
84
  icon = _tips$icon === void 0 ? "material-symbols:help" : _tips$icon,
82
85
  iconClassName = tips.iconClassName,
83
- tipsConfig = _objectWithoutProperties(tips, _excluded2);
86
+ restTipsConfig = _objectWithoutProperties(tips, _excluded2);
87
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 memo 恒不命中。
88
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
89
+ var tipsConfig = useShallowStable(restTipsConfig);
90
+ // memo 只需要知道「有没有配 tips」,把对象本身放进依赖数组等于按引用比:
91
+ // 消费方写内联 `tips={{ ... }}`(最常见的写法)就让 label 的 memo 恒不命中。
92
+ // 拆成布尔量后依赖回到值语义。
93
+ var hasTips = Object.keys(tips).length > 0;
84
94
  var _usePermissions = usePermissions(hasPermi),
85
95
  permitted = _usePermissions.permitted;
86
96
  var cls = useMemo(function () {
@@ -91,7 +101,7 @@ var ItemContainer = function ItemContainer(props) {
91
101
  if (hideLabel) {
92
102
  return undefined;
93
103
  }
94
- return Object.keys(tips).length ? /*#__PURE__*/_jsxs(_Fragment, {
104
+ return hasTips ? /*#__PURE__*/_jsxs(_Fragment, {
95
105
  children: [/*#__PURE__*/_jsx("span", {
96
106
  className: classNames(styles.labelContent, labelClassName),
97
107
  children: /*#__PURE__*/_jsx("span", {
@@ -137,7 +147,7 @@ var ItemContainer = function ItemContainer(props) {
137
147
  children: labelExtra
138
148
  })]
139
149
  }) : undefined;
140
- }, [tips, labelClassName, label, tipsConfig, icon, iconClassName, labelExtra, labelExtraClassName, labelEllipsis, labelBreak, hideLabel]);
150
+ }, [hasTips, labelClassName, label, tipsConfig, icon, iconClassName, labelExtra, labelExtraClassName, labelEllipsis, labelBreak, hideLabel]);
141
151
  var _useLabelSize = useLabelSize({
142
152
  labelWidth: labelWidth,
143
153
  labelHeight: labelHeight,
@@ -167,7 +177,7 @@ var ItemContainer = function ItemContainer(props) {
167
177
  required: required,
168
178
  message: requiredMsg !== null && requiredMsg !== void 0 ? requiredMsg : en ? "".concat(PlaceholderDictEn[type || "INPUT"]) : "".concat(PlaceholderDict[type || "INPUT"])
169
179
  }].concat(_toConsumableArray(rules)),
170
- className: classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, cls, true), styles.formItem, true), className !== null && className !== void 0 ? className : "", true), styles[layout], layout), styles[requiredPosition], requiredPosition), styles.hideRequired, hideRequired), styles[horizontalAlignment], layout === "horizontal" && horizontalAlignment), styles.hasLabelContent, !!Object.keys(tips).length), styles.hideAdditiona, hideAdditiona), styles.legacyHasLabelExtra, legacyHasSelector && layout === "vertical" && !hideLabel && !!label && !!labelExtra && !Object.keys(tips).length)),
180
+ className: classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, cls, true), styles.formItem, true), className !== null && className !== void 0 ? className : "", true), styles[layout], layout), styles[requiredPosition], requiredPosition), styles.hideRequired, hideRequired), styles[horizontalAlignment], layout === "horizontal" && horizontalAlignment), styles.hasLabelContent, hasTips), styles.hideAdditiona, hideAdditiona), styles.legacyHasLabelExtra, legacyHasSelector && layout === "vertical" && !hideLabel && !!label && !!labelExtra && !hasTips)),
171
181
  colon: typeof colon === "boolean" ? colon : layout === "horizontal" && requiredPosition === "before",
172
182
  label: labelRender ? labelRender(_label) : _label,
173
183
  style: _objectSpread({
@@ -25,6 +25,9 @@ import classNames from "classnames";
25
25
  import moreImg from "./more.png";
26
26
  import { jsx as _jsx } from "react/jsx-runtime";
27
27
  import { jsxs as _jsxs } from "react/jsx-runtime";
28
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
29
+ var EMPTY_MENU = [];
30
+
28
31
  /**
29
32
  * Render an icon
30
33
  * @param icon - Icon configuration
@@ -51,7 +54,7 @@ var Operate = function Operate(props) {
51
54
  var title = props.title,
52
55
  className = props.className,
53
56
  _props$menu = props.menu,
54
- menu = _props$menu === void 0 ? [] : _props$menu,
57
+ menu = _props$menu === void 0 ? EMPTY_MENU : _props$menu,
55
58
  icon = props.icon,
56
59
  isDelete = props.delete,
57
60
  popconfirm = props.popconfirm,
@@ -18,11 +18,13 @@ import styles from "./index.module.scss";
18
18
  import usePaginationSync from "./_hooks/usePaginationSync";
19
19
  import { jsx as _jsx } from "react/jsx-runtime";
20
20
  import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
22
+ var EMPTY_PAGE_SIZE_OPTIONS = [];
21
23
  var Pagination = function Pagination(props) {
22
24
  var _props$current, _props$pageSize2;
23
25
  var simple = props.simple,
24
26
  _props$pageSizeOption = props.pageSizeOptions,
25
- pageSizeOptions = _props$pageSizeOption === void 0 ? [] : _props$pageSizeOption,
27
+ pageSizeOptions = _props$pageSizeOption === void 0 ? EMPTY_PAGE_SIZE_OPTIONS : _props$pageSizeOption,
26
28
  showSizeChanger = props.showSizeChanger,
27
29
  _onShowSizeChange = props.onShowSizeChange,
28
30
  _onChange = props.onChange,
@@ -18,6 +18,9 @@ import { useAdaptiveColumnNum } from "./useAdaptiveColumnNum";
18
18
  import { useSearchExpand } from "./useSearchExpand";
19
19
  import { cleanSearchData, calculateVisibleItems, calculateButtonGroupAndColumnWidth, shouldDisplayExtraItem } from "../_utils";
20
20
  import styles from "../index.module.scss";
21
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
22
+ var EMPTY_SEARCH_ITEMS = [];
23
+
21
24
  /**
22
25
  * Extracts the common logic shared by all Search components
23
26
  */
@@ -25,7 +28,7 @@ export var useSearchCommon = function useSearchCommon(params) {
25
28
  var form = params.form,
26
29
  searchItems = params.searchItems,
27
30
  _params$moreSearchIte = params.moreSearchItems,
28
- moreSearchItems = _params$moreSearchIte === void 0 ? [] : _params$moreSearchIte,
31
+ moreSearchItems = _params$moreSearchIte === void 0 ? EMPTY_SEARCH_ITEMS : _params$moreSearchIte,
29
32
  searchData = params.searchData,
30
33
  hasPermi = params.hasPermi,
31
34
  beforeButtonGroup = params.beforeButtonGroup,
@@ -27,6 +27,8 @@ import Icon from "../../Icon";
27
27
  import { isLegacyHasSelectorBrowser } from "../../../utils/cssSupports";
28
28
  import { jsx as _jsx } from "react/jsx-runtime";
29
29
  import { jsxs as _jsxs } from "react/jsx-runtime";
30
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
31
+ var EMPTY_OPTIONS = [];
30
32
  var AutoCompleteSelect = function AutoCompleteSelect(props) {
31
33
  var prefix = props.prefix,
32
34
  suffix = props.suffix,
@@ -40,7 +42,7 @@ var AutoCompleteSelect = function AutoCompleteSelect(props) {
40
42
  customFilterOption = props.filterOption,
41
43
  onChange = props.onChange,
42
44
  _props$options = props.options,
43
- options = _props$options === void 0 ? [] : _props$options,
45
+ options = _props$options === void 0 ? EMPTY_OPTIONS : _props$options,
44
46
  _props$placement = props.placement,
45
47
  placement = _props$placement === void 0 ? "bottomLeft" : _props$placement,
46
48
  onDropdownVisibleChange = props.onDropdownVisibleChange,
@@ -20,15 +20,21 @@ import { Equal, generateRandomStr } from "hsu-utils";
20
20
  import "x-data-spreadsheet/dist/xspreadsheet.css";
21
21
  import classNames from "classnames";
22
22
  import { stox } from "./xlsxspread";
23
+ import useShallowStable from "../../hooks/useShallowStable";
23
24
  import { jsx as _jsx } from "react/jsx-runtime";
25
+ // 解构默认值写成字面量会每次渲染新建一个对象,进依赖数组就让 effect 每渲染必重跑;提到模块级常量
26
+ var EMPTY_X_OPTIONS = {};
24
27
  var Spreadsheet = function Spreadsheet(props) {
25
28
  var data = props.data,
26
29
  _props$xOptions = props.xOptions,
27
- xOptions = _props$xOptions === void 0 ? {} : _props$xOptions,
30
+ xOptions = _props$xOptions === void 0 ? EMPTY_X_OPTIONS : _props$xOptions,
28
31
  className = props.className;
29
32
  var _xOptions$showBottomT = xOptions.showBottomTool,
30
33
  showBottomTool = _xOptions$showBottomT === void 0 ? true : _xOptions$showBottomT,
31
- xOptionsRest = _objectWithoutProperties(xOptions, _excluded);
34
+ restXOptions = _objectWithoutProperties(xOptions, _excluded);
35
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 memo 恒不命中。
36
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
37
+ var xOptionsRest = useShallowStable(restXOptions);
32
38
  var ref = useRef(null);
33
39
  var containerRef = useRef(null);
34
40
  var id = useMemo(function () {
@@ -22,6 +22,9 @@ import usePermissions from "../../../hooks/usePermissions";
22
22
  import { jsx as _jsx } from "react/jsx-runtime";
23
23
  import { Fragment as _Fragment } from "react/jsx-runtime";
24
24
  import { jsxs as _jsxs } from "react/jsx-runtime";
25
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
26
+ var EMPTY_COLUMNS = [];
27
+
25
28
  // measureAlign columns: measured at 14px, consistent with the table body and autoWidth title measurement
26
29
  var MEASURE_ALIGN_FONT_SIZE = 14;
27
30
  // 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
@@ -66,7 +69,7 @@ var getMeasureAlignWidth = function getMeasureAlignWidth(column, dataSource) {
66
69
  };
67
70
  var useTableColumns = function useTableColumns(params) {
68
71
  var _params$columns = params.columns,
69
- columns = _params$columns === void 0 ? [] : _params$columns,
72
+ columns = _params$columns === void 0 ? EMPTY_COLUMNS : _params$columns,
70
73
  scroll = params.scroll,
71
74
  autoWidth = params.autoWidth,
72
75
  dataSource = params.dataSource,
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { useEffect, useState, useMemo, useRef } from "react";
7
+ import { useEffect, useState, useMemo, useRef, useCallback } from "react";
8
8
  import { Equal } from "hsu-utils";
9
9
  import { normalizeCheckedKeys } from "../_utils/normalizeCheckedKeys";
10
10
 
@@ -38,11 +38,14 @@ export var useExpandedKeys = function useExpandedKeys(expandedKeysProps, default
38
38
  }
39
39
  }, [defaultExpandedKeys, expandedKeysProps]);
40
40
 
41
- // Wrap setExpandedKeys to mark that the user has manually interacted
42
- var handleSetExpandedKeys = function handleSetExpandedKeys(keys) {
41
+ // Wrap setExpandedKeys to mark that the user has manually interacted.
42
+ // 必须 useCallback:这个函数被 Tree handleExpand 当依赖用,
43
+ // 每渲染新建一个就让那个 useCallback 恒不命中——展开回调每渲染换引用透给 antd Tree。
44
+ // 函数体只碰 ref 和状态 setter,两者都恒定,所以依赖数组是空的。
45
+ var handleSetExpandedKeys = useCallback(function (keys) {
43
46
  hasUserInteractedRef.current = true;
44
47
  setExpandedKeys(keys);
45
- };
48
+ }, []);
46
49
  return [expandedKeys, handleSetExpandedKeys];
47
50
  };
48
51
 
@@ -26,9 +26,12 @@ import { useClearNodeTitle } from "./_hooks/useClearNodeTitle";
26
26
  import { getExpandedKeysByLevel, getNodePath } from "./_utils";
27
27
  import TextEllipsis from "../TextEllipsis";
28
28
  import usePermissions from "../../hooks/usePermissions";
29
+ import useShallowStable from "../../hooks/useShallowStable";
29
30
  import { isLegacyHasSelectorBrowser } from "../../utils/cssSupports";
30
31
  import { jsx as _jsx } from "react/jsx-runtime";
31
32
  import { jsxs as _jsxs } from "react/jsx-runtime";
33
+ // 解构默认值写成字面量会每次渲染新建一个数组,进依赖数组就让 memo 恒不命中;提到模块级常量
34
+ var EMPTY_TREE_DATA = [];
32
35
  var Tree = function Tree(props) {
33
36
  var title = props.title,
34
37
  _titleRender = props.titleRender,
@@ -38,7 +41,7 @@ var Tree = function Tree(props) {
38
41
  className = props.className,
39
42
  search = props.search,
40
43
  _props$treeData = props.treeData,
41
- treeData = _props$treeData === void 0 ? [] : _props$treeData,
44
+ treeData = _props$treeData === void 0 ? EMPTY_TREE_DATA : _props$treeData,
42
45
  onChange = props.onChange,
43
46
  onCheck = props.onCheck,
44
47
  onSelect = props.onSelect,
@@ -61,7 +64,10 @@ var Tree = function Tree(props) {
61
64
  _props$allowDeselect = props.allowDeselect,
62
65
  allowDeselect = _props$allowDeselect === void 0 ? true : _props$allowDeselect,
63
66
  titleSearchBarClassName = props.titleSearchBarClassName,
64
- treeConfig = _objectWithoutProperties(props, _excluded);
67
+ restTreeConfig = _objectWithoutProperties(props, _excluded);
68
+ // rest 解构出来的对象每次渲染都是新引用,直接进依赖数组会让 memo 恒不命中。
69
+ // useShallowStable 让它回到值语义:内容浅相等就复用同一引用,真变了立刻透出新引用。
70
+ var treeConfig = useShallowStable(restTreeConfig);
65
71
  var _usePermissions = usePermissions(hasPermi),
66
72
  permitted = _usePermissions.permitted;
67
73
  var legacyHasSelector = isLegacyHasSelectorBrowser();
@@ -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;
@@ -0,0 +1,54 @@
1
+ import { useRef } from "react";
2
+
3
+ /**
4
+ * 把一个**内容没变、但每次渲染都新建**的对象收敛成**引用恒定**的对象:
5
+ * 浅比较(自有键 + `Object.is` 比值)相等就继续返回上一次那个引用。
6
+ *
7
+ * 用途只有一个:让它可以直接进 `useMemo` / `useEffect` 的依赖数组。
8
+ *
9
+ * React 的依赖数组按 `Object.is` 比引用,所以依赖里只要混进一个「每次渲染都新建
10
+ * 的对象」,memo 就**恒不命中**、effect 就**每渲染必重跑**。组件内部最容易出现
11
+ * 这种对象的地方是 rest 解构:
12
+ *
13
+ * ```tsx
14
+ * const { className, style, ...coreOption } = props; // coreOption 每次都是新对象
15
+ * const option = useMemo(() => ({ ...coreOption }), [coreOption]); // 永远不命中
16
+ * ```
17
+ *
18
+ * 消费方就算把每一个 prop 都 memo 好,也躲不掉——新对象是组件自己建的。
19
+ * 正确写法是让这个对象回到值语义:
20
+ *
21
+ * ```tsx
22
+ * const { className, style, ...restOption } = props;
23
+ * const coreOption = useShallowStable(restOption); // 内容不变 → 引用不变
24
+ * ```
25
+ *
26
+ * 注意这**不是**「缓存结果跳过副作用」:memo 该重算时照样重算、effect 该重跑时
27
+ * 照样重跑——只要 rest 里任何一个值真的变了,浅比较就不相等,新引用立刻透出去。
28
+ *
29
+ * 渲染期间读写 ref 的安全性:并发渲染下被丢弃的那次渲染可能已经把 ref 换成了它
30
+ * 自己的对象,但那个对象与当次 props 浅相等,所以后续渲染拿到的引用**内容永远
31
+ * 与当前 props 一致**,不会读到过期值。
32
+ */
33
+ export function useShallowStable(value) {
34
+ var ref = useRef(value);
35
+ if (!shallowEqual(ref.current, value)) {
36
+ ref.current = value;
37
+ }
38
+ return ref.current;
39
+ }
40
+ function shallowEqual(a, b) {
41
+ if (Object.is(a, b)) return true;
42
+ var aKeys = Object.keys(a);
43
+ var bKeys = Object.keys(b);
44
+ if (aKeys.length !== bKeys.length) return false;
45
+ for (var _i = 0, _aKeys = aKeys; _i < _aKeys.length; _i++) {
46
+ var key = _aKeys[_i];
47
+ if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
48
+ if (!Object.is(a[key], b[key])) {
49
+ return false;
50
+ }
51
+ }
52
+ return true;
53
+ }
54
+ export default useShallowStable;