-
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
Modifying Class Names on Blocks Breaks Layouts #67134
Comments
Hi @pattyok, thank you for reporting this issue. I tried to reproduce this issue but it seems to be working fine for me. Here are the steps I followed:
The styles remained intact after the upgrade and editing. Looking into the code, I found in /* `is-image-fill` is deprecated and the styles are kept for backward compatibility. */ This indicates that while the class name has been updated to is-image-fill-element, WordPress maintains backward compatibility for the is-image-fill class to prevent layout breaks in older versions. For additional debugging, could you please provide: The specific CSS code you're using or any custom theme Let me know if you need any clarification or have additional information to share. |
cc @sgomes |
Hi @pattyok! I understand your frustration and would like to offer some context, and also whatever help you may need in crafting new CSS. As @himanshupathak95 mentioned, the previous styles are kept for backwards-compatibility, so it sounds like what happened was that the pages in question were edited, and were therefore upgraded to the new version of the block, which includes the new class name. The editor only "knows" how to save the current version of a block, so any time a page is edited, block markup is automatically upgraded to the new version, through the standard deprecations mechanism. Pages that were not edited should be working normally, and if they're not then please let us know, since that would definitely be unexpected behaviour. I understand your concerns regarding introducing new class names, and can assure you this was not done lightly. Changes were needed in order to fix performance issues with the block (see #52789 for the bug report), and adding a new class was necessary in order to avoid breaking existing pages, since the markup is fundamentally different between both versions of the block. If you're curious, you can follow this thread where the issue was discussed in more detail. As for this being done more or less invisibly, I understand where you're coming from, and agree it would be useful to be aware of these kinds of changes. I'll do some research into whether any mechanism already exists to make these block upgrades (and the need for validation) more obvious. If that mechanism doesn't exist, it sounds like something for which we could file a feature request! |
@pattyok : Is there any chance you could share what your goals were with customising the styles for the Media & Text block, or even share some sample CSS? I mention this because another approach we could also look at would be providing the customisation you need directly as part of the block options, so that CSS overrides wouldn't be necessary in the first place. |
@sgomes I build custom themes for my sites. We use the media text block extensively and I often use the various options provided on the block to build different style options. With the image-fill class I usually customize the padding/margins on each side separately and set my own default minimum height. One of the limitations of the media text block is that the padding/margin settings apply to the whole block and not to either side, which is what I want. Here is an example: https://eatlocalfirst.org/holiday-food-farm-finder/ I appreciate the idea in trying to offer everything in the block settings, but I also appreciate the consistency that I can get with setting the styles in the css vs the block settings. In building sites with the client editing experience in mind, I aim to make it easy for them to put blocks on the page and have them behave consistently. I should have learned my lesson by now that I can't rely on the markup from core blocks, but adding my own attributes/styles seems redundant especially in this case. |
Thank you for taking the time to explain your requirements so thoroughly, @pattyok! It sounds like the fundamental issue here is that It might be interesting to explore ways of communicating block options in markup in a more stable manner, although I'm not sure how often these class changes take place. Your reply makes it sound like this isn't the first time class changes have pulled the rug from under your feet? As for your requirements, thank you again for all the info! It does sound like we could consider some options around providing more fine-grained padding options for each side of the block. I do also understand your point regarding consistency without user overhead (i.e., not requiring users to go in and modify options on every block), and noticed your use of CSS custom properties to keep things consistent across your theme. If we were to enable the options you need at the block level at some point, then one possibility to consider would be setting up some patterns with your preferred settings, and guiding authors to that higher-level building block when building their pages. Or perhaps even better, setting up global styles for your theme, to have them applied automatically to all instances of the block. In any case, I'll share your feedback with the rest of the team, and see where we can go from there! |
I just want to chime in that this is definitely not the first time a core block class change has gone largely unmentioned in dev notes and it's very hard. For context, there are 13 plugins and 30 themes in the repository using these classes. I also use this in one plugin of my own and in my standard starter theme.
@sgomes In nearly all of my cases, customization options would not be helpful for me, because the point of the styles is to enforce various style changes that are baked into the site design. |
Thank you, @mrwweb, that's good feedback! I'm not sure how best to handle CSS class name changes going forward, but you're right that they weren't even mentioned in the dev notes in this case.
This is really interesting to know, and something I'd like to dig into a bit deeper, as being able to configure styling for all blocks of a given type is the main idea behind global styles. Is there some way we could make those better, to reduce the need to write custom CSS? |
Apologies for the confusion, I mistakenly linked an unrelated PR to this issue. |
Not speaking for @mrwweb, but in our case, adjustment of styling on blocks is treated as a bonus if it's allowed at all. We don't want our editors to fiddle around with the design in the editor, we want them to just use the pieces we've provided. In the specific case of this change, you could have avoided changing the class by adjusting the selector for the legacy styles to look for the background image: // Legacy versions of the block markup that use a background image
.wp-block-media-text.is-image-fill > .wp-block-media-text__media:where([style*="background-image"]) {
background-size: cover;
}
.wp-block-media-text.is-image-fill > .wp-block-media-text__media:where([style*="background-image"]) img {
// The image is visually hidden but accessible to assistive technologies.
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
// The new object-fit styles are unaffected by the above and will work exactly as written I'm not sure if it's too late to switch back to just using (Importantly, |
Very interesting, thank you @cbirdsong! Using I'm also not sure whether it's something we could switch to at this point. Do you have any idea, @Mamaduka?
I guess my specific question is: where adjustment is available (of course the point is moot if not), why do you prefer providing those pieces as CSS, rather than e.g. theme-level global styles, that editors could even easily override for a specific instance of a block if they so chose? Is there something lacking from global styles that we could improve to reduce the amount of CSS it takes to customise a theme, and particularly the need to rely on block implementation aspects such as option-related CSS class names? |
There are several reasons:
|
Similar to @cbirdsong's 1st point, when we get down to reasons I'm still writing CSS—while still embracing the block editor—it usually comes down to needing conditional styles.
Looking at the list of themes using it, I think it's similar:
Hope that's some useful context. |
Thank you both, @cbirdsong and @mrwweb, that's very useful information indeed! 👍 |
Description
With the release of 6.7, the class for cropped images on the Media Text Block changed from is-image-fill to is-image-fill-element. This totally breaks layouts in all of my sites where I have customized the styles of the media text block.
What makes is worse for a change like this is that the change isn't evident until someone goes in and edits a page. So I make the update, scan the site for issues and three days later the issue shows up on the home page. Changes to classnames on blocks should not be updated casually.
Logging as bug in the process. Class names should not be removed from existing blocks.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
Wordpress 6.7
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
The text was updated successfully, but these errors were encountered: