Skip to content

fix: render synced patterns inside Group blocks in newsletters#2069

Open
jason10lee wants to merge 8 commits intotrunkfrom
fix/reusable-block-in-group
Open

fix: render synced patterns inside Group blocks in newsletters#2069
jason10lee wants to merge 8 commits intotrunkfrom
fix/reusable-block-in-group

Conversation

@jason10lee
Copy link
Copy Markdown
Contributor

@jason10lee jason10lee commented Apr 7, 2026

Changes proposed

Synced patterns (reusable blocks / core/block) placed inside Group blocks were silently stripped from newsletter email output. This happened because:

  1. is_empty_block() treated core/block as empty (it has no innerHTML — content lives in a referenced wp_block post). This is similar to a pattern that prevented Remote Data Blocks from rendering on send.
  2. render_mjml_component() had no handler for core/block — resolution only happened at the top level in post_to_mjml_components()

This PR extracts the reusable block resolution into a shared resolve_reusable_block() method used by both code paths, with additional hardening:

  • Post validation — checks post_type === 'wp_block' and post_status === 'publish' (previously unchecked)
  • Circular reference guard — static stack prevents infinite recursion if patterns reference each other
  • Filter consistency — uses get_valid_post_blocks() so the newspack_newsletters_newsletter_content filter is applied to nested patterns, matching top-level behavior
  • Stale ref handling — deleted/invalid refs return empty instead of rendering empty wrapper markup

Resolves NPPM-2610: Bug: Some Patterns don't display in sent Newsletters when placed inside of a "Group" block

How to test

  1. Create a synced pattern containing a Heading and a Paragraph block
  2. Create a newsletter, add a Group block, insert the synced pattern inside it
  3. Preview the newsletter — the pattern content should appear in the email output
  4. Also verify: a top-level synced pattern (not in a group) still renders correctly

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes newsletter MJML rendering so synced patterns (core/block / reusable blocks) render correctly when nested inside core/group blocks, adding safer reusable-block resolution behavior.

Changes:

  • Add shared reusable-block resolution with wp_block validation and circular-reference protection.
  • Teach render_mjml_component() to handle core/block (not just top-level conversion).
  • Add PHPUnit coverage for nested reusable blocks, stale refs, and circular refs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
includes/class-newspack-newsletters-renderer.php Adds core/block rendering support via resolve_reusable_block(), circular guard stack, and resets stack per render.
tests/test-renderer.php Adds regression tests covering nested synced patterns, stale refs, and circular references.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/class-newspack-newsletters-renderer.php Outdated
Comment thread includes/class-newspack-newsletters-renderer.php
@jason10lee jason10lee marked this pull request as ready for review April 7, 2026 15:34
@jason10lee jason10lee requested a review from a team as a code owner April 7, 2026 15: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.

2 participants