close
Skip to content

Block Comments: Add blockComment block support#71847

Closed
karthick-murugan wants to merge 3 commits intoWordPress:trunkfrom
karthick-murugan:blockcomment-block-support
Closed

Block Comments: Add blockComment block support#71847
karthick-murugan wants to merge 3 commits intoWordPress:trunkfrom
karthick-murugan:blockcomment-block-support

Conversation

@karthick-murugan
Copy link
Contributor

What?

Closes #71784

Adds blockCommentId as a global attribute to all blocks to resolve 400 errors when adding block comments to ServerSideRender blocks.

Why?

When adding block comments to blocks that use ServerSideRender components, a 400 error occurs because the blockCommentId attribute is not recognized server-side. The REST API validation rejects the request with:

How?

This PR implements blockCommentId as a global attribute similar to metadata and lock attributes:

PHP Implementation

  • Adds a filter on register_block_type_args to inject blockCommentId as a global attribute for all blocks
  • Ensures the attribute is available during block registration, not after (avoiding timing issues)
  • Uses the same pattern as other global attributes in WordPress core

JavaScript Implementation

  • Adds a hook on blocks.registerBlockType to ensure blockCommentId is registered client-side
  • Follows the same pattern as the existing lock and metadata hooks
  • Ensures consistency between server and client-side attribute definitions

Testing Instructions

  1. Open a post or page in the editor
  2. Insert a block that uses ServerSideRender (e.g., Latest Comments)
  3. Add a block comment to the ServerSideRender block
  4. Verify that no 400 error occurs in the browser console
  5. Confirm that the block comment is successfully added and displayed

Video

REC-20250923193256.mp4

@github-actions
Copy link

github-actions bot commented Sep 23, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: karthick-murugan <karthickmurugan@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@karthick-murugan karthick-murugan changed the title Add blockComment block support Block Comments: Add blockComment block support Sep 23, 2025
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a leftover from an AI.

* @param array $args Array of arguments for registering a block type.
* @return array Modified arguments.
*/
function gutenberg_add_block_comment_global_attribute( $args ) {
Copy link
Member

Choose a reason for hiding this comment

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

The feature is still experimental, so this should be placed in lib/experimental/block-comments.php.

Copy link
Member

Choose a reason for hiding this comment

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

This logic already exists in packages/editor/src/components/collab-sidebar/index.js. There is no need for duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated all the changes @Mamaduka

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. Collaborative Workflows Phase 3 of the Gutenberg roadmap around all-things related to collaborative workflows labels Sep 23, 2025
@t-hamano
Copy link
Contributor

Thanks for the PR!

I think there is a contradiction between the PR title and the implementation. I believe this PR just adds block attributes on the server-side, not block support.

This is code generated by an AI and has not been tested, but if we really want to add block support, the implementation should look something like this:

Details
<?php
/**
 * Block comment block support flag.
 *
 * @package gutenberg
 */

/**
 * Registers the blockComment block attribute for block types that support it.
 * This support is enabled by default and can be disabled by setting blockComment: false in block.json.
 *
 * @param WP_Block_Type $block_type Block Type.
 */
function gutenberg_register_block_comment_support( $block_type ) {
	// Check if block has explicitly disabled block comment support
	$has_block_comment_disabled = block_has_support( $block_type, array( 'blockComment' => false ), false );

	// If explicitly disabled, don't register the attribute
	if ( $has_block_comment_disabled ) {
		return;
	}

	if ( ! $block_type->attributes ) {
		$block_type->attributes = array();
	}

	if ( ! array_key_exists( 'blockComment', $block_type->attributes ) ) {
		$block_type->attributes['blockComment'] = array(
			'type' => 'string',
		);
	}
}

// Register the block support.
WP_Block_Supports::get_instance()->register(
	'block-comment',
	array(
		'register_attribute' => 'gutenberg_register_block_comment_support',
	)
);

@t-hamano t-hamano added the [Feature] Block API API that allows to express the block paradigm. label Sep 24, 2025
@Mamaduka
Copy link
Member

I think there is a contradiction between the PR title and the implementation. I believe this PR just adds block attributes on the server-side, not block support.

IMO, that's what's needed for this case, but I agree the title/description needs to be updated.

P.S. There's no need to add block-supports for this feature, since it's controlled at the post-type level and not by individual blocks.

@t-hamano
Copy link
Contributor

Another idea: how about treating the blockCommentId as part of the metadata? That way we can avoid a core backport PR and hook.

@Mamaduka
Copy link
Member

Another idea: how about treating the blockCommentId as part of the metadata? That way we can avoid a core backport PR and hook.

I like the idea; the value seems more suitable for metadata. @adamsilverstein, what do you think?

@adamsilverstein
Copy link
Member

Another idea: how about treating the blockCommentId as part of the metadata? That way we can avoid a core backport PR and hook.
I like the idea; the value seems more suitable for metadata. @adamsilverstein, what do you think?

I like the idea in principle, would this mean moving the id from attributes to metadata? I'm not familiar with how block metadata works so I'll have to dig deeper to review or test a PR.

@t-hamano
Copy link
Contributor

would this mean moving the id from attributes to metadata?

Yes. The block markup will be changed as follows:

<!-- From -->

<!-- wp:paragraph { "metadata": { "name": "My Paragraph" }, "blockCommentId": 1 } -->
<p>Hello World</p>
<!-- /wp:paragraph -->

<!-- To -->

<!-- wp:paragraph { "metadata": { "name": "My Paragraph", "blockCommentId": 1 } } -->
<p>Hello World</p>
<!-- /wp:paragraph -->

@t-hamano
Copy link
Contributor

Another idea: how about treating the blockCommentId as part of the metadata? That way we can avoid a core backport PR and hook.

To advance this approach, I have updated the title of the issue to follow the new approach. #71784

@adamsilverstein
Copy link
Member

Yes. The block markup will be changed as follows:

Great, thanks for clarifying @t-hamano. My next question which I can answer by testing your PR is if existing comment Ids need to be migrated to the metadata location to keep existing comments intact.

ps. Does the project have a description of what types of data should be stored in metadata vs. attributes? is metadata just a specific attribute or does it have special properties/APIs?

@t-hamano
Copy link
Contributor

if existing comment Ids need to be migrated to the metadata location to keep existing comments intact.

The Block Commenting is still an experimental feature, so I don't think we should migrate existing comment IDs. Breaking changes should be acceptable for now.

@adamsilverstein
Copy link
Member

The Block Commenting is still an experimental feature, so I don't think we should migrate existing comment IDs. Breaking changes should be acceptable for now.

Makes sense, thanks!

@t-hamano
Copy link
Contributor

Let's try the new approach in a separate PR.

@karthick-murugan, I'd like to close this PR, but thanks for your efforts!

@t-hamano t-hamano closed this Sep 26, 2025
@t-hamano t-hamano added [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting and removed Collaborative Workflows Phase 3 of the Gutenberg roadmap around all-things related to collaborative workflows labels Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Block API API that allows to express the block paradigm. [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block Commenting: Move blockCommentId attribute into metadata

4 participants