-
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
Fixing broken layout styles for themes using theme.json settings on blocks that require layout styles #43925
Conversation
Oh, thanks for looking into a fix for this! (And apologies, I believe the issue was likely introduced in #43757 when I attempted to get the layout output to handle As a potential alternative, we could always update the check in Would it work to use a check like |
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 fixing this! Tested with a few blocks with custom theme.json settings and everything seems to be working fine. Might be good to add some tests to make sure the function still behaves as expected though.
It feels like the system should be less easy to break, getting an empty string instead of null in PHP is something to guard against - so this fix should fix the fact that invalid styles are output when the value to generate from is empty string. We should strive to return consistent types as well, but if |
I think it makes sense to do both things. |
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 follow-ups @matiasbenedetto, this is testing nicely for me! Also, adjusting the return type to null
looks reasonably safe to me, since the function is protected and is only used in the layout output and in compute_style_properties
where the null case is handled 👍
I tested that it resolves the issue with post content, and also tested with a variety of different values for simple and split (axial) block gap, and all appears to be working well for me.
Thanks for catching the 0
non-string value issue, too — since the UI will always save the 0
value as a string, I hadn't thought of hand-written themes using an integer value, so good to ensure that we don't accidentally cause issues for themes that explicitly set 0
.
I just left a totally optional comment about potentially grouping together the test cases into one, but feel free to ignore it, it's not at all a blocker. (Also, it looks like you've already fixed up that final test while I was typing out this comment 😀)
What?
The function
get_property_value
fromWP_Theme_JSON_6_1
class returns an empty string instead ofNULL
when a property is not set. So when we call this function to get the styles, of a block that needs layout settings, the block gap value is an empty string instead of null and that prevents that the value is fallback to the correct value.Let's see a example:
When Gutenberg calls
get_property_value
to get the layout styles of thecore/post-content
block, with$block_gap_value = static::get_property_value( $node, array( 'spacing', 'blockGap' ) )
,$block_gap_value
value is an empty string instead of NULL.This is causing that, for example, the default layout block gap value is not properly set forcore/post-content
block, ending in invalid CSS being rendered.Why?
Because returning an empty string is causing problems while rendering layout styles resulting in the rendering of invalid CSS. This problem is described in #43924.
How?
This PR makes
NULL
the default result ofget_property_value()
.If this looks like an acceptable solution for the problem probably I should add some PHP unit tests.
Testing Instructions
core/post-content
intheme.json
as TT3.Screenshots or screencast
Fixes: #43924