File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
packages/x-charts/src/internals/plugins/featurePlugins Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { useAssertModelConsistency } from '@mui/x-internals/useAssertModelConsistency' ;
2
2
import useEventCallback from '@mui/utils/useEventCallback' ;
3
3
import useEnhancedEffect from '@mui/utils/useEnhancedEffect' ;
4
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare' ;
4
5
import { ChartPlugin } from '../../models' ;
5
6
import { HighlightItemData , UseChartHighlightSignature } from './useChartHighlight.types' ;
6
7
@@ -33,6 +34,12 @@ export const useChartHighlight: ChartPlugin<UseChartHighlightSignature> = ({ sto
33
34
} ) ;
34
35
35
36
const setHighlight = useEventCallback ( ( newItem : HighlightItemData ) => {
37
+ const prevItem = store . getSnapshot ( ) . highlight . item ;
38
+
39
+ if ( fastObjectShallowCompare ( prevItem , newItem ) ) {
40
+ return ;
41
+ }
42
+
36
43
params . onHighlightChange ?.( newItem ) ;
37
44
store . update ( ( prev ) => ( { ...prev , highlight : { item : newItem } } ) ) ;
38
45
} ) ;
Original file line number Diff line number Diff line change 1
1
import useEventCallback from '@mui/utils/useEventCallback' ;
2
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare' ;
2
3
import { ChartPlugin } from '../../models' ;
3
4
import { Coordinate , UseChartInteractionSignature } from './useChartInteraction.types' ;
4
5
import { ChartItemIdentifier , ChartSeriesType } from '../../../../models/seriesType/config' ;
@@ -55,13 +56,19 @@ export const useChartInteraction: ChartPlugin<UseChartInteractionSignature> = ({
55
56
) ;
56
57
57
58
const setItemInteraction = useEventCallback ( ( newItem : ChartItemIdentifier < ChartSeriesType > ) => {
58
- store . update ( ( prev ) => ( {
59
- ...prev ,
60
- interaction : {
61
- ...prev . interaction ,
62
- item : newItem ,
63
- } ,
64
- } ) ) ;
59
+ store . update ( ( prev ) => {
60
+ if ( fastObjectShallowCompare ( prev . interaction . item , newItem ) ) {
61
+ return prev ;
62
+ }
63
+
64
+ return {
65
+ ...prev ,
66
+ interaction : {
67
+ ...prev . interaction ,
68
+ item : newItem ,
69
+ } ,
70
+ } ;
71
+ } ) ;
65
72
} ) ;
66
73
67
74
const setPointerCoordinate = useEventCallback ( ( coordinate : Coordinate | null ) => {
You can’t perform that action at this time.
0 commit comments