Skip to content

Commit

Permalink
fixed offsetHeight error if documentElement defined as null
Browse files Browse the repository at this point in the history
  • Loading branch information
Fellan-91 committed Sep 24, 2024
1 parent 0309879 commit 504526a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions assets/editor-constructor/boxes/code-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export default function CodePreview(props) {
function setIframeHeight() {
const iframe = iframeRef.current;

// 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.style.height = `${height}px`;
if (iframe.contentDocument.documentElement) {
// 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.style.height = `${height}px`;
}
}

function calculateIframeHeight(iframe) {
Expand Down

0 comments on commit 504526a

Please sign in to comment.