From ae0ed4176bfbf43781adf3b3901979c185a63aba Mon Sep 17 00:00:00 2001 From: Lars Artmann Date: Wed, 15 Mar 2023 09:55:11 +0100 Subject: [PATCH] fixes #7548 - Scroll bar because auto height adjustment doesn't take <0.5 values into account (#7549) Co-authored-by: Peer Richelsen Co-authored-by: Hariom Balhara --- .../embeds/embed-core/src/embed-iframe.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/embeds/embed-core/src/embed-iframe.ts b/packages/embeds/embed-core/src/embed-iframe.ts index 28158e0ad2..ece358bbde 100644 --- a/packages/embeds/embed-core/src/embed-iframe.ts +++ b/packages/embeds/embed-core/src/embed-iframe.ts @@ -341,15 +341,16 @@ function keepParentInformedAboutDimensionChanges() { } const mainElementStyles = getComputedStyle(mainElement); - const contentHeight = - mainElement.offsetHeight + - parseInt(mainElementStyles.marginTop) + - parseInt(mainElementStyles.marginBottom); - const contentWidth = - mainElement.offsetWidth + - parseInt(mainElementStyles.marginLeft) + - parseInt(mainElementStyles.marginRight); - + // Use, .height as that gives more accurate value in floating point. Also, do a ceil on the total sum so that whatever happens there is enough iframe size to avoid scroll. + const contentHeight = Math.ceil( + parseFloat(mainElementStyles.height) + + parseFloat(mainElementStyles.marginTop) + + parseFloat(mainElementStyles.marginBottom)); + const contentWidth = Math.ceil( + parseFloat(mainElementStyles.width) + + parseFloat(mainElementStyles.marginLeft) + + parseFloat(mainElementStyles.marginRight)); + // During first render let iframe tell parent that how much is the expected height to avoid scroll. // Parent would set the same value as the height of iframe which would prevent scroll. // On subsequent renders, consider html height as the height of the iframe. If we don't do this, then if iframe get's bigger in height, it would never shrink