Skip to content

fix: preserve explicit HTML fragments in native intent - #194

Merged
noeltock merged 2 commits into
mainfrom
block-theme/html-fragments
Oct 12, 2026
Merged

noeltock merged 2 commits into
mainfrom
block-theme/html-fragments

Conversation

@noeltock

@noeltock noeltock commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Problem

Explicit Custom HTML in native intent silently becomes an empty block on WordPress 7.1. Its content attribute is local to the editor; serialization now reads innerContent. Small authored SVG and form fragments therefore disappear even though validation reports success.

Solution

Reuse the converter's existing HTML construction helper for intent core/html. Preserve supplied attributes and dropped-attribute diagnostics, keep text precedence, and reject non-string content. Converter fallback behavior remains unchanged.

Behaviour that changes or must stay true Read first Proof
Explicit fragment bytes survive intent serialization src/intent/index.ts SVG/form regression through assemble, realize, parse and validate
Native block metadata and diagnostics remain visible createHtmlFallback and intent constructor Metadata and dropped-attribute assertions
Converter fallback still warns and refuses strict conversion src/convert/fallback.ts Cross-producer fragment checks

Diff

3 files, +60 / -6.

 assembleNode(core/html)
- generic createBlock('core/html', attrs, [])
+ validate consumed string content
+ createHtmlFallback(wp, content, attrs)
 createHtmlFallback
+ optional attrs forwarded to createBlock
  existing innerContent/originalContent payload retained
+ SVG/form cross-producer regression; malformed content rejection

Testing & verification

Reviewed revision: d3f6293e97ea2dd36b5611abb1ad966cbe60eebb · Environment: Node 22 locally; WordPress 7.1 / PHP 8.4 in OrbStack.

  • npm test -- dev/test/intent.test.ts dev/test/convert.test.ts dev/test/coverage.test.ts: 95 passed.

  • npm run typecheck, npm run build, npm run check:private, git diff --check: passed.

  • Actual general CLI apply updated a native page containing both localized fragments, with successful full field readback. A real page editor edit, Save and reopen retained both SVG/form fragments with zero invalid blocks; restoring the edit returned exactly to compiled content. Native theme files also saved byte-for-byte unchanged.

  • Converter selection and existing fallback behavior are unchanged; this does not add a conversion rule or change benchmark scores.

  • Exact-head CI 38301931599: Node 22.13/24, package-boundary, WordPress proof and CI scope passed.

Not verified: no production apply or release. The large-mutation transport fix in #193 is already merged.

Risk / rollout

Callers that explicitly supply non-string Custom HTML content now get a clear failure instead of silent empty output. Detection: exact payload roundtrip checks and visible live fragments. Rollback: revert these three files; that reintroduces silent intent fragment loss and does not undo WordPress writes.

Base automatically changed from block-theme/site-apply-stdin to main October 12, 2026 20:11
@noeltock
noeltock merged commit 2d8cc11 into main Oct 12, 2026
8 checks passed
@noeltock
noeltock deleted the block-theme/html-fragments branch October 12, 2026 20:34
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.

1 participant