Skip to content

Custom HTML: Ensure the block is always visible - #82895

Closed
alecgeatches wants to merge 3 commits into
trunkfrom
fix/empty-embed-preview
Closed

alecgeatches wants to merge 3 commits into
trunkfrom
fix/empty-embed-preview

Conversation

@alecgeatches

@alecgeatches alecgeatches commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

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?

  • Adds min-height: $grid-unit-50 (40px) to the .block-library-html__edit wrapper, roughly the height of the old single-line code textarea. Blocks with taller content are unaffected. Adds a test for this.

Testing Instructions

  1. Create a new post and insert a Custom HTML block.

  2. Click Edit HTML, click the "JavaScript" tab, then enter console.log( 'test' );, and click Update.

  3. 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
  4. Enter HTML content (e.g. <p>Hello</p>) instead and confirm the block HTML is rendered.

Testing Instructions for Keyboard

  1. With the script-only block in the post, with blocks before and after, use the arrow keys to move between blocks and confirm the Custom HTML block can be reached and shows its toolbar.

Use of AI Tools

Tool(s): Claude Code

@alecgeatches alecgeatches self-assigned this Sep 14, 2026
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: room34 <room34@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: joedolson <joedolson@git.wordpress.org>
Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: prachigarg19 <prachigarg19@git.wordpress.org>
Co-authored-by: cbirdsong <cbirdsong@git.wordpress.org>
Co-authored-by: MadtownLems <madtownlems@git.wordpress.org>

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 props-bot label to refresh.

📦 Bundle size

Size Change: +74 B (0%)

Total Size: 8.29 MB

📦 View Changed
Filename Size Change
build/styles/block-library/editor-rtl.css 12.6 kB +6 B (+0.05%)
build/styles/block-library/editor-rtl.min.css 10.3 kB +9 B (+0.09%)
build/styles/block-library/editor.css 12.6 kB +12 B (+0.1%)
build/styles/block-library/editor.min.css 10.3 kB +9 B (+0.09%)
build/styles/block-library/html/editor-rtl.css 1.43 kB +9 B (+0.63%)
build/styles/block-library/html/editor-rtl.min.css 503 B +8 B (+1.62%)
build/styles/block-library/html/editor.css 1.44 kB +13 B (+0.91%)
build/styles/block-library/html/editor.min.css 503 B +8 B (+1.62%)

12db581 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 817e49c trunk % Change
timeToFirstByte 49.65 ms +10.47% -1.81% 50.55 ms +10.48% -3.96% -1.78%
largestContentfulPaint 86 ms +6.98% -4.65% 88 ms +4.55% -4.55% -2.27%
lcpMinusTtfb 34.4 ms +6.1% -6.1% 34.2 ms +7.16% -4.09% 0.58%
wpBeforeTemplate 23.55 ms +10.11% -1.7% 24.08 ms +5.77% -4.9% -2.2%
wpTemplate 22.49 ms +4.27% -4% 22.79 ms +3.69% -4.74% -1.32%
wpTotal 45.98 ms +9.53% -2.22% 46.62 ms +9.74% -3.17% -1.37%
wpMemoryUsage 7.65 MB +0% -0% 7.62 MB +0% -0% 0.45%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric 817e49c trunk % Change
timeToFirstByte 40.4 ms +2.23% -1.98% 36.55 ms +9.17% -1.64% 10.53%
largestContentfulPaint 92 ms +6.52% -0% 84 ms +7.14% -4.76% 9.52%
lcpMinusTtfb 52.65 ms +3.04% -2.56% 46.25 ms +10.05% -5.3% 13.84%
wpBeforeTemplate 20.47 ms +3.76% -0.88% 20.79 ms +8.13% -0.77% -1.54%
wpTemplate 16.58 ms +3.5% -1.87% 12.76 ms +15.52% -3.61% 29.94%
wpTotal 37.31 ms +2.6% -1.82% 33.58 ms +9.2% -1.31% 11.11%
wpMemoryUsage 6.28 MB +0% -0% 6.10 MB +0% -0% 2.9%
wpDbQueries 14 +0% -0% 10 +0% -0% 40%

media-processing

Metric 817e49c trunk % Change
mediaProcessingJpeg 389.15 ms +0.28% -0.92% 384.54 ms +0.36% -2.23% 1.2%
mediaProcessingAvif 5626.21 ms +0.11% -0.23% 5607.21 ms +0.26% -0.11% 0.34%
mediaProcessingJpegToAvif 3838.05 ms +0.07% -0.28% 3831.96 ms +0.45% -0.18% 0.16%

media-upload

Metric 817e49c trunk % Change
jpegUploadProcessing 1444.91 ms +32.77% -1.89% 1432.4 ms +0.91% -1.24% 0.87%
pngUploadProcessing 203.23 ms +8.07% -5.3% 205.97 ms +12.22% -2.29% -1.33%
largeJpegUploadProcessing 1415.85 ms +0.46% -0.91% 1406.15 ms +0.87% -0.4% 0.69%
multipleImageUploadProcessing 1544.24 ms +0.52% -1.02% 1530.74 ms +1.35% -1.12% 0.88%

post-editor

Metric 817e49c trunk % Change
serverResponse 394.97 ms +7.21% -3.23% 421.02 ms +3.37% -8.18% -6.19%
firstPaint 234.2 ms +29.29% -13.36% 244.03 ms +9.39% -14.2% -4.03%
domContentLoaded 1078.88 ms +0.86% -1.23% 1100.81 ms +2.69% -2.07% -1.99%
loaded 1080.27 ms +0.85% -1.26% 1102.18 ms +2.68% -2.07% -1.99%
firstContentfulPaint 450.3 ms +3.06% -0.9% 465.66 ms +3.33% -9.84% -3.3%
firstBlock 3212.13 ms +1.17% -1.51% 3230.93 ms +1.18% -1.43% -0.58%
type 18.63 ms +4.08% -1.99% 19.12 ms +5.49% -1.94% -2.56%
typeWithoutInspector 18.22 ms +5.6% -2.31% 19.21 ms +4.69% -5.57% -5.15%
typeWithTopToolbar 24.92 ms +5.9% -6.22% 24.06 ms +2.33% -5.2% 3.57%
typeContainer 8.55 ms +11.93% -4.91% 8.7 ms +5.4% -4.6% -1.72%
focus 116.83 ms +4.66% -2.56% 116.7 ms +6.32% -3.7% 0.11%
firstFocus 219.2 ms +0% -0% 238.5 ms +0% -0% -8.09%
selectAll 538.42 ms +3.33% -2.01% 544.36 ms +1.39% -3.43% -1.09%
listViewOpen 77.11 ms +9.22% -5.33% 80.81 ms +6.94% -4.24% -4.58%
inserterOpen 42.4 ms +9.2% -9.67% 43.55 ms +3.61% -8.98% -2.64%
inserterHover 12.58 ms +6.84% -7.79% 13.09 ms +5.12% -9.85% -3.9%
inserterSearch 9.31 ms +2.69% -4.08% 8.8 ms +7.16% -7.61% 5.8%
loadPatterns 638 ms +7.64% -3.4% 655.41 ms +10.07% -5.68% -2.66%
wpTotal 383.74 ms +7.42% -3.19% 409.98 ms +3.04% -8.34% -6.4%
wpMemoryUsage 13.21 MB +0% -0% 13.17 MB +0% -0% 0.28%
wpDbQueries 54 +0% -1.85% 54 +0% -1.85% 0%

site-editor

Metric 817e49c trunk % Change
serverResponse 513.17 ms +3.43% -5.43% 503.98 ms +4.07% -7.13% 1.82%
firstPaint 273.02 ms +11.07% -8.42% 267.36 ms +9.32% -9.06% 2.12%
domContentLoaded 1187.65 ms +2.96% -1.14% 1180.5 ms +1.91% -0.88% 0.61%
loaded 1188.96 ms +2.97% -1.15% 1181.75 ms +1.92% -0.87% 0.61%
firstContentfulPaint 470.85 ms +2.54% -1.96% 470.26 ms +1.06% -1.31% 0.13%
firstBlock 4459.43 ms +0.44% -0.87% 4411.62 ms +0.77% -0.53% 1.08%
type 19.47 ms +10.37% -5.08% 18.99 ms +4.27% -4% 2.53%
navigate 119.85 ms +2.24% -4.81% 124.82 ms +9.77% -6.67% -3.98%
loadPatterns 1292.75 ms +8.04% -4.09% 1322.82 ms +6.01% -3.25% -2.27%
loadPages 1025.04 ms +1.29% -1.12% 1035 ms +0.33% -0.91% -0.96%
wpTotal 503.46 ms +3.43% -5.45% 493.98 ms +4.16% -7.27% 1.92%
wpMemoryUsage 12.25 MB +0% -0% 12.21 MB +0% -0% 0.3%
wpDbQueries 43 +2.33% -0% 43 +2.33% -0% 0%

12db581 Run

🏁 Flaky tests

Some 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 /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → GET http://localhost:8889/wp-json/wp/v2/blocks?per_page=100&status=publish%2Cfuture%2Cdraft%2Cpending%2Cprivate%2Ctrash
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.21 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: 494e3e4684
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1791498080%7CzYwwGOAzaaNs9wVehBKuII73phNq8p7btQNYnLrp6Ts%7Cc24badc436d6ae1006d3b1997eab3f312df9bc5b146e9c4644bfac05ca025c43; wp-settings-time-1=1791325281

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:112:39)
    at RequestUtils.deleteAllBlocks (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/blocks.ts:23:28)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:11:22

12db581 Run

@alecgeatches alecgeatches mentioned this pull request Sep 14, 2026
4 of 6 tasks
@alecgeatches
alecgeatches requested a review from aduth September 14, 2026 21:42
@aduth

aduth commented Sep 15, 2026

Copy link
Copy Markdown
Member

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.

@aduth

aduth commented Sep 15, 2026

Copy link
Copy Markdown
Member

It also has me thinking about how we present other, similar types of "empty" blocks.

Spacer is a good example.

By default, it presents similar to what you've proposed here, just a blank area where the block is:

image

But when it's hovered, there's more distinct styling to show that a block exists:

image

I don't know that it's necessarily "better", but it feels like a similar sort of thing where we might want to be consistent.

@aduth aduth added the Needs Design Feedback Needs general design feedback. label Sep 15, 2026
@alecgeatches

alecgeatches commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

It also has me thinking about how we present other, similar types of "empty" blocks.

Spacer is a good example.

...when it's hovered, there's more distinct styling to show that a block exists:
image

I like this better than a blank area! However, it's tricky with the custom HTML block. Normally we want to preview the contents of the HTML block as rendered, and not with an overlay. It's hard to tell if arbitrary code will render as an empty box or have actual visual contents. We could use a heuristic based on contents, but we may sometimes show that overlay on top of preview content when we're wrong. Maybe a border state or subtle overlay color that's always present, and doesn't majorly affect preview contents, could work.

If there's no easy design fix, I hope this PR roughly as-is can be merged to fix the major issue of invisible blocks first.

@alecgeatches alecgeatches added the [Type] Bug An existing feature does not function as intended label Sep 15, 2026
@youknowriad

Copy link
Copy Markdown
Contributor

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?

@aduth

aduth commented Sep 16, 2026

Copy link
Copy Markdown
Member

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 :empty pseudo-selector or component logic to detect if there's meaningful content in the block (:empty unfortunately doesn't appear to work the way we want it to here, though). Perhaps even reusing some of the block's own internal handling for splitting HTML, CSS, and JavaScript.

@youknowriad

Copy link
Copy Markdown
Contributor

In that situation, I imagine the worst-case would be there's a bit of unnecessary padding toward the bottom of the block?

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.

@aduth

aduth commented Sep 16, 2026

Copy link
Copy Markdown
Member

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 parseContent, though I gather that would only detect JavaScript and CSS added after #73108 that have the special data- attributes. That could be enough for a first pass, or otherwise we could do some basic HTML querying to see what kind of contents the block contains and whether they'd be expected to show something meaningful.

@youknowriad

Copy link
Copy Markdown
Contributor

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)

@room34

room34 commented Sep 16, 2026 •

Copy link
Copy Markdown

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...

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 <script> tag for pulling in the third-party JavaScript, and an empty <div> that the JavaScript is inserting the form into.

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.

@aduth

aduth commented Sep 16, 2026

Copy link
Copy Markdown
Member

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 😅

@alecgeatches

alecgeatches commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

@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!

@youknowriad

Copy link
Copy Markdown
Contributor

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

@youknowriad

Copy link
Copy Markdown
Contributor

Closing this one as we merged the alternative.

@youknowriad youknowriad closed this Oct 7, 2026
@youknowriad
youknowriad deleted the fix/empty-embed-preview branch October 7, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Design Feedback Needs general design feedback. [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom HTML Block: always show SOMETHING in the editor

4 participants