close
Skip to content

FSE script into iframe insertion needs to be less restrictive on how it determines whether to include a stylesheet  #42509

@albanyacademy

Description

@albanyacademy

Description

In the Site Editor, Block CSS should be included without needing to use wp-block as a CSS selector in the built stylesheet, it should be included in the iframe by virtue of it being registered through enqueue_block_assets.

My suggestion would be to add to enqueue_block_assets a data-attr/some "block asset" identifier to just scan for instead, because whether or not the right selectors are in the stylesheet shouldn't be the sole criteria for including it in the FSE.

Step-by-step reproduction instructions

  1. Build a bunch of blocks with separate editor and generic stylesheets
  2. Don't use ".wp-block" as the main classname/selector for your custom blocks.
  3. Go into FSE and use your custom blocks
  4. Observe that their styles are not included inside the iframe.

Screenshots, screen recording, code snippet

Specifically this section:
https://github.com/WordPress/gutenberg/blob/0a6a23b213c4fe9e3b337c8b71fa87bbf82c4496/packages/block-editor/src/components/iframe/index.js

function matchFromRules( _cssRules ) {
				return Array.from( _cssRules ).find(
					( {
						selectorText,
						conditionText,
						cssRules: __cssRules,
					} ) => {
						// If the rule is conditional then it will not have selector text.
						// Recurse into child CSS ruleset to determine selector eligibility.
						if ( conditionText ) {
							return matchFromRules( __cssRules );
						}

						return (
							selectorText &&
							( selectorText.includes(
								`.${ BODY_CLASS_NAME }`
							) ||
								selectorText.includes( `.${ BLOCK_PREFIX }` ) )
						);
					}
				);
			}

			const isMatch = matchFromRules( cssRules );

Environment info

No response

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions