-
Notifications
You must be signed in to change notification settings - Fork 4.7k
QueryInspectorControls: avoid rerender of TaxonomyControls on every keystroke #44562
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
Conversation
|
Size Change: +8 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
8ccf97d to
3366738
Compare
Mamaduka
left a comment
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, @jsnajdr!
The issue is hard to reproduce manually. Any keystroke action that can update the core store deselects the Query Loop block.
But the changes here make sense to me, and I couldn't spot any regressions.
The last little thing is rewriting a few .reduce loops to for or .map/.filter.
I'm assuming this was mainly for readability.
ntsekouras
left a comment
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 @jsnajdr! It looks good and didn't spot any regression either. I also think that by breaking the code into more components and loosing the mapper object make the code simpler and easier to follow.
It will need a rebase but after that 🚢
3366738 to
90147d4
Compare
The part of the Query Loop block that was rerendered on every keystroke, even when the block was not selected, was the
Yes, there is a strong " |
Fixes an issue described in #42525 (comment). When there is a Query Loop block on a page, like when editing Twenty Twenty-Two home template, then the
QueryInspectorControlscomponent is re-rendered on every keystroke, although nothing relevant to it has changed.That's because of inefficient use of
useSelect. On every keystroke a post gets updated and anEDIT_ENTITY_RECORDaction is dispatched tocoreStore. AlluseSelectcallbacks that select fromcoreStoreare called in the subscribed listeners. And if they return a value different from previous one, re-render is triggered.The
useTaxonomyInfohook returns a different value on every call, even when the underlying data haven't changed, because of how it internally combines data from multiple queries into one object, created anew on every call.I'm fixing this by using a plain
useTaxonomiesquery that returns just the plain data from the store. Instead of combining multiple queries (list of taxonomies + list of terms for each individual taxonomy), I'm pushing the sub-queries into the sub-components that use them (TaxonomyItem). Also I'm stopping to use thegetEntitiesInfohelper, which was also creating new objects on every call. Instead of using maps likemapByName, I just do a simple O(1) search with.find.The last little thing is rewriting a few
.reduceloops toforor.map/.filter.How to test:

Select a Query Loop block, uncheck the "Inherit query from template" checkbox so that you can edit your own query, and then add a taxonomy in the "Filters" section: