mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@50836 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -270,6 +270,12 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( 'unit-tests-test-block-style', $result );
|
||||
$this->assertSame( 'replace', wp_styles()->get_data( 'unit-tests-test-block-style', 'rtl' ) );
|
||||
|
||||
// @ticket 50328
|
||||
$this->assertSame(
|
||||
wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block.css' ) ),
|
||||
wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,6 +372,12 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
|
||||
$this->assertSame( 'tests-notice-script', $result->script );
|
||||
$this->assertSame( 'tests-notice-editor-style', $result->editor_style );
|
||||
$this->assertSame( 'tests-notice-style', $result->style );
|
||||
|
||||
// @ticket 50328
|
||||
$this->assertSame(
|
||||
wp_normalize_path( realpath( DIR_TESTDATA . '/blocks/notice/block.css' ) ),
|
||||
wp_normalize_path( wp_styles()->get_data( 'unit-tests-test-block-style', 'path' ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -420,4 +420,44 @@ CSS;
|
||||
wp_common_block_scripts_and_styles();
|
||||
$this->assertTrue( wp_style_is( 'wp-block-library-theme' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the main "style.css" file gets enqueued when the site doesn't opt-in to separate_core_block_assets.
|
||||
*
|
||||
* @ticket 50263
|
||||
*/
|
||||
function test_common_block_styles_for_viewing_without_split_styles() {
|
||||
add_filter( 'separate_core_block_assets', '__return_false' );
|
||||
wp_default_styles( $GLOBALS['wp_styles'] );
|
||||
|
||||
$this->assertSame(
|
||||
$GLOBALS['wp_styles']->registered['wp-block-library']->src,
|
||||
'/' . WPINC . '/css/dist/block-library/style.css'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the "common.css" file gets enqueued when the site opts-in to separate_core_block_assets.
|
||||
*
|
||||
* @ticket 50263
|
||||
*/
|
||||
function test_common_block_styles_for_viewing_with_split_styles() {
|
||||
add_filter( 'separate_core_block_assets', '__return_false' );
|
||||
wp_default_styles( $GLOBALS['wp_styles'] );
|
||||
|
||||
$this->assertSame(
|
||||
$GLOBALS['wp_styles']->registered['wp-block-library']->src,
|
||||
'/' . WPINC . '/css/dist/block-library/style.css'
|
||||
);
|
||||
}
|
||||
|
||||
function test_block_styles_for_viewing_with_split_styles() {
|
||||
add_filter( 'separate_core_block_assets', '__return_true' );
|
||||
wp_default_styles( $GLOBALS['wp_styles'] );
|
||||
|
||||
$this->assertSame(
|
||||
$GLOBALS['wp_styles']->registered['wp-block-library']->src,
|
||||
'/' . WPINC . '/css/dist/block-library/common.css'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user