Skip to content

Commit

Permalink
Add extra guarding against legacy widget preview errors (#44635)
Browse files Browse the repository at this point in the history
* Add extra guarding against legacy widget preview errors

* Add a fallback height
  • Loading branch information
talldan authored Oct 4, 2022
1 parent 91e65cb commit a7f4df0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/widgets/src/blocks/legacy-widget/edit/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ export default function Preview( { idBase, instance, isVisible } ) {
function setHeight() {
// Pick the maximum of these two values to account for margin collapsing.
const height = Math.max(
iframe.contentDocument.documentElement.offsetHeight,
iframe.contentDocument.body.offsetHeight
iframe.contentDocument.documentElement?.offsetHeight ?? 0,
iframe.contentDocument.body?.offsetHeight ?? 0
);
iframe.style.height = `${ height }px`;

// Fallback to a height of 100px if the height cannot be determined.
// This ensures the block is still selectable. 100px should hopefully
// be not so big that it's annoying, and not so small that nothing
// can be seen.
iframe.style.height = `${ height !== 0 ? height : 100 }px`;
}

const { IntersectionObserver } = iframe.ownerDocument.defaultView;
Expand Down

0 comments on commit a7f4df0

Please sign in to comment.