Skip to content

Commit 2b24937

Browse files
fix(block-popover): defer popover recompute to next animation frame to prevent toolbar position shift
1 parent 1ace216 commit 2b24937

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

  • packages/block-editor/src/components/block-popover

packages/block-editor/src/components/block-popover/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useMergeRefs } from '@wordpress/compose';
1010
import { Popover } from '@wordpress/components';
1111
import {
1212
forwardRef,
13+
useCallback,
1314
useMemo,
1415
useReducer,
1516
useLayoutEffect,
@@ -52,6 +53,10 @@ function BlockPopover(
5253
0
5354
);
5455

56+
const debouncedRecompute = useCallback( () => {
57+
window.requestAnimationFrame( () => forceRecomputePopoverDimensions() );
58+
}, [ forceRecomputePopoverDimensions ] );
59+
5560
// When blocks are moved up/down, they are animated to their new position by
5661
// updating the `transform` property manually (i.e. without using CSS
5762
// transitions or animations). The animation, which can also scroll the block
@@ -64,15 +69,13 @@ function BlockPopover(
6469
return;
6570
}
6671

67-
const observer = new window.MutationObserver(
68-
forceRecomputePopoverDimensions
69-
);
72+
const observer = new window.MutationObserver( debouncedRecompute );
7073
observer.observe( selectedElement, { attributes: true } );
7174

7275
return () => {
7376
observer.disconnect();
7477
};
75-
}, [ selectedElement ] );
78+
}, [ selectedElement, debouncedRecompute ] );
7679

7780
const popoverAnchor = useMemo( () => {
7881
if (

0 commit comments

Comments
 (0)