Skip to content
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

Section Styles: Prevent flash of variation styles in post editor #63071

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/compat/wordpress-6.6/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@ function gutenberg_register_wp_rest_themes_template_directory_uri_field() {
}
}
add_action( 'rest_api_init', 'gutenberg_register_wp_rest_themes_template_directory_uri_field' );

/**
* Preload theme and global styles paths to avoid flash of variation styles in post editor.
*
* @param array $paths REST API paths to preload.
* @param WP_Block_Editor_Context $context Current block editor context.
* @return array Filtered preload paths.
*/
function gutenberg_block_editor_preload_paths_6_6( $paths, $context ) {
if ( 'core/edit-post' === $context->name ) {
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
$paths[] = '/wp/v2/global-styles/themes/' . get_stylesheet();
$paths[] = '/wp/v2/themes?context=edit&status=active';
$paths[] = '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit';
}
return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_6', 10, 2 );
13 changes: 6 additions & 7 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,12 @@ export const __experimentalGetCurrentGlobalStylesId =
const globalStylesURL =
activeThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]
?.href;
if ( globalStylesURL ) {
const globalStylesObject = await apiFetch( {
url: globalStylesURL,
} );
dispatch.__experimentalReceiveCurrentGlobalStylesId(
globalStylesObject.id
);
if ( ! globalStylesURL ) {
return;
}
const id = +globalStylesURL.split( '/' ).pop();
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
if ( id ) {
dispatch.__experimentalReceiveCurrentGlobalStylesId( id );
}
};

Expand Down
Loading