Repository navigation
useGlobalStylesOutput: Use memo for derived values #42917
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this return statement mean that the whole function could early return an empty array?
It looks like prior to this PR, the function will always return an array with four elements. From looking at the
useStatecalls, an equivalent to the default values in that case might be something like:return [ [], {}, {}, true ]?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.
Correct. Initially, I was planning to return the array with the same signature, but then I checked the usage, and returning
undefinedfor values won't be an issue.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.
Very interesting! Particularly because of
hasBlockGapSupporthaving a default truthy value. Given that the function doesn't appear to be exported outside of theedit-sitepackage, this sounds okay to me in principle.One thing to keep in mind with making changes to the output, is that from the documentation it sounds like there might have been (or be) an intention of potentially extracting the global styles APIs to their own package (this line). I think I remember @jorgefilipecosta working on making global styles data available in the post editor a while back, but I'm not sure if that's related.
I see that including
hasBlockGapSupportwas added to the output of the function in #40185 in April. From the looks of it, that value was only needed intoStylesand doesn't appear to be used by any consumers ofuseGlobalStylesOutput. It might be worth double-checking with @oandregal to see if there was a reason it was added to the output or whether it's still needed? It looks like we might be able to remove it altogether from the return value 🤔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 think this is the best time to change return types if we want 😄
I was wondering about the
hasBlockGapSupportreturn as well. So let'ss see if we can remove it.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, I don't see it in use anywhere either and don't remember why it was returned in the first place :)
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 the confirmation, @oandregal. I removed
hasBlockGapSupportfrom the return value.