-
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
Add a debounce to the custom color onChange event #40285
Conversation
Size Change: +120 B (0%) Total Size: 1.22 MB
ℹ️ View Unchanged
|
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.
Nice one @glendaviesnz, I think adding a debounce makes good sense here.
It nicely improves the performance of typing in the custom color label:
One challenge with adding in a debounce is that we then no longer have completely realtime feedback when updating the color and the custom color is in use (e.g. below I've set the background of the header's group block to the custom color):
On balance, though, I think it's better to free up the UI by including the debounce rather than have the performance penalty of the realtime behaviour. Perhaps to find a middle ground, would it work to reduce the delay to 100ms
, or was 200ms
already the sweet spot?
…d change timeout to 100ms
Have switched to 100ms - I think that is good enough for this instance as people aren't going to be typing a paragraph into that box. |
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.
Thanks @glendaviesnz, that feels like a good balance in my testing now 👍
I just noticed another issue, which doesn't appear to be related to this PR (I can also replicate it on trunk). If you go to update the label of the custom color, and then change the color, there's a seemingly odd situation where if you're updating the label, then changes to the color don't immediately flow through. This appears to be because updating the label changes the name of the CSS variable, so any blocks that reference the custom color now no longer reference it. As a user, I imagine the expectation in the UI here could be that references to the custom color would be updated at the same time, but I imagine implementing a feature like that could be super complex. Just thought I'd mention it in case anyone bumps into that while testing out this change (and flagging that it's unrelated to the addition of the debounce
):
This LGTM! 🎉
@jorgefilipecosta Let me know if you can see any issues with this approach, otherwise I will merge this tomorrow. |
Provided things are working, I'm fine with this approach 👍 |
Co-authored-by: Glen Davies <[email protected]>
This was backported to wp/6.0 branch to be included in WordPress 6.0 Beta 3 tomorrow: f2b9ad4 |
What?
Adds a debounce wrapper to the onChange event for the custom color Option onChange prop.
Why?
Because updating the text of the custom color causes an update of custom colors array, each keystroke is causing a rerender of the full list.
Fixes: #38833
How?
Debounces the onChange method by 200ms to reduce the number of rerenders.
There may be a smarter way to do this, but because the index of the current item also needs to be passed into the callback I couldn't see any alternative to the current lambda that is being used for the onChange prop.
Testing Instructions