Repository navigation
Support the innerContent-based Custom HTML block - #214
Merged
Merged
Conversation
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>
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>
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.
Fixes #210
Since Gutenberg #79115 (WordPress 7.1), the core Custom HTML block stores its markup in
innerContentinstead of thecontentattribute, andsave()returnsnull. Because this plugin fully overrides the block's Edit component and still read/wroteattributes.contentviasetAttributes, 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
contentattribute definition.Once the minimum supported version reaches 7.1,
edit-legacy.tsxcan be removed.