Skip to content

Preserve author selector semantics across native block save shapes#623

Merged
chubes4 merged 1 commit into
trunkfrom
fix/622-preserve-author-selector-semantics
Jul 18, 2026
Merged

Preserve author selector semantics across native block save shapes#623
chubes4 merged 1 commit into
trunkfrom
fix/622-preserve-author-selector-semantics

Conversation

@chubes4

@chubes4 chubes4 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add reusable CSS stylesheet traversal, selector tokenization, and conservative DOM matching primitives
  • preserve source paragraph selector ownership when phrasing elements become native Paragraph blocks
  • project source anchor/button selectors onto canonical core/button interactive controls exactly once
  • rewrite inline and linked stylesheet assets in place while preserving source order, repeated occurrences, media/type conditions, and source hashes
  • add deterministic coverage for selector grammar, specificity, wrapper-driven buttons, artifact ordering, collisions, and materialization metadata

Fixes #622.

Root cause

Blocks Engine retained author CSS byte-for-byte while native Gutenberg conversion changed DOM save shapes. Source span elements promoted to Paragraph blocks gained generated p wrappers that began matching source paragraph selectors. Source button anchors became an outer .wp-block-button plus inner .wp-block-button__link, allowing source class CSS and native style support to apply box geometry twice.

The production artifact path also extracted author styles into manifest assets and skipped HtmlTransformer stylesheet materialization, so selector projection had to replace each normalized CSS asset in place rather than append a duplicate stylesheet.

Compatibility

This intentionally changes generated block classes and author stylesheet bytes when a supported source selector would otherwise target the wrong Gutenberg save-shape element. Accidental matches against generated Paragraph/button wrappers are corrected to preserve source DOM behavior.

Artifacts with multiple inline styles or repeated linked stylesheets may gain deterministic occurrence asset paths so source cascade order is retained. Stylesheet media metadata now flows through the materialization plan. Output hash describes rewritten bytes while source_hash retains the original asset hash. Unsupported selector grammar remains byte-preserved rather than partially rewritten.

Existing native block validity and zero-core/html behavior are retained. Consumers that depended on accidental generated-wrapper matches or previously collapsed stylesheet occurrences should review this output change.

How to test

  1. From a fresh checkout, run cd php-transformer && composer install --no-interaction.
  2. Run composer test.
  3. Confirm the CSS stylesheet, selector matcher, author selector semantics, and artifact stylesheet projection unit suites pass.
  4. Confirm all 242 parity fixtures pass.
  5. Inspect html-author-selector-provenance and verify source p selectors target only blocks originating from source paragraphs.
  6. Inspect html-wrapper-button-selector-projection and verify wrapper-driven source button selectors target .wp-block-button__link once.
  7. Inspect the artifact selector projection and stylesheet occurrence fixtures; verify inline/linked paths remain ordered, repeated links retain their cascade position, media metadata reaches the materialization plan, output hashes match rewritten bytes, and source hashes match original bytes.

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode with OpenAI gpt-5.6-sol; Homeboy control-plane recovery was attempted
  • Used for: Root-cause analysis, implementation, parser and matcher primitives, regression coverage, iterative code review, and verification.

@chubes4
chubes4 merged commit a5a77a7 into trunk Jul 18, 2026
1 check passed
@chubes4
chubes4 deleted the fix/622-preserve-author-selector-semantics branch July 18, 2026 12:37
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.

Preserve author CSS selector semantics across native block save shapes

1 participant