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 style updates #6959

Conversation

aaronrobertshaw
Copy link

This PR backports the changes from WordPress/gutenberg#63071

These changes include preloading the global styles REST API paths required to collect the global styles data for use in the block editor. This has two benefits:

  • Prevents a flash of style updates for block style variations in the post editor
  • Brings the post editor's preloaded paths a little more in line with the site editors

Test Instructions

  1. Active a theme that defines styles for the button outline block style variation e.g. TT4
  2. In the post editor add a button, select the Outline style, and save.
  3. Reload the post editor and ensure there is no flash of styling (i.e. from a solid color to the outline variant)
  4. In the site editor navigate to Styles > Blocks > Button > Outline
  5. Apply custom styles for the Outline block style variation e.g. change the border color, background etc.
  6. Save the Global Styles changes
  7. Switch back to the post editor, loading your earlier post with the button outline block
  8. When the editor loads there should be no flash of styling from the default theme outline styles to the custom styles assigned via Global Styles

Trac ticket: https://core.trac.wordpress.org/ticket/61553

Before After
Screen.Recording.2024-07-03.at.3.08.06.PM.mp4
Screen.Recording.2024-07-03.at.3.09.09.PM.mp4

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@aaronrobertshaw aaronrobertshaw self-assigned this Jul 3, 2024
Copy link

github-actions bot commented Jul 3, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props aaronrobertshaw, talldanwp, bgardner.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Jul 3, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I do still see a much briefer flash, but I assume that because a package update is needed to bring the JS changes from WordPress/gutenberg#63071. It's still better than in trunk.

As mentioned in the gutenberg PR, this brings consistency for the post and site editor in terms of theme/global styles preloading, so I think it's a good idea 👍

@aaronrobertshaw
Copy link
Author

I do still see a much briefer flash, but I assume that because a package update is needed to bring the JS changes from WordPress/gutenberg#63071. It's still better than in trunk.

That would be correct. Without the JS update, the global styles ID is loaded after another API request which isn't required when the ID is in the URL already.

The demo videos in the description illustrate the degree to which this is an improvement even without the JS update.

@bgardner
Copy link

bgardner commented Jul 6, 2024

Would love to see this merged prior to RC3 release. Think it is possible?

@aaronrobertshaw aaronrobertshaw force-pushed the fix/flash-of-variation-styles-in-post-editor branch from 98d3e22 to 244c37e Compare July 8, 2024 00:45
Copy link

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, too!

@@ -72,6 +72,9 @@ static function ( $classes ) {
sprintf( '%s/autosaves?context=edit', $rest_path ),
'/wp/v2/settings',
array( '/wp/v2/settings', 'OPTIONS' ),
'/wp/v2/global-styles/themes/' . get_stylesheet(),
'/wp/v2/themes?context=edit&status=active',
'/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this can be null?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the worst thing that can happen is that the path is invalid, it wouldn't cause a warning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a couple of days due to other priorities but I could tighten this up in a follow-up if needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still seeing a pretty significant flash right now, even with the code that was back-ported to RC3.

@ellatrix ellatrix closed this Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 participants