Refactor: useMemo on elements and useCallback is back on resetAllFilter#78329
Conversation
|
cc: @ciampo |
|
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. |
|
Are there any visible wins for this memoization, or is it just theoretical? Is it expensive to recreate these values? |
|
@Mamaduka actually has a point. The memoization doesn't really seem to bring concrete advantages:
With that in mind, there is still one part of this PR that is a nice improvement, ie. hoisting the const showCaptionPanel = useHasCaptionPanel( settings );
const showButtonPanel = useHasButtonPanel( settings );
const showHeadingPanel = useHasHeadingPanel( settings );We could either close this PR entirely, or keep it with only these minor changes. @Mamaduka @USERSATOSHI , do you have a preference? |
|
Yes, let’s keep panel status vars and discard memorization. |
The only reason I shared this issue was that the warning message was bugging me every time I edited that file. 😅 |

What?
Follow up PR based on #78048 (review)
Performance optimization: wrap
elementsarray andresetAllFiltercallback in memoization hooks to prevent unnecessary recreations on every render.Why?
The
elementsarray was being recreated on every render, andresetAllFilterwas being recreated wheneverelementschanged. This causes unnecessary re-renders of dependent UI components. Memoizing both ensures they only update when their actual dependencies change.How?
useHasCaptionPanel,useHasButtonPanel, anduseHasHeadingPanelhook calls to the component top level (they can't be called insideuseMemo)elementsinuseMemowith dependency array[ showCaptionPanel, showButtonPanel, showHeadingPanel ]resetAllFilterinuseCallbackwith dependency array[ elements ]Use of AI Tools
None