Skip to content

Support the innerContent-based Custom HTML block - #214

Merged
t-hamano merged 6 commits into
mainfrom
fix/custom-html-inner-content-support
Jul 19, 2026
Merged

t-hamano merged 6 commits into
mainfrom
fix/custom-html-inner-content-support

Conversation

@t-hamano

@t-hamano t-hamano commented Jul 18, 2026 •

Copy link
Copy Markdown
Owner

Fixes #210

Since Gutenberg #79115 (WordPress 7.1), the core Custom HTML block stores its markup in innerContent instead of the content attribute, and save() returns null. Because this plugin fully overrides the block's Edit component and still read/wrote attributes.content via setAttributes, the block content could no longer be updated on 7.1.

The plugin needs to keep supporting WordPress 7.0, so the Edit component is split in two and selected at registration time by inspecting the content attribute definition.

Once the minimum supported version reaches 7.1, edit-legacy.tsx can be removed.

Since Gutenberg PR #79115 (WP 7.1) the core/html block stores its markup
in `innerContent` instead of the `content` attribute, so the existing Edit
component could no longer update the block content.

Add an innerContent-based Edit component that reads content via
`getBlockContent` and writes it via `updateBlock`/`replaceInnerBlocks`, and
switch between it and the legacy Edit by inspecting the `content` attribute
definition (`role: 'local'` vs `source: 'raw'`).

Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano t-hamano changed the title Support the innerContent-based Custom HTML block (WordPress 7.1) Support the innerContent-based Custom HTML block Jul 18, 2026
t-hamano and others added 5 commits July 19, 2026 01:05
On WordPress 7.1 a Custom HTML block can contain `<!-- wp:* -->` inner
blocks. Show them as editable blocks in preview mode via the block-editor
`InnerContent` private API, so they can be edited in place instead of being
rendered as inert serialized HTML. Plain HTML (no inner blocks) still uses
the sandboxed render to keep the live CSS/JS preview.

Also show a placeholder in preview mode when the block has no content,
instead of an empty sandbox iframe.

Co-Authored-By: Claude <noreply@anthropic.com>
Core stopped wrapping block previews in the `Disabled` component and removed
its use from the Custom HTML block in #73108, standardizing on the
`isPreviewMode` editor setting. `Disabled.Consumer` only covers the
auto-height block preview, so post/template previews and zoom-out would still
mount the heavy Monaco editor. Read `getSettings().isPreviewMode` instead to
cover every preview path and drop the `Disabled` dependency.

Also list `clientId` and `updateBlock` in the migration effect's deps (both
are stable) instead of suppressing the exhaustive-deps lint.

Co-Authored-By: Claude <noreply@anthropic.com>
Align with core, which renders the Custom HTML block through `InnerContent`
alone. The sandboxed live CSS/JS preview and its `hasInnerBlocks` branch are
no longer needed, so drop `SandBox`, the editor-style injection, and the
preview overlay. Preview mode now always renders `InnerContent`, matching the
editor canvas.

Also merge the two `useSelect` calls into one and inline the private-API
unlock.

Co-Authored-By: Claude <noreply@anthropic.com>
The namespace import lacked a privateApis type, forcing an `as unknown as`
double cast to reach it. Augment the package types with a `privateApis`
declaration so `unlock()` can consume it directly.

Co-Authored-By: Claude <noreply@anthropic.com>
edit.tsx imports __dangerousOptInToUnstableAPIsOnlyForCoreModules directly
from @wordpress/private-apis, but the package was only resolved transitively
via @wordpress/block-editor. Declare it explicitly to avoid relying on a
phantom dependency that could break under stricter package managers or if
block-editor drops it.

Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano
t-hamano marked this pull request as ready for review July 19, 2026 06:34
@t-hamano
t-hamano merged commit 83b5848 into main Jul 19, 2026
8 checks passed
@t-hamano
t-hamano deleted the fix/custom-html-inner-content-support branch July 19, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

innerContentサポートの動作確認

1 participant