-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rich text: combine all ref effects #60936
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. |
034f2c6
to
bf1c0af
Compare
Size Change: -41 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
b7ef3d7
to
c373832
Compare
Merging this because it's just a refactor and I have some other PRs that touch these listeners. Regardless of any perceivable performance benefit, I think it make each listener also less verbose and more understandable. |
( element ) => { | ||
if ( ! props.isSelected ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally this PR avoids attaching all these listeners for non selected blocks.
What?
Instead of calling
useRef
anduseRefEffect
(which consists of anotheruseRef
anduseCallback
call) 17 times for a single rich text instance, we can reuse the same ref and callback to add all event listeners.Why?
Reduces the amount of React hooks in rich text, and the verbosity.
How?
We can use a single ref effect to attach all the event listeners.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast