-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 styles declarations returning before all properties output #42954
Conversation
Size Change: +102 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
if ( | ||
( key === '--wp--style--root--padding' && | ||
typeof styleValue === 'string' ) || | ||
! useRootPaddingAlign |
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.
For this condition, is it possible that more declarations will be skipped than desired if ! useRootPaddingAlign
evaluates to true
? I was wondering if the condition is meant to be just for the --wp--style--root--padding
key, like:
if (
key === '--wp--style--root--padding' &&
( typeof styleValue === 'string' || ! useRootPaddingAlign )
) {
return declarations;
}
Apologies if I'm not understanding the logic here correctly!
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.
It looks like fontFamily
is one of the few ones that isn't using the style engine, so I found it a little challenging to work out an error state for this one, but I think the following test seems to catch it:
it( 'Should output padding and font family properties if useRootPaddingAwareAlignments is disabled', () => {
const blockStylesWithFontFamily = {
...blockStyles,
typography: {
fontFamily: 'sans-serif',
},
};
expect(
getStylesDeclarations(
blockStylesWithFontFamily,
'body',
false
)
).toEqual( [
'font-family: sans-serif',
'background-color: var(--wp--preset--color--light-green-cyan)',
'padding-top: 33px',
'padding-right: 33px',
'padding-bottom: 33px',
'padding-left: 33px',
] );
} );
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.
Oh, I've found a better real world example with the Duotone feature. In TwentyTwentyTwo, if you add the following to the theme.json
file (from #37727) to switch on a particular Duotone for image blocks:
{
"styles": {
"blocks": {
"core/image": {
"filter": {
"duotone": "var(--wp--preset--duotone--foreground-and-secondary)"
}
}
}
}
}
Expected | Actual |
---|---|
The above change appears to fix 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.
Oh, good catch! Yes, the parentheses should be around the OR as you suggested 😄
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.
Nice work figuring out this one @tellthemachines (and for adding additional tests 🎉 )! Skipping the output in the loop over extraRules
looks like a good approach to me 👍. I just left a comment about the condition to skip the variable output, as it looks like it might be unexpectedly returning early.
Aside from that though, this is otherwise testing nicely for me manually in the site editor with TwentyTwentyTwo and Emptytheme and resolves the issue with color output.
if ( | ||
( key === '--wp--style--root--padding' && | ||
typeof styleValue === 'string' ) || | ||
! useRootPaddingAlign |
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.
It looks like fontFamily
is one of the few ones that isn't using the style engine, so I found it a little challenging to work out an error state for this one, but I think the following test seems to catch it:
it( 'Should output padding and font family properties if useRootPaddingAwareAlignments is disabled', () => {
const blockStylesWithFontFamily = {
...blockStyles,
typography: {
fontFamily: 'sans-serif',
},
};
expect(
getStylesDeclarations(
blockStylesWithFontFamily,
'body',
false
)
).toEqual( [
'font-family: sans-serif',
'background-color: var(--wp--preset--color--light-green-cyan)',
'padding-top: 33px',
'padding-right: 33px',
'padding-bottom: 33px',
'padding-left: 33px',
] );
} );
@andrewserong thanks for reviewing and kindly providing the extra test! I fixed the issue, and added font-family to the initial block styles in the test, so now we can check that it gets output on all three tests. |
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.
@tellthemachines, @andrewserong, @andrewserong would this be a candidate for a 13.8.x release? The root issue is impacting quite a range of things. I just discovered that some theme.json style settings are not getting output, notably those for template parts. With this fix, everything now works like a charm. |
@ndiego it's not a huge change so should be fine to add to the next minor release, yes! |
What?
Fixes #42913.
Why?
When
useRootPaddingAwareAlignments
is set,getStylesDeclarations
returns before all the global style properties are output. This means colour changes in global styles aren't reflected in the editor.How?
Change the function logic so it only omits
padding
properties whenuseRootPaddingAwareAlignments
is enabled, as well as not outputting the variables if the setting is disabled.Adds tests to check for correct behaviour.
Testing Instructions
"useRootPaddingAwareAlignments": true
;"useRootPaddingAwareAlignments"
back tofalse
;.editor-styles-wrapper
, but not both.Screenshots or screencast