Fix: Custom HTML block preview keeps expanding when iframe uses height:100vh#78677
Open
hbhalodia wants to merge 1 commit into
Open
Fix: Custom HTML block preview keeps expanding when iframe uses height:100vh#78677hbhalodia wants to merge 1 commit into
hbhalodia wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Closes #78539
Why?
How?
Testing Instructions
height:100vh:<iframe src="https://www.photopea.com" style="width:100%; height:100vh; border:0;"></iframe>Testing Instructions for Keyboard
Screenshots or screencast
Before
After
Screen.Recording.2026-05-26.at.3.46.56.PM.mov
Use of AI Tools
Detailed AI review
AI Summary Started
Root cause
The
SandBoxcomponent (used by the Custom HTML block's preview) intentionally strips viewport-unit styles (vh,vw, etc.) from user-supplied HTML, because those units are relative to the iframe's own size and would otherwise create a measurement feedback loop.That stripping is done by
removeViewportStylesinpackages/components/src/sandbox/index.tsxusing this regex:/^\\d+(vw|vh|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)$/The pattern contains a double backslash (
\\d). In a regex literal\\dmeans "a literal backslash followed by the letterd" — not "a digit". So the regex never matches any real CSS value, including100vh, and the strip step is effectively a no-op.Why this causes unbounded expansion
When the user puts
<iframe style="height:100vh">inside the Custom HTML block:100vhis not stripped (because of the broken regex).<iframe>resolves100vhagainst the sandbox iframe's current height.MutationObservermeasuresdocument.body.getBoundingClientRect()and posts the new height to the parent viapostMessage.heightattribute to that value.100vhresolves to a larger value → body grows → observer fires → parent grows the iframe again → infinite loop.That's what produces the "preview keeps expanding, editor becomes heavy, very tall scrollbar" behavior described in the issue.
Fix
Correct the regex (single backslash) and also accept decimal values like
50.5vh:With this in place,
100vhis correctly identified and stripped before the first measurement, the feedback loop is broken, and the preview settles at a stable height.Test steps
<iframe src="https://www.photopea.com" style="width:100%; height:100vh; border:0;"></iframe>Before: the block grows continuously, vertical scrollbar appears, editor becomes sluggish.
After: the preview renders at a stable, finite height with no runaway growth.
AI Summary Completed
Regex101 Test
Previous regex
Link - https://regex101.com/?regex=%5E%5C%5Cd%2B%28vw%7Cvh%7Csvw%7Clvw%7Cdvw%7Csvh%7Clvh%7Cdvh%7Cvi%7Csvi%7Clvi%7Cdvi%7Cvb%7Csvb%7Clvb%7Cdvb%7Cvmin%7Csvmin%7Clvmin%7Cdvmin%7Cvmax%7Csvmax%7Clvmax%7Cdvmax%29%24&testString=100vh%0A&flags=&flavor=pcre2&delimiter=%2F
New Regex
Link - https://regex101.com/?regex=%5E%5Cd%2B%28%3F%3A%5C.%5Cd%2B%29%3F%28vw%7Cvh%7Csvw%7Clvw%7Cdvw%7Csvh%7Clvh%7Cdvh%7Cvi%7Csvi%7Clvi%7Cdvi%7Cvb%7Csvb%7Clvb%7Cdvb%7Cvmin%7Csvmin%7Clvmin%7Cdvmin%7Cvmax%7Csvmax%7Clvmax%7Cdvmax%29%24%0A&testString=100vh%0A&flags=&flavor=pcre2&delimiter=%2F