-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Memoize useSelect
for usePatterns
#54588
Conversation
Size Change: +88 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
cf61ba4
to
1a6c423
Compare
@Mamaduka Do you want to give it a quick test to see if it works for you? 🙇 |
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 for tackling this one @kevin940726 👍
I didn't spot any issues or regressions while exploring the pattern management page in the Site Editor. Whether it was navigating categories, searching, filtering, viewing, editing or creating patterns it all seemed to work well. No warnings or errors appeared in devtools console.
I'm not very familiar with rememo
so it would be great to get some extra eyes on this and sanity check the approach.
From my end though, the changes make sense and avoid a more drastic refactor, while still addressing the console warnings.
Nice work ✨
Thank you, @kevin940726! I'll have a more in-depth look as soon as possible. |
0b0dd30
to
65e310d
Compare
65e310d
to
381abf6
Compare
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.
I've given this another test after the recent tweaks at it is working well still for me. No sign of the useSelect
warnings.
Have we missed the boat to get this into the 16.7 release if it is only seen as an enhancement?
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.
The code looks good to me, but using the createSelector
like this feels bit odd 😅
Ideally, we would return only selector values from useSelect
and handle filtering/mapping outside of the hook, but I understand this would require langer refactoring.
I'm okay with landing this solution and then following up with refactoring. What do you think?
P.S. This can count as a bug fix or code quality improvement. I think it would be okay to land in Gutenberg RC.
Yeah, it's unconventional, but it's also essentially how selectors work. I agree we should follow the convention as much as possible by placing the selectors in a Thanks for reviewing! We can work on refactoring them into conventional selectors next! ❤️ |
I just cherry-picked this PR to the release/16.7 branch to get it included in the next release: ab08f21 |
I just cherry-picked this PR to the release/16.7 branch to get it included in the next release: bbdcba0 |
What?
Originally reported in #52303 (comment) by @Mamaduka. This PR memoizes some selectors to avoid re-renders.
It's best to be reviewed with whitespaces hidden.
Why?
Even though re-renders aren't necessarily bad, and sometimes over-memoizing selectors comes with a cost, I don't think memoizing it brings any harm either. It silences a warning in console so that must be good! 😆
How?
Use
rememo
to memoize some selectors used inusePatterns
.Testing Instructions
usePatterns
(site-editor.php?path=/patterns
) and navigate around or interact with it.useSelect
warning aboutusePatterns
.Testing Instructions for Keyboard
Same as above.
Screenshots or screencast
N/A