-
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
Inserter: Return the same items when the state and parameters don't change #62263
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. |
Size Change: -65 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
select( blockEditorStore ).getInserterItems( | ||
rootClientId, | ||
options | ||
), |
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.
Shouldn't we account for this in getInserterItems
? Also the default there is an empty object on every call, so we should change that too?
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.
Shouldn't we account for this in getInserterItems?
That would be ideal, but we need to figure out how. Functions have no control over the arguments they receive.
Also the default there is an empty object on every call, so we should change that too?
Yes. We should either pass undefined
or an EMTPY_OBJECT
.
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.
Yeah, this is a good fix for now. I wonder if we should just create another private getInserterItems
selector and avoid the options altogether. Actually this would also allow us to remove all the reusable blocks logic. We're adding these blocks, just to filter them back out in the UI 😄
Confirmed that this also fixes perf regression https://github.com/WordPress/gutenberg/actions/runs/9361910664/attempts/3#summary-25773603112 |
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.
Good one 👍
Ideally, we'd address it inside getInserterItems
but I agree that it can be tricky.
Thanks @Mamaduka 🚀
Do we still need the default parameter change to fix calls without options? |
Yes, and I just pushed an update for it. |
@@ -76,6 +76,8 @@ const EMPTY_ARRAY = []; | |||
*/ | |||
const EMPTY_SET = new Set(); | |||
|
|||
const EMPTY_OBJECT = {}; |
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 omitted the comment here. The other ones are a bit outdated and we should probably revise them together.
This will need to be backported |
@@ -1996,7 +1998,7 @@ const buildBlockTypeItem = | |||
*/ | |||
export const getInserterItems = createRegistrySelector( ( select ) => | |||
createSelector( | |||
( state, rootClientId = null, options = {} ) => { | |||
( state, rootClientId = null, options = EMPTY_OBJECT ) => { |
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.
Actually I guess this doesn't matter because createSelector
is not aware of the default, it would just not be defined. Sorry my mistake :D
…dd/on-async-directives * 'trunk' of https://github.com/WordPress/gutenberg: (72 commits) Top toolbar: fix half a pixel artifacting of the bottom border. (#62225) Fix UI order for theme.json spacing sizes (#62199) Chore: Simplify a padding style on global styles. (#62291) Editor: Avoid remounts of `DocumentBar` (#62214) Add `default-spacing-sizes` and `default-font-sizes` options for classic themes (#62252) Editor: Cleanup styles and classnames (#62237) Scripts: Pin the @wordpress/scripts version to a version supported by WP 6.5 (#62234) Documentation: Better changelogs for the JSX transform upgrade (#62265) Chore: Simplify a padding style on dataviews. (#62276) MediaUpload: Remove dialog markup on close (#62168) Tabs: Prevent accidental overflow in indicator (#61979) Make edit site pagination buttons accessibly disabled. (#62267) Fix: Remove unused code from dataviews styles. (#62275) Re-enable React StrictMode (#61943) Inserter: Return the same items when the state and parameters don't change (#62263) Update instances of text-wrap: pretty to fall back to balance (#62233) Update: Slotfill documentation samples (links, code, and rephrase). (#62271) Try: Fix mover positioning. (#62226) [Mobile] - Image corrector - Check the path extension is a valid one (#62190) Update: Block styles documentation. ...
…hange (#62263) * Inserter: Return the same items when the state and parameters don't change * Use stable default Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
…hange (#62263) * Inserter: Return the same items when the state and parameters don't change * Use stable default Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
…hange (WordPress#62263) * Inserter: Return the same items when the state and parameters don't change * Use stable default Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
This was cherry-picked to the wp/6.6 branch. |
What?
PR updates the selector in the
useBlockTypesState
hook to return the sameitems
when the state and parameters haven't changed.This is a follow-up to #62169 (comment).
Why?
The
getInserterItems
is a memoized selector, and when an argument is different on each call, it will return different (fresh) values. This behavior makes it complicated to addarray
orobject
type parameters to similar selectors. Example: #40718.How?
Memoize the
options
passed to the selector on the component level.I don't like shifting this responsibility to the consumer, but I see no other way besides changing the
getInserterItems
signature.Testing Instructions
useBlockTypesState
hook generates no warning.Testing Instructions for Keyboard
Same.
Screenshots or screencast