Overview

In in useSyncIframeHeightToContent.ts

// Apply a max-height to elements with vh units in their height - otherwise an infinite loop can occur where a component's
          // height is based on the height of the iFrame and the iFrame's height is based on that component leading
          // to an ever-increasing iFrame height!
          const elements: NodeListOf<HTMLElement> =
            iframeHTML.querySelectorAll('*');
          elements.forEach((element: HTMLElement) => {
            if (element.style.height.endsWith('vh')) {
              const vhValue = parseFloat(element.style.height);
              const newHeight = (vhValue / 100) * height;
              element.style.maxHeight = newHeight + 'px';
              resizeIframe();
            }
          });

This is very useful as it allows the use of vh units to style components without screwing up the iframe styling. However, this only works for inline styles, so this will need to work for stylesheet-applied vh-heights as well (likely the more common scenario).

Proposed resolution

User interface changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bnjmnm created an issue. See original summary.

wim leers’s picture

Are tests feasible for this? 🤔

bnjmnm’s picture

Are tests feasible for this? 🤔

Yes -

  • create a test-only component that uses VH units for its height
  • In an e2e test first drag the component into the layout
  • Check the iframe height and confirm it isn't absurdly large due to it determining height based on a seemingly infinitely tall vh-height component
gauravvvv’s picture

Assigned: Unassigned » gauravvvv

gauravvvv’s picture

Assigned: gauravvvv » Unassigned
Status: Active » Needs work

Still needs to add test component.

wim leers’s picture

Issue tags: +Needs tests

jessebaker’s picture

Version: » 0.x-dev
Assigned: Unassigned » bnjmnm

Came across this pretty old one!

In some very quick testing this still seems to be slightly problematic. I made a code component with a 50vh height. While it doesn't seem to grow infinitely in size, the 50vh IS based on the height of the iFrame and on a very long page that can be huge.

Perhaps a different solution would be to get the height of the parent window and base the vh calculation on that rather than the height of the iFrame/whole page. It's still not perfect, but at least it will more likely be closer to the intended height.

jessebaker’s picture

Adding #3518708: Components with height in VH can cause the preview iFrame to expand infinitely in height as a related issue. That fixes a bug that was present for vh units in inline styles.

The stylesheet based VH unit issue described in the summary still exists.

wim leers’s picture

Title: VH units fix only works for inline styles » VH units fix only works for inline styles, not for VH units used in CSS files

#10: so would this title be more accurate?

bnjmnm’s picture

Assigned: bnjmnm » Unassigned

This shouldn't be a problem once [##3534490] lands

jessebaker’s picture

Status: Needs work » Closed (outdated)
Related issues: +#3538809: IFrame height breaks when using min-h-screen class on component

Closing this. #3534490: Cannot use `h-screen` from Tailwind with XB landed which addressed the main problem described by this issue. The two remaining issues that I can see are not accurately described by the issue summary here and can be fixed in their respective issues

#3538809: IFrame height breaks when using min-h-screen class on component
#3544531: 100% height on body or html element breaks viewport height calculation