Repository navigation
Custom HTML: Ensure the block is always visible - #82895
alecgeatches wants to merge 3 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf 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. Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +74 B (0%) Total Size: 8.29 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. last-inserted block should be given and keep the selection (small viewport) in
|
|
Nice work here! And thanks for tracking down that history. I was actually unaware of #73108 being a more recent change leading to the issues being discussed in #80843 and #78576. This feels like a pretty reasonable minimal fix to at least allow the block to occupy some space, even when its contents are invisible. Since it's still not super-obvious that there's a block there, I imagine there might be a bigger redesign we could explore with how the block is presented given various contents. But I think the changes proposed here would be at least an incremental improvement. I'd be curious to get some feedback from @youknowriad @mtias as having been involved in the original effort in #73108 and how they might have considered handling invisible content like this. |
|
Personally, I'm wondering if this breaks some expectations. Like what if the HTML block is used to render some small SVG elements or something that are smaller than the minimum height proposed here? |
|
In that situation, I imagine the worst-case would be there's a bit of unnecessary padding toward the bottom of the block? It'd be nice if we could do something like an |
But which is worse is the question. IMO with agents generating HTML blocks, it's kind of common to have small HTML blocks. This is in fact one of the main reasons we switched the default to preview as otherwise a lot of sites felt broken in the editor. |
|
It does feel like a bulk of what I'm seeing in the discussion in #80843 and #78576 revolves around HTML blocks containing only CSS or JavaScript and not HTML, so maybe the simplest improvement is to at least check for that in determining whether to show some placeholder or default minimum height. We could use the block's existing |
|
Yeah, sounds good to me, actually even wonder if we should some something special for these HTML blocks, might some kind of floating elements to avoid messing with the surroundings. (The dreamweaver "php" blocks come to my mind haha) |
I'd just like to clarify something about this for the specific scenarios where I'm encountering this as a problem. One of my clients' most common use cases for a Custom HTML block are when they need to embed an external form, e.g. a donation form. There's not anything going into the CSS or JavaScript tabs in this situation. There's a So… it's only HTML, but there's nothing visibly displayed until the JavaScript loads. I'm not sure how best to check for something like this; I just think it's important to recognize that the problem I, at least, am hoping to solve here would not be solved by a simple check that there's nothing in the HTML tab. |
|
Thanks for sharing your real-world example @room34 . I agree that's both harder to account for, and not covered by what I proposed in #82895 (comment) . Another option could be to measure the preview after it renders and show something if there's not any height of its own. There's some complexity here around asynchronous preview rendering and race-conditions like what #78576 was originally highlighting and #78582 was trying to address. I don't necessarily want to lose sight of the original proposal here either. It's got a few drawbacks as already discussed, but one thing it's certainly got going for it is its simplicity 😅 |
|
@aduth @youknowriad Any chance I could get a sign-off for this dangling issue? We still have reports coming in for hidden HTML blocks, and as @room34 comments above there's not going to be a simple way to detect when content will be visible. I'm all for a more complex solution if one is available, but for today I think this solves the major invisible block issue causing confusion for users. A later PR with a more nuanced fix is always an option. Alternatively, please tag me on another PR if you have a solution in mind you'd prefer and I'd be happy to test and review. Thanks! |
|
Hey @alecgeatches here's the alternative I was thinking about #84150, we may want to get a designer's eye on it though but let me know what you think |
|
Closing this one as we merged the alternative. |



What?
Closes #80843 and #78576.
Gives the custom HTML block a minimum height so it stays visible and clickable when its content has no visible output.
Why?
In WordPress 6.9, the custom HTML block had an in-editor preview and code editor mode, which ensured it always occupied some visual space:
script-tag-6.9.mov
Since #73108, the canvas only shows the rendered output of the block, with the code editor moving to a modal. This causes custom HTML content with no direct output (e.g. a
<script>tag) to render empty:script-tag-7.1.mov
Users can't see the block or click it directly, and can only find it through the List View.
How?
min-height: $grid-unit-50(40px) to the.block-library-html__editwrapper, roughly the height of the old single-line code textarea. Blocks with taller content are unaffected. Adds a test for this.Testing Instructions
Create a new post and insert a Custom HTML block.
Click Edit HTML, click the "JavaScript" tab, then enter
console.log( 'test' );, and click Update.On trunk, the block disappears from the canvas. On this branch, it keeps a 40px area that shows the block outline on hover and can be clicked to select the block:
always-visible-html-preview.mov
Enter HTML content (e.g.
<p>Hello</p>) instead and confirm the block HTML is rendered.Testing Instructions for Keyboard
Use of AI Tools
Tool(s): Claude Code