@@ -32,6 +32,7 @@ import {
3232 useGeneratedHtmlId ,
3333} from '../../services' ;
3434import { logicalStyle } from '../../global_styling' ;
35+ import { hasResizeObserver } from '../observer/resize_observer/resize_observer' ;
3536
3637import { CommonProps , PropsOfElement } from '../common' ;
3738import { EuiFocusTrap , EuiFocusTrapProps } from '../focus_trap' ;
@@ -221,25 +222,29 @@ export const EuiFlyout = forwardRef(
221222
222223 // We manually set up a resize observer here because useResizeObserver calls getBoundingClientRect
223224 // which results in layout thrashing when the width changes frequently, such as with a resizable flyout
224- const observer = new ResizeObserver ( ( entries ) => {
225- const width = entries [ 0 ] ?. borderBoxSize ?. [ 0 ] ?. inlineSize ;
226-
227- /**
228- * Accomodate for the `isPushed` state by adding padding to the body equal to the width of the element
229- */
230- if ( isPushed ) {
231- if ( side === 'right' ) {
232- document . body . style . paddingInlineEnd = `${ width } px` ;
233- } else if ( side === 'left' ) {
234- document . body . style . paddingInlineStart = `${ width } px` ;
225+ let observer : ResizeObserver | undefined ;
226+
227+ if ( hasResizeObserver ) {
228+ observer = new ResizeObserver ( ( entries ) => {
229+ const width = entries [ 0 ] ?. borderBoxSize ?. [ 0 ] ?. inlineSize ;
230+
231+ /**
232+ * Accomodate for the `isPushed` state by adding padding to the body equal to the width of the element
233+ */
234+ if ( isPushed ) {
235+ if ( side === 'right' ) {
236+ document . body . style . paddingInlineEnd = `${ width } px` ;
237+ } else if ( side === 'left' ) {
238+ document . body . style . paddingInlineStart = `${ width } px` ;
239+ }
235240 }
236- }
237- } ) ;
241+ } ) ;
238242
239- observer . observe ( resizeRef ) ;
243+ observer . observe ( resizeRef ) ;
244+ }
240245
241246 return ( ) => {
242- observer . disconnect ( ) ;
247+ observer ? .disconnect ( ) ;
243248
244249 if ( isPushed ) {
245250 if ( side === 'right' ) {
0 commit comments