Skip to content

Conversation

@lysyjan
Copy link
Contributor

@lysyjan lysyjan commented Jun 18, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes WOOPLUG-4675

  • A new functionality for the email editor when blocks are loaded by the supports.email property.
  • Moving constant with allowed blocks from the PHP package to the JS package.

Screenshots or screen recordings:

N/A

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Enable the email editor feature in WooCommerce > Settings > Advanced> Features
  2. Go to WooCommerce > Settings > Emails and open an email in the editor
  3. Verify allowed blocks in the email editor and it's funcionality

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@lysyjan lysyjan self-assigned this Jun 18, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

This change updates the email editor to determine supported blocks using a metadata flag (supports.email) rather than a static allow-list. JavaScript logic is added to mark and filter blocks based on this flag, and PHP code is refactored to remove the old allow-list mechanism. Documentation and settings handling are updated accordingly.

Changes

Files / Paths Change Summary
packages/js/email-editor/src/blocks/core/supported-blocks.ts Added setEmailBlockSupport function to mark allowed core blocks with supports.email: true during registration.
packages/js/email-editor/src/blocks/index.ts Calls setEmailBlockSupport in initBlocks and re-exports getAllowedBlockNames from utils.
packages/js/email-editor/src/blocks/utils.ts Added getAllowedBlockNames utility to return block names with supports.email: true.
packages/js/email-editor/src/editor.tsx Updates editor settings to set allowedBlockTypes using getAllowedBlockNames.
packages/js/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings
packages/php/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings
Changelog entries describing the switch to metadata-based block support and removal of PHP allow-list usage.
packages/php/email-editor/src/Engine/class-settings-controller.php Removed ALLOWED_BLOCK_TYPES constant and related code from settings; no longer sets allowedBlockTypes in settings array.
packages/php/email-editor/src/Engine/class-email-editor.php Added enqueue_admin_styles method and hooks to ensure block types and assets are registered on admin script enqueue.
packages/php/email-editor/src/Engine/Renderer/readme.md Updated documentation to instruct adding allowed blocks in the JS file instead of the PHP settings controller.
plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php Enhanced load_editor_assets to inject inline scripts setting block categories and preloading server-side block definitions.
plugins/woocommerce/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings Added changelog entry for loading block categories on the email editor page.

Poem

🐇 In fields of code where blocks align,
A flag named "email" now does shine.
From PHP’s lists we gently part,
To metadata’s clever art.
Blocks bloom where rabbits hop and play,
Supporting emails in a brand new way! 🌸✨


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ade49cb and 8a7ed8d.

📒 Files selected for processing (1)
  • plugins/woocommerce/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build
  • GitHub Check: Validate markdown
  • GitHub Check: Validate changelog
  • GitHub Check: Build Project Jobs
  • GitHub Check: Check Asset Sizes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lysyjan lysyjan force-pushed the wooplug-4675-load-supported-email-editor-blocks-from-supports-settings branch from 3e6e943 to 68c01ef Compare June 18, 2025 16:42
@lysyjan lysyjan marked this pull request as ready for review June 18, 2025 17:14
@github-actions
Copy link
Contributor

github-actions bot commented Jun 18, 2025

Size Change: +1.34 kB (+0.02%)

Total Size: 5.95 MB

Filename Size Change
./plugins/woocommerce/client/admin/build/email-editor/index.js 26.7 kB +150 B (+0.56%)
./plugins/woocommerce/client/admin/build/wp-admin-scripts/email-editor-integration.js 30.4 kB +144 B (+0.48%)
./packages/js/email-editor/build/blocks/core/supported-blocks.js 493 B +493 B (new file) 🆕
./packages/js/email-editor/build/blocks/utils.js 413 B +413 B (new file) 🆕

compressed-size-action

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/js/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1)

4-4: Fix typo in changelog description.

"alowed" should be "allowed".

-Add loading alowed blocks in the email editor by metadata `supports.email`.
+Add loading allowed blocks in the email editor by metadata `supports.email`.
packages/php/email-editor/src/Engine/class-email-editor.php (1)

101-101: Consider scoping the admin hook to relevant pages only.

The hook registration looks correct, but it will execute on every admin page. Consider adding a condition to only register this hook when the email editor is needed.

-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
+		if ( $this->is_email_editor_context() ) {
+			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
+		}

You would need to implement is_email_editor_context() to check if the current page requires email editor functionality.

packages/js/email-editor/src/blocks/utils.ts (1)

9-16: Consider improving type safety and error handling.

The implementation logic is correct, but there are opportunities for improvement:

  1. The @ts-expect-error comment indicates a type safety issue
  2. No error handling for getBlockTypes() failures
+interface BlockWithEmailSupport extends Block {
+	supports?: {
+		email?: boolean;
+		[key: string]: unknown;
+	};
+}
+
 export function getAllowedBlockNames(): string[] {
-	return getBlockTypes()
-		.filter( ( block: Block ) => {
-			// @ts-expect-error: 'email' is a custom property
-			return block.supports?.email === true;
-		} )
-		.map( ( block ) => block.name );
+	try {
+		return getBlockTypes()
+			.filter( ( block: BlockWithEmailSupport ) => {
+				return block.supports?.email === true;
+			} )
+			.map( ( block ) => block.name );
+	} catch ( error ) {
+		console.error( 'Failed to get allowed block names:', error );
+		return [];
+	}
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fb54e5 and 68c01ef.

📒 Files selected for processing (9)
  • packages/js/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1 hunks)
  • packages/js/email-editor/src/blocks/core/supported-blocks.ts (1 hunks)
  • packages/js/email-editor/src/blocks/index.ts (1 hunks)
  • packages/js/email-editor/src/blocks/utils.ts (1 hunks)
  • packages/js/email-editor/src/editor.tsx (2 hunks)
  • packages/php/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1 hunks)
  • packages/php/email-editor/src/Engine/Renderer/readme.md (1 hunks)
  • packages/php/email-editor/src/Engine/class-email-editor.php (2 hunks)
  • packages/php/email-editor/src/Engine/class-settings-controller.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Check Asset Sizes
🔇 Additional comments (10)
packages/php/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1)

1-4: LGTM!

The changelog entry accurately describes the removal of the static allowedBlockTypes configuration from PHP.

packages/js/email-editor/src/editor.tsx (2)

12-12: LGTM!

The import statement correctly includes getAllowedBlockNames to support the new dynamic block configuration.


36-37: Verify initialization order and consider immutable approach.

The logic correctly sets allowed block types dynamically. However, verify that:

  1. setEmailBlockSupport() is called before this component renders to ensure the metadata is available
  2. Consider if mutating the settings object directly could cause issues in React's reconciliation
#!/bin/bash
# Description: Verify that setEmailBlockSupport() is called before getAllowedBlockNames()
# Expected: setEmailBlockSupport should be called during initBlocks() which happens before editor renders

# Check the initialization order in the initialize function
rg -A 10 -B 5 "initBlocks.*getAllowedBlockNames" --type ts --type tsx
packages/php/email-editor/src/Engine/Renderer/readme.md (1)

7-7: LGTM!

The documentation correctly updates the path to reflect the new location where developers should add email block support.

packages/js/email-editor/src/blocks/index.ts (3)

30-30: LGTM!

The import correctly brings in the setEmailBlockSupport function for email block support initialization.


32-32: LGTM!

The export correctly makes getAllowedBlockNames available for use in other modules.


35-35: LGTM!

The function call is correctly placed at the beginning of initBlocks() to ensure email block support is registered before other initialization steps.

packages/php/email-editor/src/Engine/class-email-editor.php (1)

290-298: LGTM! Block editor assets loading is correctly implemented.

The method properly triggers the enqueue_block_editor_assets action to ensure block types are registered, which is essential for the new JavaScript-based block filtering approach.

packages/js/email-editor/src/blocks/core/supported-blocks.ts (1)

10-45: LGTM! Block support filtering is well implemented.

The filter approach correctly modifies block registration to add email support metadata. The list of allowed blocks is appropriate for email contexts.

Consider making the block list configurable or documented for easier maintenance:

+/**
+ * Core blocks that are supported in the email editor.
+ * This list should be updated when adding or removing email-compatible blocks.
+ */
 const ALLOWED_BLOCK_TYPES = new Set( [
packages/php/email-editor/src/Engine/class-settings-controller.php (1)

56-56: ```shell
#!/bin/bash

Search for usage of getAllowedBlockNames and allowedBlockTypes in TS/TSX files

rg -n "getAllowedBlockNames" --glob '.ts' --glob '.tsx' -A5 -B5
rg -n "allowedBlockTypes" --glob '.ts' --glob '.tsx' -A5 -B5


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@github-actions
Copy link
Contributor

github-actions bot commented Jun 18, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@lysyjan lysyjan force-pushed the wooplug-4675-load-supported-email-editor-blocks-from-supports-settings branch from 68c01ef to 6b5ab36 Compare June 19, 2025 14:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php (1)

150-155: Consider the implications of using unstable WordPress API.

While the implementation correctly follows WordPress core patterns, note that wp.blocks.unstable__bootstrapServerSideBlockDefinitions() is marked as unstable. This could potentially break in future WordPress versions.

Consider monitoring WordPress core updates for changes to this API or implementing a fallback mechanism. Also, for consistency with line 146, consider using sprintf() for string formatting:

-'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
+sprintf( 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions( %s );', wp_json_encode( get_block_editor_server_block_settings() ) )
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68c01ef and 6b5ab36.

📒 Files selected for processing (11)
  • packages/js/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1 hunks)
  • packages/js/email-editor/src/blocks/core/supported-blocks.ts (1 hunks)
  • packages/js/email-editor/src/blocks/index.ts (1 hunks)
  • packages/js/email-editor/src/blocks/utils.ts (1 hunks)
  • packages/js/email-editor/src/editor.tsx (2 hunks)
  • packages/php/email-editor/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1 hunks)
  • packages/php/email-editor/src/Engine/Renderer/readme.md (1 hunks)
  • packages/php/email-editor/src/Engine/class-email-editor.php (2 hunks)
  • packages/php/email-editor/src/Engine/class-settings-controller.php (1 hunks)
  • plugins/woocommerce/changelog/wooplug-4675-load-supported-email-editor-blocks-from-supports-settings (1 hunks)
  • plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php (1 hunks)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/js/email-editor/src/editor.tsx
  • packages/js/email-editor/src/blocks/index.ts
  • packages/php/email-editor/src/Engine/Renderer/readme.md
  • packages/php/email-editor/src/Engine/class-settings-controller.php
  • packages/js/email-editor/src/blocks/core/supported-blocks.ts
  • packages/js/email-editor/src/blocks/utils.ts
  • packages/php/email-editor/src/Engine/class-email-editor.php
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
  • GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: JavaScript - @woocommerce/admin-library [unit]
  • GitHub Check: PHP: 8.1 WP: latest [WP latest] - @woocommerce/email-editor-php-config [unit:php]
  • GitHub Check: Lint - @woocommerce/plugin-woocommerce
  • GitHub Check: Check Asset Sizes
  • GitHub Check: build
🔇 Additional comments (1)
plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php (1)

142-148: LGTM! Good implementation following WordPress core patterns.

The addition of block categories loading is well-implemented and follows the WordPress core approach. The comment with the GitHub reference is helpful for understanding the context and rationale.

@lysyjan lysyjan force-pushed the wooplug-4675-load-supported-email-editor-blocks-from-supports-settings branch from 6b5ab36 to d5527e8 Compare June 19, 2025 14:48
lysyjan added 7 commits June 19, 2025 17:00
The action enqueue_block_editor_assets loads enqueue scripts containing block from other plugins.
To eliminate warning about missing block categories, we need to add inline script to set categories.
To eliminate warning about missing block titles, we need to add inline script to set categories.
@lysyjan lysyjan force-pushed the wooplug-4675-load-supported-email-editor-blocks-from-supports-settings branch 2 times, most recently from ade49cb to 8fae3cf Compare June 19, 2025 15:03
@lysyjan lysyjan requested a review from costasovo June 19, 2025 15:23
@lysyjan lysyjan assigned costasovo and unassigned lysyjan Jun 19, 2025
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jun 19, 2025
@github-actions
Copy link
Contributor

Testing Guidelines

Hi @costasovo ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@costasovo costasovo added Ballade Issues related to block-based email editor package: @woocommerce/email-editor issues related to the @woocommerce/email-editor package labels Jun 20, 2025
Copy link
Contributor

@costasovo costasovo left a comment

Choose a reason for hiding this comment

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

@lysyjan Thank you for implementing the API!

I have one suggestion. Please see the other comment. Please note it is not a blocker and we can do it later with server-side render callbacks. I had that idea and wanted to ask for your thoughts.

I tested the editor and I can see all allowed core blocks are present.

Screenshot 2025-06-20 at 11 11 01

/**
* Set supports.email = true for the blocks that are supported in the block email editor.
*/
export function setEmailBlockSupport() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a suggestion here. I think it could be nicer if we moved this to PHP.
The reason is that would have it in one place.
I think we could do that in packages/php/email-editor/src/Integrations/Core/class-initializer.php

We could move the constant with the list of blocks there and add a filter:

add_filter( 'block_type_metadata', array( $this, 'allow_blocks' ) );

/**
* Allow blocks for the email editor.
*
* @param array $block_type_metadata Block type metadata.
*/
public function allow_blocks( array $block_type_metadata ): array {
if ( isset( $block_type_metadata['name'] ) && in_array( $block_type_metadata['name'], $this->allowed_blocks, true ) ) {
	if ( ! isset( $block_type_metadata['supports'] ) ) {
		$block_type_metadata['supports'] = array();
	}
	$block_type_metadata['supports']['email'] = true;
}
return $block_type_metadata;
}

But when I tried it I ran into an issue that some of the core blocks are registered very early. So we can't register the filter for block_type_metadata in Automattic\WooCommerce\EmailEditor\Initializer::initialize, but we have to do it earlier. It worked for me when I put it directly into Automattic\WooCommerce\EmailEditor\Bootstrap::init.

I think we will need to add rendering callbacks to the core blocks metadata anyway in PHP.

What do you think about moving it to PHP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While working on the second ticket, I had a similar idea.
I would merge this pull request and then refactor it.

@costasovo costasovo assigned lysyjan and unassigned costasovo Jun 20, 2025
@lysyjan lysyjan merged commit e93478f into trunk Jun 20, 2025
39 checks passed
@lysyjan lysyjan deleted the wooplug-4675-load-supported-email-editor-blocks-from-supports-settings branch June 20, 2025 12:43
@github-actions github-actions bot added this to the 10.1.0 milestone Jun 20, 2025
Kallyan01 pushed a commit to Kallyan01/woocommerce that referenced this pull request Jun 23, 2025
…e#58966)

* Add using the action `enqueue_block_editor_assets` to the email editor

The action enqueue_block_editor_assets loads enqueue scripts containing block from other plugins.

* Set allowed blockTypes dynamically instead of PHP constant

* Add a function setting called "supports.email" for supported blocks

* Update adding support for a block in readme

* Add changelogs

* Add loading block categories

To eliminate warning about missing block categories, we need to add inline script to set categories.

* Add loading server side block definitions

To eliminate warning about missing block titles, we need to add inline script to set categories.

* Add changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ballade Issues related to block-based email editor package: @woocommerce/email-editor issues related to the @woocommerce/email-editor package plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants