From 179cffad3e7719c5ac0396d0009327253db16d17 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:16:07 +1000 Subject: [PATCH] Fix editor error in Safari due to availability of checkVisibility method (#65069) * Fix editor error in Safari due to availability of checkVisibility method * Add fallback approach if checkVisibility is not available * Be specific about which Safari version we're talking about Co-authored-by: Ramon --------- Co-authored-by: andrewserong Co-authored-by: ramonjd --- packages/block-editor/src/utils/dom.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/utils/dom.js b/packages/block-editor/src/utils/dom.js index bfdce60b9f006..9c2e813ef742b 100644 --- a/packages/block-editor/src/utils/dom.js +++ b/packages/block-editor/src/utils/dom.js @@ -96,11 +96,26 @@ function isElementVisible( element ) { return false; } - return element.checkVisibility( { - opacityProperty: true, - contentVisibilityAuto: true, - visibilityProperty: true, - } ); + // Older browsers, e.g. Safari < 17.4 may not support the `checkVisibility` method. + if ( element.checkVisibility ) { + return element.checkVisibility?.( { + opacityProperty: true, + contentVisibilityAuto: true, + visibilityProperty: true, + } ); + } + + const style = viewport.getComputedStyle( element ); + + if ( + style.display === 'none' || + style.visibility === 'hidden' || + style.opacity === '0' + ) { + return false; + } + + return true; } /**