Repository navigation
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Xmerlin7! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsUnlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Xmerlin7. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
|
Thanks for the PR, @Xmerlin7! Clearing the stylesheet fixes the repro steps, but the root cause is a stale Created a PR with an alternative fix: #86168. |
What?
Closes #86064
This PR fixes a bug where the gray background color used to highlight rich text formatting boundaries (like italics) persists on the screen even after the user moves focus to a different block.
Why?
Currently, the
useBoundaryStylehook dynamically injects a<style id="rich-text-boundary-style">tag into the document head to render the boundary color based on the current text color. However, theuseEffectlacked a cleanup function. When a user clicked away andactiveFormatsbecame empty, the hook returned early but left the generated<style>tag in the DOM.With the recent focus management architectural changes in WP 7.2 (where the editor canvas retains a global
contenteditable="true"state), the native:focusselector in that orphaned stylesheet continued to match, causing the gray background to persist.How?
I added a cleanup function to the
useEffectwithinpackages/rich-text/src/hook/use-boundary-style.ts. When the component unmounts or the active formats are cleared, the cleanup function checks theglobalStyleelement and safely empties itsinnerHTML, correctly removing the CSS rule from the DOM.Testing Instructions
Testing Instructions for Keyboard
TabandEnter.Shift + Arrow Keysand italicize it usingCmd/Ctrl + I.UporDownarrow keys to move the cursor focus out of the paragraph and into an adjacent block.Screenshots or screencast
Use of AI Tools
I used an AI assistant as a pair-programming partner to help locate the specific
useBoundaryStylehook in the codebase usinggrep, and to assist in analyzing the ReactuseEffectlifecycle to determine where the cleanup function needed to be injected. I manually reviewed, tested, and verified the final code changes locally.