-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block editor: separate content styles for the iframe #44298
Conversation
Size Change: -4.18 kB (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
bc7d529
to
1d48fff
Compare
lib/experimental/content-assets.php
Outdated
|
||
$script_handles = array(); | ||
$style_handles = array( | ||
'wp-edit-blocks', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has been taken over exactly from core, except for the removal of the wp-block-editor
dependency and also wp-block-library
that is a dependency of wp-edit-blocks
.
gutenberg/lib/compat/wordpress-6.0/client-assets.php
Lines 38 to 112 in 749e412
/** | |
* Sets the editor styles to be consumed by JS. | |
*/ | |
function gutenberg_resolve_assets() { | |
global $pagenow; | |
$script_handles = array(); | |
$style_handles = array( | |
'wp-block-editor', | |
'wp-block-library', | |
'wp-edit-blocks', | |
); | |
if ( current_theme_supports( 'wp-block-styles' ) ) { | |
$style_handles[] = 'wp-block-library-theme'; | |
} | |
if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { | |
$style_handles[] = 'wp-widgets'; | |
$style_handles[] = 'wp-edit-widgets'; | |
} | |
$block_registry = WP_Block_Type_Registry::get_instance(); | |
foreach ( $block_registry->get_all_registered() as $block_type ) { | |
if ( ! empty( $block_type->style ) ) { | |
$style_handles[] = $block_type->style; | |
} | |
if ( ! empty( $block_type->editor_style ) ) { | |
$style_handles[] = $block_type->editor_style; | |
} | |
if ( ! empty( $block_type->script ) ) { | |
$script_handles[] = $block_type->script; | |
} | |
} | |
$style_handles = array_unique( $style_handles ); | |
$done = wp_styles()->done; | |
ob_start(); | |
// We do not need reset styles for the iframed editor. | |
wp_styles()->done = array( 'wp-reset-editor-styles' ); | |
wp_styles()->do_items( $style_handles ); | |
wp_styles()->done = $done; | |
$styles = ob_get_clean(); | |
$script_handles = array_unique( $script_handles ); | |
$done = wp_scripts()->done; | |
ob_start(); | |
wp_scripts()->done = array(); | |
wp_scripts()->do_items( $script_handles ); | |
wp_scripts()->done = $done; | |
$scripts = ob_get_clean(); | |
return array( | |
'styles' => $styles, | |
'scripts' => $scripts, | |
); | |
} | |
add_filter( | |
'block_editor_settings_all', | |
function( $settings ) { | |
// In the future we can allow WP Dependency handles to be passed. | |
$settings['__unstableResolvedAssets'] = gutenberg_resolve_assets(); | |
return $settings; | |
} | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be moved to gutenberg/lib/compact/wordpress-6.2/script-loader.php
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess? I'm not familiar with the new structure for PHP code. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. Do you expect any changes/breakage based on this change?
lib/experimental/content-assets.php
Outdated
|
||
$script_handles = array(); | ||
$style_handles = array( | ||
'wp-edit-blocks', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be moved to gutenberg/lib/compact/wordpress-6.2/script-loader.php
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some styles in BlockPreview that should go into the "content" styles. Like the ones targeting block-editor-block-preview__content-iframe
9ccd60a
to
290a0ca
Compare
Moved them also to a content stylesheet. |
Hi @ellatrix ! This PR seems to break the styles of the block toolbar when dragged (I can't provide a screenshot 😅 ) It's missing it's dark background and white text color |
@corentin-gautier Seems to have been removed by accident! Restored in #46396. |
$style_handles = array_merge( | ||
$style_handles, | ||
$block_type->style_handles, | ||
$block_type->editor_style_handles | ||
); | ||
|
||
$script_handles = array_merge( | ||
$script_handles, | ||
$block_type->script_handles | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellatrix We think that this code is causing a fatal error in WordPress 6.0 with the latest version of the Gutenberg plugin. 🤔
Since these block_type->style_handles
, etc. properties were added in WordPress 6.1, this code becomes array_merge( $style_handles, NULL, NULL )
, which throws a warning in PHP <8, but a fatal error in PHP 8.
I have a fix here: #46488, which just checks for null values, but just a heads up in case further work is needed to support 6.0 here
…_assets() and wp_default_styles(). This changeset: * Removes the `'wp-block-editor'` and `'wp-block-library'` from the iframe's stylesheet collection (i.e. `_wp_get_iframed_editor_assets()`). * Adds the new `'wp-block-editor-content'` for the separate stylesheet to the list of editor (`'wp-edit-blocks'`) dependencies. Why? These PHP changes are part of the initiative to: * Separate the content styles contained in the block editor package into a separate stylesheet. * Avoid loading all block editor styles into the iframe. References: * [WordPress/gutenberg#44298 Gutenberg PR 44298]. Follow-up to [53160], [50761]. Props ellatrix, youknowriad. Fixes #57550. git-svn-id: https://develop.svn.wordpress.org/trunk@55179 602fd350-edb4-49c9-b593-d223f7449a82
…_assets() and wp_default_styles(). This changeset: * Removes the `'wp-block-editor'` and `'wp-block-library'` from the iframe's stylesheet collection (i.e. `_wp_get_iframed_editor_assets()`). * Adds the new `'wp-block-editor-content'` for the separate stylesheet to the list of editor (`'wp-edit-blocks'`) dependencies. Why? These PHP changes are part of the initiative to: * Separate the content styles contained in the block editor package into a separate stylesheet. * Avoid loading all block editor styles into the iframe. References: * [WordPress/gutenberg#44298 Gutenberg PR 44298]. Follow-up to [53160], [50761]. Props ellatrix, youknowriad. Fixes #57550. Built from https://develop.svn.wordpress.org/trunk@55179 git-svn-id: http://core.svn.wordpress.org/trunk@54712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…_assets() and wp_default_styles(). This changeset: * Removes the `'wp-block-editor'` and `'wp-block-library'` from the iframe's stylesheet collection (i.e. `_wp_get_iframed_editor_assets()`). * Adds the new `'wp-block-editor-content'` for the separate stylesheet to the list of editor (`'wp-edit-blocks'`) dependencies. Why? These PHP changes are part of the initiative to: * Separate the content styles contained in the block editor package into a separate stylesheet. * Avoid loading all block editor styles into the iframe. References: * [WordPress/gutenberg#44298 Gutenberg PR 44298]. Follow-up to [53160], [50761]. Props ellatrix, youknowriad. Fixes #57550. Built from https://develop.svn.wordpress.org/trunk@55179 git-svn-id: https://core.svn.wordpress.org/trunk@54712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…_assets() and wp_default_styles(). This changeset: * Removes the `'wp-block-editor'` and `'wp-block-library'` from the iframe's stylesheet collection (i.e. `_wp_get_iframed_editor_assets()`). * Adds the new `'wp-block-editor-content'` for the separate stylesheet to the list of editor (`'wp-edit-blocks'`) dependencies. Why? These PHP changes are part of the initiative to: * Separate the content styles contained in the block editor package into a separate stylesheet. * Avoid loading all block editor styles into the iframe. References: * [WordPress/gutenberg#44298 Gutenberg PR 44298]. Follow-up to [53160], [50761]. Props ellatrix, youknowriad. Fixes #57550. Built from https://develop.svn.wordpress.org/trunk@55179 git-svn-id: http://core.svn.wordpress.org/trunk@54712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
Related: #37466.
Separates the content styles contained in the block editor package into a separate style sheet.
Why?
We shouldn't be loading all block editor styles in the iframe.
How?
Testing Instructions
Screenshots or screencast