Repository navigation
Rich Text: Store the anchor element only for the selected field - #85983
Conversation
Every field stored its element in state when it mounted, which rendered each field a second time. Only the selected field shows the toolbar that needs the element, so only that field stores it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +2 B (0%) Total Size: 8.56 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. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
What?
Only the selected rich text field stores its element in state, for the toolbar that needs it.
Why?
Since "Rich Text: Make inline toolbar more reactive for proper positioning" (#73853), every rich text field calls
setAnchorElement( element )from its ref when it mounts. The state change renders every field a second time, running all of the wrapper's hooks again, although only the selected field shows the format toolbar that reads the element.Mounting 500 blocks, in µs per block (3 runs each):
RichTextHow?
The merged ref only includes
setAnchorElementwhile the field is selected. When a field becomes selected, the merged ref calls it with the element before paint, so only that field renders again. The toolbar renders only while the field is selected, so it still gets the element.Testing Instructions
Testing Instructions for Keyboard
Select text with Shift and the arrow keys, and add a link with Cmd+K.
Screenshots or screencast
No visual change.
Use of AI Tools
Written with Claude Code (Claude Opus 5.5). Reviewed by the author.
🤖 Generated with Claude Code