-
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
Global Styles: Allow opt out of certain sets of styles in the editor #61035
Global Styles: Allow opt out of certain sets of styles in the editor #61035
Conversation
Size Change: +84 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
Just noting here that the documentation around how these global styles are generated needs some updating as flagged in #61026 (review). A task to do this has been added to the tracking issue for section styles. |
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. |
marginReset: true, | ||
presets: true, | ||
rootPadding: true, | ||
...styleOptions, |
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 will throw an error by default because styleOptions
is undefined
. Using a default value of {}
or EMPTY_ARRAY
instead of undefined
might resolve 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.
Primitives can be spread into objects as well. All falsy values have no enumerable properties so nothing is spread.
Further proof there is that if you run the unit tests that don't supply the style options, there are no errors.
I'm not against updating the default value here just clarifying it doesn't throw an error as suggested.
I know the difference is completely negligible but is a default value of undefined
ever so slightly less resource intensive than creating an 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.
You're right, my mistake, it's arrays where undefined
can't be spread.
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.
Always good to challenge anything that looks odd. I appreciate the attention to detail 🙇
Does that mean we don't support "settings" in style variations or it's something we want to start with in a conservative manner, or what's the idea here? |
At this stage block style variations do not support their own "settings". The current enhancements to block style variations being worked on add the ability to style inner blocks/elements as well as nest the application of block style variations. To achieve this (primarily the nesting) #57908 generates styles per-application of a block style variation on a block and enqueues them. The root, layout, preset styles etc have already been generated and loaded by the primary theme.json/global styles stylesheet so they are superfluous in the context of the variation styles generated. It is on the radar that eventually block style variations would support their own settings definitions but for the time being it's out of scope for the current work. |
Related:
Note: The changes in this PR are being split out from #57908 to make that more manageable
What?
Adds a new option param to the editor's
toStyles
function that provides the ability to opt out of certain sets of styles.Why?
The extended block style variations in #57908 need to generate a stylesheet per application. The catch is they do not need all the root styles, layout, presets etc that would be generated without the ability to opt out of those.
Testing Instructions
npm run test:unit packages/block-editor/src/components/global-styles/test/use-global-styles-output.js
The unit tests should pass.
Note: While reviewing this PR it might be easier to toggle off the whitespace changes.