Skip to content

Blocks: Refactor dynamic blocks with HtmlRenderer component #74248

@t-hamano

Description

@t-hamano

See: #74228

What problem does this address?

Dynamic blocks using the ServerSideRender component have two extra divs:

  • The wrapper div with the blockProps applied
  • The div output by the RawHTML component
<div class="block-editor-block-list__block wp-block wp-block-test"> <!-- The wrapper div with the blockProps applied -->
    <div><!-- The div output by the RawHTML component -->
      <p class="wp-block-test">Dynamic block content</p>
    </div>
  </div>
</div>

These extra div elements may require special CSS overrides for the editor.

What is your proposed solution?

  • Use the HTMLRenderer component and useServerSideRender() hook to eliminate these extra divs and make the HTML on the front end and editor match. We can refer to the implementation of the Tag Cloud block.
  • If the block has any special CSS for the editor, we may be able to remove it.
  • Make sure the global styles work correctly in the editor as before.

Here are the blocks to work on:

Note that we don't have to address everything in one PR - address one block per PR and test carefully.

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