@@ -116,11 +116,11 @@ export default function PopoverContainer({
116
116
/*
117
117
This is a heuristic. Some layout changes are caused by user clicks (e.g. toggling the tools panel, submitting a form),
118
118
and by tracking the click event we can adapt the popover's position to the new layout.
119
- */
120
119
121
- const controller = new AbortController ( ) ;
120
+ TODO: extend this to Enter and Spacebar?
121
+ */
122
122
123
- const onClick = async ( event : UIEvent | KeyboardEvent ) => {
123
+ const onClick = ( event : UIEvent | KeyboardEvent ) => {
124
124
if (
125
125
// Do not update position if keepPosition is true.
126
126
keepPosition ||
@@ -131,29 +131,14 @@ export default function PopoverContainer({
131
131
return ;
132
132
}
133
133
134
- // Continuously update the popover position for one second to account for any layout changes
135
- // and animations. On browsers where `requestIdleCallback` is supported,
136
- // this runs only while the CPU is otherwise idle. In other browsers (mainly Safari), we call it
137
- // with a low frequency.
138
- const targetTime = performance . now ( ) + 1_000 ;
139
-
140
- while ( performance . now ( ) < targetTime ) {
141
- if ( controller . signal . aborted ) {
142
- break ;
143
- }
144
-
134
+ requestAnimationFrame ( ( ) => {
145
135
updatePositionHandler ( ) ;
146
-
147
- if ( typeof requestIdleCallback !== 'undefined' ) {
148
- await new Promise ( r => requestIdleCallback ( r ) ) ;
149
- } else {
150
- await new Promise ( r => setTimeout ( r , 50 ) ) ;
151
- }
152
- }
136
+ } ) ;
153
137
} ;
154
138
155
139
const updatePositionOnResize = ( ) => requestAnimationFrame ( ( ) => updatePositionHandler ( ) ) ;
156
140
const refreshPosition = ( ) => requestAnimationFrame ( ( ) => positionHandlerRef . current ( ) ) ;
141
+ const controller = new AbortController ( ) ;
157
142
158
143
window . addEventListener ( 'click' , onClick , { signal : controller . signal } ) ;
159
144
window . addEventListener ( 'resize' , updatePositionOnResize , { signal : controller . signal } ) ;
0 commit comments