Custom HTML: show placeholder when block renders no visible HTML content - #80934
Custom HTML: show placeholder when block renders no visible HTML content#80934himanshupathak95 wants to merge 6 commits into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
What?
Closes #80843
When a Custom HTML block contains only JavaScript or CSS, with no visible HTML markup, and the editor canvas collapses the block to zero height. The block saves and renders correctly on the frontend, but is completely invisible in the editor: only a detached toolbar badge indicates it exists. Multiple such blocks on a page produce a blank editing experience.
Why?
The redesign stores JS as <script data-wp-block-html="js"> and CSS as <style data-wp-block-html="css"> inside the block's inner content. When painting the canvas, InnerContent passes all markup, which strips <script> tags. A JS-only block then has nothing to inject into the DOM, gets a height of zero, and collapses silently.
How?
Adds a new early-return branch in HTMLEdit between the existing empty-content check and the normal InnerContent render:
parseContent(content).The block content is not modified. Only the editor-side visual representation changes.
Testing Instructions
Screenshots or screencast
Before
Screen.Recording.2026-07-30.at.16.25.26.mov
After
Screen.Recording.2026-07-30.at.16.22.11.mov
Screen.Recording.2026-07-30.at.16.22.33.mov