Skip to content

CSS nesting is broken in the fallback div.editor-styles-wrapper version of the editor. #65172

Closed

Description

@tcmulder

Description

When the editor falls back to the editor div rather than the new iframe, the .editor-styles-wrapper class scoping breaks CSS nesting, which is now supported in all major, modern browsers.

In the new iframe, for instance, I could write the following, which gets output exactly as it is written here, which works in modern browsers:

.some-parent {
	.some-child {
		color: purple;
	}
}

However, when this gets loaded into the .editor-styles-wrapper div and add_editor_style adds the scoping class, the result is this:

.editor-styles-wrapper .some-parent {
	.editor-styles-wrapper .some-child {
		color: purple;
	}
}

The child should not receive a scope, since .some-parent does not contain an element called .editor-styles-wrapper.

Step-by-step reproduction instructions

  1. Create a CSS file, e.g. css-nesting.css at the root of your theme.
  2. Add the following in that file:
.some-parent {
	.some-child {
		color: purple;
	}
}
  1. Add the following to functions.php.
add_action( 'after_setup_theme', function() {
	add_theme_support( 'editor-styles' );
	add_editor_style( '/css-nesting.css' );
} );
  1. Load a page that uses the old div.editor-styles-wrapper and view the source: you'll see the broken nesting in the <style> tag that gets created for scoping.

Note I'm not 100% sure how to force the old div.editor-styles-wrapper version to be used, but I've heard having a block registered with apiVersion equal to 2 in the blocks.json will trigger this behavior.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.6.1.
  • Basic Underscores theme.
  • No plugins active.

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

Activity

  1. added
    [Type] BugAn existing feature does not function as intended
    on Sep 9, 2024
  2. kubiqsk commented on Jul 24, 2025

    @kubiqsk

    Hi,
    did you find some tricky way how to fix this?
    I see it's almost 1 year and there is no reaction in here, despite it's a pretty serious bug...

  3. tcmulder commented on Jul 25, 2025

    @tcmulder
    Author

    I think this has been fixed. I now get:

    :where(.editor-styles-wrapper) .some-parent .some-child {
      color: purple;
    }

    in WordPress 6.8.1. That works.

    Also, it's much more common for the new iframe to load rather than the legacy div system these days, since far fewer block.json files for blocks are below version 3.

  4. kubiqsk commented on Jul 25, 2025

    @kubiqsk

    Not really, for me it's still not working, that's why I commented this thread in here...
    I had to do @import() in main CSS file to trick it, so it will not add any :where(.editor-styles-wrapper) anywhere...

    Eg.

    a.case-study-item{
    	overflow: hidden;
    	display: flex;
    	flex-direction: column;
    
    	.image{
    		position: relative;
    	}
    }

    will be

    :where(.editor-styles-wrapper) a.case-study-item{
    	overflow: hidden;
    	display: flex;
    	flex-direction: column;
    
    	:where(.editor-styles-wrapper) .image{
    		position: relative;
    	}
    }

    and that will not work for the .image class of course

  5. kubiqsk commented on Jul 25, 2025

    @kubiqsk

    Can you reopen this issue please? Or should I create a new one? Because it's really not solved...

  6. tcmulder commented on Jul 25, 2025

    @tcmulder
    Author

    Ah, you're right: my build tool was compiling the problem away. With my previous example, I'm now getting:

    :where(.editor-styles-wrapper) .some-parent {
    	:where(.editor-styles-wrapper) .some-child {
    		color: purple;
    	}
    }

    which is slightly different than before, but still problematic. I've not found a workaround beyond implementing a build tool (I'm using @wordpress/scripts) if my theme needs to support version 2 of block.json.

  7. USERSATOSHI commented on Jul 30, 2025

    @USERSATOSHI
    Contributor

    Reproduction Report

    Description

    This report validates whether the issue can be reproduced.

    Environment

    • WordPress: 6.9-alpha-60272
    • PHP: 8.2.28
    • Server: Apache/2.4.62 (Debian)
    • Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.28)
    • Browser: Chrome 138.0.0.0
    • OS: macOS
    • Theme: Twenty Eleven 4.9
    • MU Plugins:
      • Gutenberg Test Plugin, Disable Login Autofocus
      • Gutenberg Test Plugin, Disable Remote Patterns
      • Gutenberg Test Plugin, Enable Templates UI
      • Gutenberg Test Plugin, No-cache Headers
      • Gutenberg Test Plugin, Normalize Theme
      • server-timing.php
    • Plugins:
      • Gutenberg 21.3.0-rc.2
      • Test Reports 1.2.0

    Actual Results

    1. ✅ Error condition occurs (reproduced).

    Supplemental Artifacts

    Image Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Package] Block editor/packages/block-editor[Status] In ProgressTracking issues with work in progress[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