Skip to content

Refactor theme image block and improve HTML processing#23

Merged
jeremyfelt merged 3 commits into
trunkfrom
claude/code-audit-fixes-2b1CW
Feb 20, 2026
Merged

Refactor theme image block and improve HTML processing#23
jeremyfelt merged 3 commits into
trunkfrom
claude/code-audit-fixes-2b1CW

Conversation

@jeremyfelt
Copy link
Copy Markdown
Member

Summary

This PR refactors the theme image block to improve code quality, fix bugs, and enhance maintainability. Changes include optimizing HTML tag processing logic, fixing variable references, improving accessibility handling, and correcting the textdomain configuration.

Key Changes

  • HTML Processing Optimization: Moved WP_HTML_Tag_Processor instantiation inside the if ( $link_url ) conditional to avoid unnecessary processing when no link URL is present. Simplified the logic by removing redundant processor instantiation and directly using the updated HTML content.

  • Wrapper Attributes Handling: Changed wrapper attributes to only include the class attribute when $wrapper_classes is not empty, preventing empty class attributes in the rendered output.

  • Variable Reference Fixes: Corrected references from happyprimeData to happyprime_themeimageblock_data to use the properly localized data object throughout the JavaScript component.

  • Textdomain Correction: Updated block.json textdomain from "happyprime" to "theme-image-block" for proper translation domain alignment.

  • Block Reference Management: Introduced useRef hook to track the block element, replacing direct DOM queries with document.querySelector() for more reliable anchor positioning in the link editor popover.

  • Alt Text Handling: Refactored alt text logic to properly respect the omitAltText attribute, computing the alt text value once and using it consistently in the image element.

  • Code Cleanup: Removed unnecessary conditional logic for default width styling in the editor preview, simplifying the styles computation.

Notable Implementation Details

  • The HTML tag processor refactoring reduces unnecessary DOM operations and makes the code flow more logical by keeping related operations together.
  • Using useRef for DOM element tracking is more reliable than querying by class name, which could be fragile if class names change.
  • The alt text refactoring ensures that when omitAltText is true, an empty string is used instead of falling back to default text.

https://claude.ai/code/session_011559Dfm5rxu8GGfejrzy5c

claude and others added 3 commits February 19, 2026 13:50
…ption, alt text, popover anchor

- Fix critical bug: `happyprimeData` references changed to correct
  `happyprime_themeimageblock_data` variable name (broke all editor previews)
- Fix textdomain in block.json from `happyprime` to `theme-image-block`
  to match plugin Text Domain and enable proper i18n
- Fix link processing in Block.php to only search for <a> tags when a
  link URL is set, preventing corruption of SVGs containing <a> elements
- Fix editor alt text to respect altText and omitAltText attributes,
  matching the PHP render behavior
- Fix Popover anchor using useRef instead of document.querySelector to
  target the correct block instance when multiple blocks exist
- Remove forced width:100% on inline SVGs in editor that didn't match
  frontend rendering
- Avoid passing empty class attribute to get_block_wrapper_attributes

https://claude.ai/code/session_011559Dfm5rxu8GGfejrzy5c
The <figure> element had both dangerouslySetInnerHTML (for inline SVG
without a link) and JSX children (content + caption RichText), which
React forbids. Render the SVG inside a display:contents span instead,
keeping it as a normal child of the figure.

https://claude.ai/code/session_011559Dfm5rxu8GGfejrzy5c
@jeremyfelt jeremyfelt merged commit 5516018 into trunk Feb 20, 2026
5 checks passed
@jeremyfelt jeremyfelt deleted the claude/code-audit-fixes-2b1CW branch February 20, 2026 17:48
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.

2 participants