Skip to content

Conversation

@Mamaduka
Copy link
Member

@Mamaduka Mamaduka commented Oct 22, 2025

What?

Requires #71728.
Related #71668 (comment).

PR overrides the children embeddable link for notes to allow embedding their replies (children). The current link returns no results because it uses the default type and status collection params, instead of inheriting from the current query.

An alternative option is to add a new replies link just for the note comment type and not modify the existing one, but considering we're already patching responses for the Notes, I don't think this is a breaking change.

Why?

See #71668 (comment).

Testing Instructions

  1. Comment out following filter - add_action( 'comments_clauses', 'exclude_block_comments_from_admin', 10, 2 );.
  2. Create a post.
  3. Add blocks.
  4. Add notes and their replies to these blocks.
  5. Run JS test snippet.
Test JS snippet

function testNotesEmbedQuery( ) {
    const postId = wp.data.select( 'core/editor' ).getCurrentPostId();

    const queryArgs = {
		post: postId,
		type: 'note',
		status: 'all',
		parent: 0,
		per_page: 100,
		context: 'edit',
		_embed: 'children',
	};

	return wp.data.select( 'core' ).getEntityRecords( 'root', 'comment', queryArgs );
}

console.log( testNotesEmbedQuery() );

Testing Instructions for Keyboard

Same.

Screeenshot

CleanShot 2025-10-22 at 11 03 13

@Mamaduka Mamaduka self-assigned this Oct 22, 2025
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended REST API Interaction Related to REST API [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting labels Oct 22, 2025
@Mamaduka Mamaduka force-pushed the try/notes-endpoint-embed-children branch from 05c6482 to e213526 Compare October 22, 2025 06:38
$args = array(
'parent' => $comment->comment_ID,
'type' => $comment->comment_type,
'status' => 'all',
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, embedded replies are missing a couple of properties, such as content.raw and meta.

I know that links can pass their own context, but I haven't seen it used in practice by core. Is this something we should avoid?

P.S. What's the reason for disallowing embed context for specific properties, but allowing it in view context? Wasn't able to find anything in the docs.

Copy link
Member

Choose a reason for hiding this comment

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

such as content.raw

We wouldn't include content.raw, because it's an edit only property. The embed should be a subset of view.

I know that links can pass their own context, but I haven't seen it used in practice by core. Is this something we should avoid?

Yeah, I wouldn't want us to introduce that to Core, because that's really something that the client should be deciding on.

I wouldn't be opposed to something like ?_embed=children.view perhaps? Maybe that's too cheeky of an API.

What's the reason for disallowing embed context for specific properties, but allowing it in view context?

Ultimately, it's a judgement call about payload size/cost and importance. The embed context is often thought of as being used in a context (ha) where you are displaying a small snippet of a resource, and then would often link to a view where you can see everything about a resource.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can still make it work without content.raw. We could refetch the note that the user is editing with proper context, or just use content.rendered. The form currently lacks RichText capabilities.

The meta values are used for display, so we'll need to fetch them. It would have been nice if each meta property could define its context, if needed.

Ultimately, it's a judgement call about payload size/cost and importance. The embed context is often thought of as being used in a context (ha) where you are displaying a small snippet of a resource, and then would often link to a view where you can see everything about a resource.

Thanks for the explanation. The logic now makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

It would have been nice if each meta property could define its context, if needed.

They can in their show_in_rest schema definition. I've always used it to add an edit context and hide the value. I think we could safely extend the context for meta to include embed as a value, and then automatically apply a default context of view,edit for each meta key.

Copy link
Member Author

Choose a reason for hiding this comment

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

Really? I tried setting a custom context for these meta fields, but it wasn't available in the embed response.

The meta fields object has its context set to view,edit, and I don't think you can override it without changing the REST API code.

https://github.com/WordPress/wordpress-develop/blob/bd797e0358dc1f8b216f48dec1b31ef4ef24028d/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php#L528

Copy link
Member

Choose a reason for hiding this comment

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

Right, at the moment, it only works to constrain it further. So I'm suggesting we add embed to the context list for meta. And when build up the properties schema here we add a default context of view,edit. That way, any existing meta keys continue to not show up in an embed context.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. However, that's probably something for the next major release. But I'll create a ticket and patch on Trac.

Do you think that the current children link fix makes sense to include with the current release, even if we don't end up using embedded values?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I think so. It looks like a valid bug fix to me.

@Mamaduka Mamaduka force-pushed the try/notes-endpoint-embed-children branch from e213526 to 72c6616 Compare October 23, 2025 09:11
@github-actions
Copy link

Flaky tests detected in 72c6616.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18743459196
📝 Reported issues:

@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: Mamaduka <[email protected]>
Co-authored-by: TimothyBJacobs <[email protected]>

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

@Mamaduka Mamaduka force-pushed the try/notes-endpoint-embed-children branch from 72c6616 to b8a7e37 Compare October 27, 2025 14:38
@Mamaduka
Copy link
Member Author

I'm going to merge this after all checks pass. @adamsilverstein is working on backports.

@Mamaduka Mamaduka merged commit c7a37db into trunk Oct 28, 2025
34 checks passed
@Mamaduka Mamaduka deleted the try/notes-endpoint-embed-children branch October 28, 2025 04:22
@github-actions github-actions bot added this to the Gutenberg 22.0 milestone Oct 28, 2025
@jeffpaul
Copy link
Member

@Mamaduka Does this need the 6.9 backport label or expected to have this pulled into the wordpress-develop work that @adamsilverstein is working on?

@Mamaduka
Copy link
Member Author

@jeffpaul, this should be part of WordPress/wordpress-develop#10405 (comment).

@adamsilverstein
Copy link
Member

@jeffpaul - I am pulling this in manually.

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 REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants