diff --git a/packages/components/src/popover/index.tsx b/packages/components/src/popover/index.tsx index 3005f13c952ec0..83092342d625d1 100644 --- a/packages/components/src/popover/index.tsx +++ b/packages/components/src/popover/index.tsx @@ -287,11 +287,45 @@ const UnforwardedPopover = ( ? undefined : normalizedPlacementFromProps, middleware, - whileElementsMounted: ( referenceParam, floatingParam, updateParam ) => - autoUpdate( referenceParam, floatingParam, updateParam, { - layoutShift: false, - animationFrame: true, - } ), + whileElementsMounted: ( + referenceParam, + floatingParam, + updateParam + ) => { + const cleanupAutoUpdate = autoUpdate( + referenceParam, + floatingParam, + updateParam, + { + layoutShift: false, + animationFrame: true, + } + ); + + // Observe mutations on the parent div of the inserter to update toolbar position. + const targetElement = document.querySelector( + '.interface-interface-skeleton__body' + ); + + if ( targetElement ) { + const mutationObserver = new MutationObserver( () => { + updateParam(); + } ); + + mutationObserver.observe( targetElement, { + childList: true, + subtree: true, + attributes: true, + } ); + + return () => { + cleanupAutoUpdate(); + mutationObserver.disconnect(); + }; + } + + return cleanupAutoUpdate; + }, } ); const arrowCallbackRef = useCallback(