Skip to content

Conversation

@R1shabh-Gupta
Copy link
Contributor

@R1shabh-Gupta R1shabh-Gupta commented Sep 14, 2025

What?

Closes #71642

This PR fixes block commenting functionality to prevent crashes and disable comments when editing templates or other contexts without valid integer post ID.

Why?

Comments were allowed in template editing (where post ID is a string like 'twentytwentyfive//home'), but the WordPress REST API requires post IDs to be integers, causing requests to fail

How?

Added a check to only show comment functionality when postId is a valid number (integer), completely hiding comment UI for templates and other invalid contexts

Testing Instructions

  1. Test normal post commenting (should still work):

    • Open any existing post or page for editing
    • Select any block
    • Verify the comment button appears and works normally
  2. Test template editing (comments should be disabled):

    • Go to Appearance > Theme Editor > Templates
    • Edit any template (like "Home" or "Single Post")
    • Select any block within the template
    • Verify that NO comment button or comment functionality appears

Screenshots or screencast

Before After
Screenshot 2025-09-14 at 6 21 59 PM Screenshot 2025-09-14 at 6 21 29 PM

Comment on lines 341 to 343
if ( ! hasValidPostId ) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We could just inline the check here. I usually avoid creating the variables if they're only used once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I update it like this, @Mamaduka? And would it be fine to add a comment?

// If postId is not a valid number, do not render the comment sidebar.
if ( ! ( !! postId && typeof postId === 'number' ) ) {
	return null;
}

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that looks about right.

@Mamaduka
Copy link
Member

@R1shabh-Gupta, is this ready for the review?

@R1shabh-Gupta R1shabh-Gupta marked this pull request as ready for review September 15, 2025 11:30
@github-actions
Copy link

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: R1shabh-Gupta <rishabhwp@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended Collaborative Workflows Phase 3 of the Gutenberg roadmap around all-things related to collaborative workflows labels Sep 15, 2025
@t-hamano
Copy link
Contributor

@Mamaduka, do we ship this PR first and then add a block comment post type support? #71642 (comment)

@Mamaduka
Copy link
Member

@t-hamano, yes. We should resolve current errors and since post type supports is still in discussion, this seems like a fastest way.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@t-hamano t-hamano merged commit 043d2aa into WordPress:trunk Sep 15, 2025
69 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.7 milestone Sep 15, 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] Notes Phase 3 of the Gutenberg roadmap around block commenting [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block Comenting: Add block-comment as a new post type support

3 participants