-
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
Section styles are stripped out of query loops #65644
Comments
I added this to the 6.7 board as it feels important to fix this before the release. |
I've started digging into this one but don't yet have a full explanation or possible solution. It appears the issue has been around for quite a while and also impacts block instance element and layout styles in addition to section styles. Here's an earlier issue where the problem with element styles was raised: #63606. If looking at the right area, the problem is that posts to be displayed by the Query Loop (and therefore Post Template) are retrieved via a REST API call. The response for that includes rendered content that has already had filters for Those filters are what the element, layout, and block style variation (section styles) supports use to apply classnames and enqueue additional stylesheets. The additional stylesheets aren't included in the API response and as such aren't loaded on the editor page. If the content received and rendered within Post Template isn't treated as blocks, then the editor's JS hooks also won't run and create appropriate style overrides. While I can partially explain the bug I'm coming up empty on an appropriate solution. I'm happy to explore any ideas people might have 🙏 |
This was raised during the dev-chat earlier. Would someone be able to post some reproduction steps for the issue? Until recently, Global Styles weren't shown in the post editor -- see https://core.trac.wordpress.org/ticket/62042 -- so I am wondering if this is a similar problem. |
Yes, related to this and the problem with the element styles is that the group block grid is also missing CSS when displayed in the post content. |
Check out Twenty Twenty-Five, or use the version bundled with the beta. Now author some content that uses section styles. Example in a GIF, steps outlined below:
Now you can go to the site editor, or any place with a query loop, and you'll see the section style missing: |
Thanks for weighing in @peterwilsoncc 👍
I don't think this is related. That was a problem with non-admin users not having access to the Global Styles CPT data. This is an issue for all users due to the Post Content block only rendering the After some further digging today and conversations with @andrewserong, here's what I've found. There was a previous attempt to solve this issue in #35863. That approach was blocked due to some concerns rendering the raw blocks in previews might expose private block data that shouldn't be. One short-term idea for 6.7 could be to compromise here and render the raw blocks when the current user has the I'll try and at least get a PoC up for this compromise tomorrow unless better ideas surface before then. FWIW hacking around bringing in changes from #35863 shows it does still render block support styles correctly.
Regarding the concerns on exposing private content, I'm not sure I fully understand the issue enough. The Post Content block retrieves a post's Is the problem that there could be a filter running server side that would normally block a user's access to a particular post or something within it? If that's the case, shouldn't that also be applied to the content returned in the REST API response? The only other alternative would appear to be retrieving block support styles from the style engine context/store as well as cc/ @ntsekouras and @youknowriad in case you have any thoughts, or buried memories, given your involvement on #35863 |
In addition to @jasmussen's steps for section styles, you can also encounter the problem by applying element styles or using a Row block.
Example block markup for post when testing with TT5<!-- wp:group {"className":"is-style-section-4","style":{"spacing":{"padding":{"right":"var:preset|spacing|40","left":"var:preset|spacing|40","top":"var:preset|spacing|40","bottom":"var:preset|spacing|40"}}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group is-style-section-4" style="padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)"><!-- wp:group {"style":{"layout":{"columnSpan":1,"rowSpan":1}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group"><!-- wp:paragraph {"style":{"elements":{"link":{"color":{"text":"#29c8f8"}}}}} -->
<p class="has-link-color">Welcome to <a href="http://www.wordpress.org">WordPress</a>. This is your first post. Edit or delete it, then start writing! Welcome to WordPress. </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"style":{"elements":{"link":{"color":{"text":"#3ee732"}}}}} -->
<p class="has-link-color">Welcome to WordPress. This is your first post. Edit or delete it, then start writing! Welcome to <a href="http://wordpress.org">WordPress</a>. </p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:buttons {"style":{"layout":{"columnSpan":2,"rowSpan":1}},"layout":{"type":"flex","justifyContent":"center"}} -->
<div class="wp-block-buttons"><!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons --></div>
<!-- /wp:group --> Using the above example:
|
I have a tentative short-term fix up in #66003. While it might not be perfect, it definitely minimises this issue for WP6.7 and TT5's release. If there's consensus that it is safe enough, it would be good to land sooner rather than later so it can get some broader testing during the beta/RC phase. |
Thanks Aaron, will test now. I would encourage anyone else subscribed to take a look at the PR to see if it threads the needle. It would be very good for Twenty Twenty-Five that this land in 6.7, as it comes with 6 section styles for patterns, and having those work only in permalinks makes it lose a lot of the flavor. |
The fix in #66003 has been merged so I'll close this one out. |
Excellent follow up here! |
If you create and apply a section style to a pattern or group of blocks, this section style shows up in post and page editors, and on the frontend, correctly:
However in the site editor when viewing the post through a query loop in the Blog Home template, the section style is not applied:
This is the query loop:
In the "Content" block I would expect the section style to not be stripped away.
The text was updated successfully, but these errors were encountered: