Skip to content

Block API: getBlockContent is adding extraneous divs #48139

@codebykat

Description

@codebykat

Description

This was introduced sometime between blocks package versions 11.20.0 and 12.4.0 (block-editor versions 10.4 and 11.4). Unfortunately because all packages need to be updated together (and we're also entangled in a React 17 to 18 upgrade which is interdependent with this upgrade), I can't easily try intermediate versions to narrow this down any further.

It is happening for all block types we're using (paragraphs, headings, etc).

Here is a test case that passes in 11.20.0 and fails in 12.4.0:

import { createBlock, getBlockContent } from "@wordpress/blocks";

describe("GB block content behavior", () => {
  beforeAll(() => {
    registerCoreBlocks();
  });

  it("Does not add extraneous divs to content", () => {
    const paragraphBlock = createBlock("core/paragraph", {
      content: "Some text",
    });
    expect(getBlockContent(paragraphBlock)).toEqual("<p>Some text</p>");
  });
});

Screen Shot 2023-02-16 at 13 35 30

Step-by-step reproduction instructions

  1. import { createBlock, getBlockContent } from "@wordpress/blocks";
  2. const paragraphBlock = createBlock(PARAGRAPH_BLOCK_ID, { content: "Some text", });
  3. getBlockContent(paragraphBlock);

Screenshots, screen recording, code snippet

No response

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

    Labels

    [Feature] Block APIAPI that allows to express the block paradigm.[Package] Blocks/packages/blocks[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions