Skip to content

Media Queries applied to blocks custom css are not working in gutenberg >=16.8.0 #55318

@jeflopodev

Description

@jeflopodev

Description

I have a query pagination that looks like this:
image
I opted to hide the pagination numbers with a media query applied as custom CSS in the core/query-pagination-numbers block style.

@media screen and (max-width: 599px) {
  & .page-numbers {
    display: none;
  }
}

But after updating gutenberg from 16.7.1 to 16.8.0 (and 16.8.1 now) I noted that my query pagination numbers were also hidden on higher resolutions with a display: none applied.
image

image

This is in theme.json in styles.blocks.core/query-pagination-numbers.css

"css": "& .page-numbers.current { padding: .5rem .7rem; border-radius: .25rem; color: var(--wp--preset--color--query-pagination-numbers-current-contrast); background-color: var(--wp--preset--color--query-pagination-numbers-current-base); } & .page-numbers.dots { padding: .5rem .6rem; border-radius: .25rem; color: var(--wp--preset--color--query-pagination-numbers-dots-contrast); background-color: var(--wp--preset--color--query-pagination-numbers-dots-base); } @media screen and (max-width: 599px) { & .page-numbers { display: none; } }",

It's like the media query fragment is completely ignored, bypassed. But not it's CSS inside that's still applied without resolution constraints.

To demonstrate it, I changed the media query code to @media screen and (max-width: 599px) { & .page-numbers { color: #f00; } }

image

And as you can see, that css inside the media query is still being applied in a 1024 resolution.

The theme is custom, made by me... But since it's working on 16.7.1 and only failed when I updated to 16.8.0 I guess it's either gutenberg failing or a change that I'm not aware of. For that, I've thoroughtly checked the release notes from 16.7.1 to 16.8.0 and I found nothing that made me think anything has changed.

It's also happening on my navigation menu, that's the only other part where I'm using media queries. Can be seen in the video below.

Oh, and everything was "tested" with CTRL + F5 for refreshing and:

define( 'WP_DEBUG', true );
define( 'SCRIPT_DEBUG', true );
define( 'WP_DEVELOPMENT_MODE', 'theme' );

Step-by-step reproduction instructions

  1. Use gutenberg 16.8.0
  2. Define a media query with custom CSS in a block style.
  3. Check if the media query is being ignored, but it's css still being applied without resolution constraints.

Screenshots, screen recording, code snippet

This video shows how it work on gutenberg 16.7.1 but doesn't properly work in 16.8.0, and how the styles within the media query are still being applied without resolution constraints.

2023-10-12.18-34-33.mp4

Environment info

WordPress 6.4-beta3-56831
Gutenberg 16.7.1 & 16.8.0
Custom theme
Google Chrome 117.0.5938.150 (Build oficial) (64 bits) (cohort: Stable)
Windows 11 Version 21H2 (Build 22000.2538)

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSS StylingRelated to editor and front end styles, CSS-specific issues.Good First IssueAn issue that's suitable for someone looking to contribute for the first time[Feature] Custom Editor StylesFunctionality for adding custom editor styles[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions