-
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
Fix mutated global styles context #49623
Conversation
Size Change: +51 B (0%) Total Size: 1.35 MB
ℹ️ View Unchanged
|
Flaky tests detected in 7a60a68. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4623199771
|
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 tracking this bug 👍
@@ -780,6 +783,7 @@ export const toStyles = ( | |||
// Process styles for block support features with custom feature level | |||
// CSS selectors set. | |||
if ( featureSelectors ) { | |||
// Mutates the passed styles object. | |||
const featureDeclarations = getFeatureDeclarations( |
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.
If this is the function mutating the object (I see a delete there), why don't we update the function to avoid the mutation instead of cloning the whole tree.
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.
The deletion/mutation is used to format some styles specially. There's code similar to this:
// special case
if ( duotoneSelector ) {
ruleset += `${ duotoneSelector } { filter: ${ styles.filter.duotone }; }`;
delete styles.filter;
}
// standard case (loop inside `getStylesDeclarations`)
if ( styles.filter.duotone ) {
ruleset += `${ selector } { filter: { ${ styles.filter.duotone }; }`;
}
This is how getFeatureDeclarations
extracts (and deletes) certain styles, and outputs them under a special selector, and how code for duotone extracts the filter.duotone
styles. The rest is left for the standard getStylesDeclarations
to handle.
To avoid the delete
mutation, we'd have to rewrite this logic. Like building an exclude list of already processed paths and passing it to getStylesDeclarations
.
We can continue cloning the styles object, but I think that cloning the entire tree
object is too much. We're mutating only the styles extracted by getNodesWithStyles
. So, it could be that function that clones the styles when calling nodes.push( { styles: clonedStyles } )
. The pickStyleKeys
could do the cloning.
This no longer appears to be broken in trunk. I'm going to close the PR but please reopen if your testing says differently! |
What?
Fixes an issue where duotone presets aren't properly being selected in the global styles filters panel, and maybe other things where the
GlobalStylesContext
is being used.Why?
In #49577 (comment), @youknowriad uncovered a bug where the duotone property was removed from the context in the duotone filters panel.
How?
The duotone property was being removed in
getFeatureDeclarations
which is needed fortoStyles
to work, so the entiremergedConfig
was cloned before calling it.Testing Instructions
styles.blocks['core/image].filter.duotone
set to one of the theme or default presets, for examplevar(--wp--preset--duotone--midnight)
.It might also be good to test some more of the blocks that use feature selectors via the
selectors
orsupports.feature.__experimentalSelector
block.json API.