Make WordPress Core


Ignore:
Timestamp:
05/11/2021 09:41:48 AM (3 years ago)
Author:
gziolo
Message:

Editor: Enqueue script and style assets only for blocks present on the page

Adds styles for individual core blocks to make it possible to render only styles for those blocks that are rendered on the page (frontend). This is optinal functionality for start that can be controlled with the new separate_core_block_assets filter.

In addition to that, styles can be inlined when path is passed when registering an individual styles. This functionality can be changed with the new styles_inline_size_limit filter. The maximum size of inlined styles in bytes defaults to 20 000.

Props aristath, aduth, westonruter, mcsf.
Fixes #50328, #52620.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r50287 r50836  
    421421        $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) );
    422422    }
     423
     424    /**
     425     * Tests that the main "style.css" file gets enqueued when the site doesn't opt-in to separate_core_block_assets.
     426     *
     427     * @ticket 50263
     428     */
     429    function test_common_block_styles_for_viewing_without_split_styles() {
     430        add_filter( 'separate_core_block_assets', '__return_false' );
     431        wp_default_styles( $GLOBALS['wp_styles'] );
     432
     433        $this->assertSame(
     434            $GLOBALS['wp_styles']->registered['wp-block-library']->src,
     435            '/' . WPINC . '/css/dist/block-library/style.css'
     436        );
     437    }
     438
     439    /**
     440     * Tests that the "common.css" file gets enqueued when the site opts-in to separate_core_block_assets.
     441     *
     442     * @ticket 50263
     443     */
     444    function test_common_block_styles_for_viewing_with_split_styles() {
     445        add_filter( 'separate_core_block_assets', '__return_false' );
     446        wp_default_styles( $GLOBALS['wp_styles'] );
     447
     448        $this->assertSame(
     449            $GLOBALS['wp_styles']->registered['wp-block-library']->src,
     450            '/' . WPINC . '/css/dist/block-library/style.css'
     451        );
     452    }
     453
     454    function test_block_styles_for_viewing_with_split_styles() {
     455        add_filter( 'separate_core_block_assets', '__return_true' );
     456        wp_default_styles( $GLOBALS['wp_styles'] );
     457
     458        $this->assertSame(
     459            $GLOBALS['wp_styles']->registered['wp-block-library']->src,
     460            '/' . WPINC . '/css/dist/block-library/common.css'
     461        );
     462    }
    423463}
Note: See TracChangeset for help on using the changeset viewer.