• When working with GenerateBlocks, I expect the Block Editor to work like full site editing, almost completely identical to what I see on the frontend. The team is doing a great job with this, but there are still many small differences that hurts the experience.

    I’ve submitted one or more issues and potential fixes to the repo (GenerateBlocks and/or GeneratePress) before they was changed to private, and I also have many private fixes in my child theme.

    One recent issue that I found is that when using official Heading and Paragraph blocks, they are centered by default because of the auto margins on each block added by WP default styles. However, on the frontend, those styles are either dequeued or overridden by GB/GP, which causes inconsistency. See the Editor and Frontend differences:

    The specific issue here is that WP is registering and adding classic.css called “wp-editor-classic-layout-styles” as a dependency here, because the theme that I’m using (GeneratePress) does not have theme.json file.

    As classic.css is never added to the frontend (at least with a GP+GB setup), that file should not be added to the dependencies either, as it just causes inconsistent layouts and I already have custom Editor CSS fixes just because of that file.

    If it does not cause any unexpected side effects, I think either GP should add that theme.json just to prevent this file to be added or GB should remove it as a dependency – at least with GP+GB setups.

    The latter is a bit complicated, but I was tired of CSS fixes so found this solution:

    add_action( 'enqueue_block_editor_assets', function() {
    // Remove classic layout styles (inconsistency, not present in frontend)
    wp_dequeue_style( 'wp-editor-classic-layout-styles' );
    wp_deregister_style( 'wp-editor-classic-layout-styles' );

    // Re-register editor styles, as 'wp-editor-classic-layout-styles' was a dependency (missing theme.json)
    // See: https://github.com/WordPress/wordpress-develop/blob/6.9/src/wp-includes/script-loader.php#L1709-L1740
    $suffix = SCRIPT_DEBUG ? '' : '.min';
    // Original dependencies
    $wp_edit_blocks_dependencies = array(
    'wp-components',
    /*
    * This needs to be added before the block library styles,
    * The block library styles override the "reset" styles.
    */
    'wp-reset-editor-styles',
    'wp-block-library',
    'wp-block-editor-content',
    );
    wp_deregister_style( 'wp-edit-blocks' ); // Deregister because previously was registered with 'wp-editor-classic-layout-styles' as a dependency
    wp_register_style(
    'wp-edit-blocks',
    "/wp-includes/css/dist/block-library/editor$suffix.css",
    $wp_edit_blocks_dependencies
    );
    } );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support ying

    (@yingscarlett)

    Hi there,

    Thanks for reaching out!

    However, I’m not able to replicate the issue in my editor. The WP heading block is not centered by default in the editor even with the margin-inline set to auto.

    Here’s a screenshot for your reference: https://app.screencast.com/4ZBfHPijDZnGU

    Can you check what the display being set for the heading blocks in the editor?

    Thread Starter frzsombor

    (@frzsombor)

    Hi @yingscarlett

    Sorry, I missed one important info: the issue is happening, when a native Heading or Paragraph block is added to a GenerateBlocks Container block, which is set to display: flex.

    It is not a huge bug, just a small inconsistency. And I’m wondering if we even need those classic.css styles in the editor if they are not even present on the frontend.

    George

    (@quantum_leap)

    Hello,

    GenerateBlocks explicitly sets margin-left: 0 and margin-right: 0 on its own blocks, which overrides the classic.css styles. Core blocks don’t have that override, so they keep the margin-left: auto and margin-right: auto from classic.css — which centers them inside a flex container.

    Rather than deregistering classic.css entirely (which could cause other editor styling issues), it might be safer to just override the specific problematic styles in your editor CSS:

    .gb-container[style=”flex”] > .wp-block-heading,
    .gb-container[style=”flex”] > .wp-block-paragraph {
    margin-left: 0;
    margin-right: 0;
    }

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.