@@ -4,7 +4,6 @@ import type {
4
4
MenuActionDescriptor ,
5
5
MenuGroupDescriptor ,
6
6
} from '../../../../../../types' ;
7
- import { useComponentDidMount } from '../../../../../../utilities/use-component-did-mount' ;
8
7
import { useI18n } from '../../../../../../utilities/i18n' ;
9
8
import { SecondaryAction } from '../../../SecondaryAction' ;
10
9
import { useEventListener } from '../../../../../../utilities/use-event-listener' ;
@@ -33,7 +32,6 @@ export function ActionsMeasurer({
33
32
} : ActionsMeasurerProps ) {
34
33
const i18n = useI18n ( ) ;
35
34
const containerNode = useRef < HTMLDivElement > ( null ) ;
36
- const animationFrame = useRef < number | null > ( null ) ;
37
35
38
36
const defaultRollupGroup : MenuGroupDescriptor = {
39
37
title : i18n . translate ( 'Polaris.ActionMenu.Actions.moreActions' ) ,
@@ -45,42 +43,30 @@ export function ActionsMeasurer({
45
43
) ;
46
44
47
45
const handleMeasurement = useCallback ( ( ) => {
48
- if ( animationFrame . current ) {
49
- cancelAnimationFrame ( animationFrame . current ) ;
46
+ if ( ! containerNode . current ) {
47
+ return ;
50
48
}
51
49
52
- animationFrame . current = requestAnimationFrame ( ( ) => {
53
- if ( ! containerNode . current ) {
54
- return ;
55
- }
56
-
57
- const containerWidth = containerNode . current . offsetWidth ;
58
- const hiddenActionNodes = containerNode . current . children ;
59
- const hiddenActionNodesArray = Array . from ( hiddenActionNodes ) ;
60
- const hiddenActionsWidths = hiddenActionNodesArray . map ( ( node ) => {
61
- const buttonWidth = Math . ceil ( node . getBoundingClientRect ( ) . width ) ;
62
- return buttonWidth + ACTION_SPACING ;
63
- } ) ;
64
- const disclosureWidth = hiddenActionsWidths . pop ( ) || 0 ;
65
-
66
- handleMeasurementProp ( {
67
- containerWidth,
68
- disclosureWidth,
69
- hiddenActionsWidths,
70
- } ) ;
50
+ const containerWidth = containerNode . current . offsetWidth ;
51
+ const hiddenActionNodes = containerNode . current . children ;
52
+ const hiddenActionNodesArray = Array . from ( hiddenActionNodes ) ;
53
+ const hiddenActionsWidths = hiddenActionNodesArray . map ( ( node ) => {
54
+ const buttonWidth = Math . ceil ( node . getBoundingClientRect ( ) . width ) ;
55
+ return buttonWidth + ACTION_SPACING ;
56
+ } ) ;
57
+ const disclosureWidth = hiddenActionsWidths . pop ( ) || 0 ;
58
+
59
+ handleMeasurementProp ( {
60
+ containerWidth,
61
+ disclosureWidth,
62
+ hiddenActionsWidths,
71
63
} ) ;
72
64
} , [ handleMeasurementProp ] ) ;
73
65
74
66
useEffect ( ( ) => {
75
67
handleMeasurement ( ) ;
76
68
} , [ handleMeasurement , actions , groups ] ) ;
77
69
78
- useComponentDidMount ( ( ) => {
79
- if ( process . env . NODE_ENV === 'development' ) {
80
- setTimeout ( handleMeasurement , 0 ) ;
81
- }
82
- } ) ;
83
-
84
70
const actionsMarkup = actions . map ( ( action ) => {
85
71
const { content, onAction, ...rest } = action ;
86
72
0 commit comments