Skip to content

Style hooks - default values cause extra wrappers and block errors in editor for standard blocks. #24387

Closed

Description

@Addison-Stavlo

Describe the bug
Semi-related to #24363.

Style hooks seem to be written with the intent to support default styles to be defined on the block- ex:

// allow blocks to specify their own attribute definition with default values if needed.
if ( ! settings.attributes.backgroundColor ) {
Object.assign( settings.attributes, {
backgroundColor: {
type: 'string',
},
} );

However, in practice this seems to not play nice in the editor. With standard blocks (reproduced with Paragraph and Heading), default styles add extra wrappers in the editor and can break the blocks.

To reproduce

Below I will explore this with a standard block, "Paragraph".

  1. Add the following to attributes in Paragraph's block.json file:
		"textColor": {
			"type": "string",
			"default": "secondary"
		},
		"backgroundColor": {
			"type": "string",
			"default": "primary"
		},
		"fontSize": {
			"type": "string",
			"default": "large"
		}
  1. Load the editor and add/edit a new paragraph. It should have the default values as expected:
    Screen Shot 2020-08-05 at 1 02 16 PM

  2. Select custom values for the fontSize, backgroundColor, and textColor and save:
    Screen Shot 2020-08-05 at 1 03 57 PM

  3. Reload the editor, notice the block has a different size and indentation:
    Screen Shot 2020-08-05 at 1 04 38 PM

Inspecting the element reveals that there is a <p> element nested inside the Paragraph wrapper:
Screen Shot 2020-08-05 at 1 06 07 PM

  1. Try changing to a different custom background color for the block. Notice the background is only applied to outer wrapper:
    Screen Shot 2020-08-05 at 1 07 56 PM

  2. Save and reload the editor, you may find the block has broken:
    Screen Shot 2020-08-05 at 1 08 41 PM

Expected behavior
Expected to not have a second wrapper and broken block.

Activity

  1. Addison-Stavlo commented on Aug 5, 2020

    @Addison-Stavlo
    ContributorAuthor

    FYI @youknowriad (not to be confused with #24363)

  2. youknowriad commented on Aug 6, 2020

    @youknowriad
    Contributor

    This only applies to paragraphs right?

    To support p-less paragraph blocks we have a "deprecated" version for the paragraph block used to auto-add the p wrapper. I think that's probably what's causing the double paragraphs here. I saw in the past that this deprecated version of paragraph block caused other similar issues (double p), so I wonder if we can rework it and try to apply it only when we detect p-less paragraphs.

  3. Addison-Stavlo commented on Aug 6, 2020

    @Addison-Stavlo
    ContributorAuthor

    This only applies to paragraphs right?

    It seems to be the case with the heading block as well. I haven't tested beyond those two currently.

  4. youknowriad commented on Aug 10, 2020

    @youknowriad
    Contributor

    It seems to be the case with the heading block as well. I haven't tested beyond those two currently.

    In that case, it's a different story independent with the "p -less" deprecation.

  5. added
    [Feature] Custom Editor Styles
    [Type] Bug
    on Sep 2, 2020
  6. annezazu commented on Sep 2, 2020

    @annezazu
    Contributor

    Just an FYI that I did the best I could to label this but if others have a better possible label, please update!

  7. added
    [Feature] Parsing
    on Nov 26, 2025
  8. youknowriad commented on Oct 15, 2026

    @youknowriad
    Contributor

    I retested this on WordPress 7.1.2 with Gutenberg trunk (late July 2026). I gave Paragraph and Heading default textColor, backgroundColor and fontSize values, set custom values, changed the background again, and round-tripped the content through save/parse. Every round trip produced a single valid <p>/<h2> with the expected classes, with no nested wrapper and no invalidation. Closing as no longer reproducible; if you can still trigger the double wrapper, please reopen with the attribute setup you used.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Custom Editor Styles[Feature] Parsing[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions