Repository navigation
Add emoji reactions on blocks (stacked on #83538) - #83169
adamsilverstein wants to merge 37 commits into
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: +2.3 kB (+0.03%) Total Size: 8.4 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. All navigation links should default to the body color and submenus and mobile overlay should default to a white background with black text in
|
|
I think that design takes this change too far in terms of real estate in the toolbar. We need to think about the balance between folks collaborating vs folks writing solo and not disrupting those simply writing with more bells and whistles, so to speak. |
Cover the REST contract (a top-level block anchor instead of a parent note, uniqueness scoped by post and anchor, a block_reaction_summary field on the post) and the editor flow (toolbar trigger, sidebar listing, persistence, undo) before the implementation lands, so each behavior is proven red first. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Add block-reactions.php with a _wp_reaction_block comment meta, a resolver that maps a reaction request to a note or a block target, and query scoping that keys a block target by post and anchor. A zero parent alone matches every top-level comment site-wide, so the extra scope is what keeps uniqueness and convergence correct for block targets. Expose a read-only block_reaction_summary field on notes-capable post types in edit context, computed with one aggregate query and only for single-item requests so post lists never pay for it. A rest_comment_query filter lets the editor list a block's reactions by anchor to name who reacted. Post-level targets stay a reserved, rejected branch of the resolver until they have a read and create policy of their own. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Replace the inline parent-note checks with the shared target resolver and accept a top-level block anchor, validated by schema pattern before the controller runs. A block target stores as a top-level row with the anchor in comment meta, written by wp_insert_comment before the convergence query so concurrent duplicates still collapse. Name the permission gates by what they read so reactions no longer inherit note policy implicitly, report rest_cannot_create_reaction for a reaction the user may not create, and look the post up before the capability gate so a missing post reports rest_comment_invalid_post_id. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Introduce the reaction target type and the helpers that mint, read and write a block's metadata.reactionsId anchor, fold a toggle into a cached summary, and build the per-target REST query. Preserve the anchor through one-to-one block transforms the way noteId already is, so a paragraph turned into a heading keeps its reactions. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Replace the noteId prop on ReactionDisplay and AddReactionButton with a target so the same pills, picker and reactor-name lookup serve a block. The note request is unchanged; a block target lists by post, parent 0 and anchor. AddReactionButton gains a label, a wrapper class and a renderToggle so a toolbar button can open the same picker, and ReactionDisplay gains onRemoveLast for a host that unmounts when its last pill goes. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Read the post's block_reaction_summary and merge each reacted block into the note threads in document order: at the head of the block's first unresolved thread, or as an entry of its own when the block has no note. Toggling a block reaction mints the anchor synchronously, posts or deletes the reaction comment, folds the result into the cached post record as a partial so unsaved edits survive, then refetches only the summary for other users' counts. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Add a reactions row (block icon, pills, "Add block reaction" trigger) that leads a block's first thread, and a standalone entry that shares the thread shell for a block with reactions but no note, so selection, keyboard navigation, floating placement and block highlighting work unchanged. The row is its own hover target for the trigger reveal. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Fill the note toolbar slot with a smiley button that opens the reaction picker for the selected block, beside the note avatar indicator. It is disabled on a classic block, which has no block-level anchor to write, and on a locked block that has none yet. Synthetic reaction entries are kept out of the note highlight styles and the avatar indicator's thread lookup. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
The floating sidebar only takes over once the user closes whatever complementary area is active, so a reaction added from the toolbar landed in a sidebar that never opened. Report success from the toggle and enable the notes area on it, the way adding a note already does. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
Add changelog entries for the editor and block-editor packages and a "Block reactions" section to the collab sidebar README covering the anchor, the summary read path and the thread placement rule. Claude-Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
The toolbar button borrowed the exported inline smiley from the picker, which the base branch has now replaced with the reaction icon from @wordpress/icons. Import that icon directly instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GaU1KRgXC1a2DBq9NaPpgx
Collection responses carried block_reaction_summary: null, and core-data merges single and collection responses into one per-record cache. A collection that included the edited post, such as a Query Loop preview, erased its loaded summary, hid the block's reactions and could route the next toggle to a duplicate add. Strip the uncomputed field instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVG6n1U8ALSytqDGniZYGF
Selecting a block-reactions entry selects the entry, then its block. The block transition synced the selection to the block's primary note, which a reactions-only block does not have, so the entry was deselected right away for both pointer and keyboard. Keep an explicitly selected thread that belongs to the newly selected block. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NVG6n1U8ALSytqDGniZYGF
The block-reactions-row test registered core/paragraph without an apiVersion, so the blocks package emitted its API version deprecation warning and the Vitest console guard failed the run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqepyjmFSryBt88j6f6ubY
WP_UnitTestCase unregisters every meta key in tear_down, so the init registration only survives for the first test of the run. The registry assertion failed whenever another test ran before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqepyjmFSryBt88j6f6ubY
The block toolbar now includes the "React to block" button between More and Options, so the keyboard navigation spec must step through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqepyjmFSryBt88j6f6ubY
77dbb23 to
bea9dd6
Compare
…ete-grid' into add/block-emoji-reactions # Conflicts: # packages/editor/src/components/collab-sidebar/README.md # packages/editor/src/components/collab-sidebar/reactions/add-reaction-button.tsx # packages/editor/src/components/collab-sidebar/style.scss
Trims the PR to the feature code, as #83538 did for the note reactions; the e2e suite covers the same behavior end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mc4Menp91Vyvh9AryqivSN
Mirrors useReaction( note ) from #83538 so the row and the toolbar button read and toggle a block's reactions themselves, instead of having the toggle and summary threaded through Notes, NoteThread and the entry. The thread-list merge moves out of useNoteThreads into addBlockReactionEntries, leaving the note ordering loop as it was, and the helpers only the unit tests needed (injected anchor generator, metadata and delta wrappers, the Math.random fallback) are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mc4Menp91Vyvh9AryqivSN
Folds the anchor, reuse and removal checks into one flow, and drops the picker keyboard test and the note-reaction half of the mixed test: the note reaction suite and the toolbar navigation spec already cover them. The toolbar trigger is now an Autocomplete combobox, so the helper finds it by that role. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mc4Menp91Vyvh9AryqivSN
The picker's Autocomplete trigger cannot live in the block toolbar: the toolbar's roving focus remounts it on mousedown, and the popup closes on mouseup. The toolbar button is now a plain ToolbarButton that lists the block in the sidebar, even before its first reaction, and focuses the row's "Add block reaction" trigger. That keeps one picker trigger per target and drops the custom trigger prop from AddReactionButton. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mc4Menp91Vyvh9AryqivSN
…ete-grid' into add/block-emoji-reactions # Conflicts: # lib/compat/wordpress-7.2/class-gutenberg-rest-comment-controller-7-2.php # packages/editor/CHANGELOG.md
|
The goal here was leaving a reaction to a block, for example a smiley on an image. I'll try cleaning this up and moving the interaction to the ellipsis menu, so Add Note and Add Reaction. |
…emoji-reactions Block reactions now store the emoji hex key, matching the base branch's hex-only storage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bb4BE9PBpaTHtGMhp4ASAQ
Reviewers felt a dedicated toolbar button gave block reactions too much weight next to the writing tools. "Add reaction" now sits after "Add note" in the block options menu and opens the block's reactions in the sidebar as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bb4BE9PBpaTHtGMhp4ASAQ
The reaction control moved from the block toolbar into the block options menu, so the toolbar no longer has a "React to block" stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bb4BE9PBpaTHtGMhp4ASAQ
Replace the CSS class locator with the row's accessible group name and share one pill helper across the block reaction specs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bb4BE9PBpaTHtGMhp4ASAQ
|
@jasmussen I added a screencast to the description and you can also try Playground. I like the overall idea of reacting to blocks, but I'm not sure I like how it works here beside Notes. |
…k-emoji-reactions Key the base's shared reactor-name cache by reaction target, so block pills share one fetch the same way note pills do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bb4BE9PBpaTHtGMhp4ASAQ
|
You're a freight-train with how many PRs you open. Impressive! On this one, it actually touches on a principle I think is very important to establish, which I suggest should be: notes are notes. Whether you add a note and write text, or whether you make an edit while in suggest mode, or even if we end up adding lint tools in the canvas then lint-notices are notes. The key being: each of them come with a thread where you can respond to a particular suggestion or add notes to a lint item. Or, you could react. In other words, I don't see a threadless "Reaction" alone as something that shouold show up in the notes tray. It could be a reaction note, the difference being that it's also just a note, with a thread, it could read out "Adam reacted with 👍", and then it's a note thread. I believe this principle of a single note type with threads being fairly important to not increase the review surface. Yes we can have many different types of contents inside a note, but a note is a note. So for me the question is one of: should reactions have its own menu item? And in my opinion, no, because the menu is already rather complicated. What do you think? I defer to @fcoveram if he has instincts. |
|
Nothing much to add, but just second what @jasmussen said above. |
Probably not. I mostly wanted to explore what reactive with emoji to blocks would look like, to make sure how we are building reactions enables that in the future.
That makes sense, so reactions become a kind of note. I'm trying to imagine adding reactions in different places in the editor, for example in the media library. I do see that Google docs enables an emoji reaction on a selection that isn't a comment. |
…k-emoji-reactions
Adopt the base's `{ count, current_user_reaction }` summary shape for
block reactions too, and move "Add reaction" on a block onto the canvas
margin floating notes that replaced the floating sidebar.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEnYgh9tWGG6ptNTQrZK6R
The base lowercased the curated reaction labels, so the block reaction specs could no longer find "Heart" or "Rocket" in the picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QEnYgh9tWGG6ptNTQrZK6R
…ete-grid' into add/block-emoji-reactions # Conflicts: # packages/editor/src/components/collab-sidebar/README.md # packages/editor/src/components/collab-sidebar/hooks.js # packages/editor/src/components/collab-sidebar/index.jsx # packages/editor/src/components/collab-sidebar/note-thread.jsx # packages/editor/src/components/collab-sidebar/notes.jsx
…k-emoji-reactions
…ete-grid' into add/block-emoji-reactions # Conflicts: # lib/compat/wordpress-7.2/class-gutenberg-rest-comment-controller-7-2.php # packages/editor/src/components/collab-sidebar/reactions/use-reaction.ts
Block reactions share the summary delta helper and the toggle flow, so they had the same stale-removal and repeated-click problems as note reactions. The resolver test fixtures now create open notes, since an approved note is a resolved thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L7rwHtVAa37GWJPC8P3Cwd
…k-emoji-reactions Follow the base's note selection rework: select a block's reactions through `pickNote`, so an empty new-note form is discarded the same way, and pass the block's reactions to the picker trigger so it marks the user's own reactions too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QEnYgh9tWGG6ptNTQrZK6R
|
@adamsilverstein, how about changing the base branch of this PR from #83538 to #76767? This is because #76767 is the one currently viable, not #83538. |
|
Good idea @t-hamano. I'll work on that when I'm back at my computer tomorrow. |
dmsnell
left a comment
There was a problem hiding this comment.
just some minor comments. this is not meant to be a full review; just trying to get at it where I can with the time I have. if I can come back and focus more on this I will.
| */ | ||
| function gutenberg_get_reaction_block_anchor_pattern() { | ||
| return '^[a-z0-9]{6,16}$'; | ||
| } |
There was a problem hiding this comment.
does this warrant a function? at least as a const it would just be a string literal, but as a function call it adds runtime overhead, meaningless as that would be in the big picture.
the JSDoc can attack to a const. just curious why the function exists
There was a problem hiding this comment.
a constant would probably be better
| $anchor = (string) $row->block; | ||
| $hex_key = wp_strip_all_tags( $row->hex_key ); | ||
|
|
||
| $summary[ $anchor ][ $hex_key ] = array( |
There was a problem hiding this comment.
is hex_key the code point for the reaction in hex?
| comment_content |
| "1F384" |
(for 🎄)
I find hex_key as the name for comment content confusing.
There was a problem hiding this comment.
I find hex_key as the name for comment content confusing.
It is the key for the reaction in hex, or i guess the code point. would you call it 'comment_content' instead?
| $summary = array(); | ||
| foreach ( (array) $rows as $row ) { | ||
| $anchor = (string) $row->block; | ||
| $hex_key = wp_strip_all_tags( $row->hex_key ); |
There was a problem hiding this comment.
what’s the goal here? I generally try and steer people away from wp_strip_all_tags() due to its poor HTML parsing.
if we are trying to match some code point sequence, perhaps a positive affirmation of the reaction would be helpful?
if ( strspn( $row->hex_key, '0123456789ABCDEFabcdef' ) !== strlen( $row->hex_key ) {
continue;
}
$codepoint = inval( $row->hex_key, 16 );
if (
$codepoint > 0x1FFFF || // Beyond the highest codepoint.
( $codepoint >= 0xD800 && $codepoint <= 0xDFFF ) // Unpaired surrogates.
) {
continue;
}There was a problem hiding this comment.
The same pattern is already in trunk from #76767, so I split this out: #86775
Claude worked through the change, here is where it differs from your snippet:
A key can hold more than one code point (skin tones and flags are sequences joined by
-, eg.1f44d-1f3fd), so the check splits on-and tests each part instead of runningintval()over the whole string.Each part has to be lowercase hex, no higher than
0x10FFFFand not a surrogate. Rows that fail are left out of the summary, and the other reads compare the stored content to the validated key exactly, sowp_strip_all_tags()is gone from the controller.Core trunk has the same calls since https://core.trac.wordpress.org/changeset/64488, so it needs the same patch there.
Does that match what you had in mind?


Claude Code wrote this description and brought it up to date with the block options menu version, new screenshots included.
Summary
Stacked on top of #83538 (standalone against trunk; it replaced #78176 and #76767, which are closed) - review that first. Part of #75144, which set out to make
reactiona comment type that can attach to more than a note.This PR lets a user react to a block itself, not only to a note on it. An "Add reaction" item in the block options menu, right after "Add note", brings the block's reactions into the Notes sidebar, where the same emoji picker notes use lives. They show up in the Notes sidebar: at the head of the block's first thread when it has a note, or as an entry of their own when it does not.
It also turns the "a reaction must have a parent note" rules in the REST layer into a small target abstraction, so posts and media can follow later as two more branches rather than a rewrite. Those two are documented but not implemented here.
Where it lives
No design exists for this yet in #82324, so the sidebar placement is still a first pass.
Data storage
A block has no persistent id, so the first reaction on a block mints a short anchor and writes it to the block's
metadata.reactionsIdattribute, mirroring how notes anchor throughmetadata.noteId. That makes the post dirty until it is saved, exactly as the first note on a block does. Later reactions reuse the anchor.Each reaction is still one row in
wp_commentswithcomment_typereaction. On a block it is a top-level row (comment_parent0) on the post, anchored through a new_wp_reaction_blockcomment meta.Writing.
POST /wp/v2/commentswithtype: reaction,post,block: <anchor>and the emoji's hex key (the same hex-only storage #83538 uses for notes). A new resolver (gutenberg_resolve_reaction_target()inlib/compat/wordpress-7.2/block-reactions.php) maps a request to a note target (parent) or a block target (block), and rejects both or neither. The anchor is validated by schema pattern (^[a-z0-9]{6,16}$) before the controller runs. Uniqueness and the concurrent-duplicate convergence from #76767 now scope by post and anchor - on its own a zero parent matches every top-level comment site-wide, which is the one real trap in generalizing this.Reading. The post resource gains a read-only
block_reaction_summaryfield ineditcontext, keyed by anchor and then by hex key with the same{ count, reacted, my_reaction_id }shape as a note'sreaction_summary. One aggregate query, computed for single-item requests only, so a list of posts never pays for it. The editor reads it off the post record it already holds, folds a toggle into the cached record as a partial (so unsaved edits survive) and refetches only the field afterwards.GET /wp/v2/comments?post=&parent=0&block=&type=reactionlists who reacted, for the pill tooltips.Permissions. Unchanged in effect: reacting needs
edit_poston a notes-capable post type, the same as a note. The permission check now names the flag each gate reads instead of folding reactions into the note flag, so a target-specific policy later (readers reacting to a published post, say) is a one-line change at that gate. A reaction the user may not create reportsrest_cannot_create_reactionrather than the note error.Orphans. Nothing on the server reconciles anchors with content on save, deliberately: reactions are created before the anchor is saved, so a save from stale content (another collaborator, a plugin calling
wp_update_post()) would trash live reactions. The client just does not list an anchor with no matching block, and undo restores the block with its anchor and its pills. Permanently deleting the post removes the rows and their meta as it does for any comment.Does the data model generalize?
Checked against the plugin and the Core backend in WordPress/wordpress-develop#10930. The storage layer already accepts a reaction with no parent on any post, and the internal-type list hides the type from front-end queries, counts and the admin list regardless of target. Every "must be a note" rule lived in the REST controller and the cascade hooks, and those are what this PR generalizes. A post or media target would need a new resolver branch, a
reaction_summaryfield on its resource reusing the same aggregate query grouped bycomment_post_ID, and its own read policy (reactions are not world-readable today, so a public count needs one). The row shape and the storage key do not change.Testing
For multi-user testing, try https://wordpress.org/plugins/user-switching/
npm run build.metadata.reactionsId.GET /wp/v2/posts/<id>?context=editcarriesblock_reaction_summary;?context=viewdoes not; the posts collection returnsnullfor it.Automated: 5 Playwright specs under
Block Reactionsinblock-notes.spec.js(the full notes spec, 71 tests, passes locally), plus phpunit cases acrossBlock_Reactions_Testand the Gutenberg comments controller test (120 pass locally).Screenshots
Screencast
block-reactions-screencast.mp4
Adding two reactions to a paragraph from the block options menu, then a note on the same block: the reactions row moves to the head of the note's thread.
Types of changes
lib/compat/wordpress-7.2/block-reactions.php:_wp_reaction_blockcomment meta, the target resolver and query scoping, theblock_reaction_summarypost field, arest_comment_queryfilter for listing by anchor.blockparam in the 7.2 comment controller; report the anchor on reaction responses; split the note/reaction permission flags.metadata.reactionsIdhelpers and aReactionTargettype; generalizeReactionDisplayto a note or block target (the note request is byte-identical); letAddReactionButtontake a label and class name.useBlockReactionSummaryanduseBlockReaction( clientId )(the block counterpart ofuseReaction( note )); merge reacted blocks intouseNoteThreads.BlockReactionsRow,BlockReactionsEntryand the "Add reaction" block options menu item; preservemetadata.reactionsIdthrough one-to-one block transforms.Open questions
noteId.AI Use
Claude Code wrote the code and this description over a few rounds of back and forth, starting from a plan we agreed on. I will review and test.
Session: https://claude.ai/code/session_01XFFaaNbo3UJuVm8so8Zsrj
https://claude.ai/code/session_01Bb4BE9PBpaTHtGMhp4ASAQ