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

Site Editor: restore block-library editor.css outside canvas #66556

Merged
merged 3 commits into from
Oct 30, 2024

Conversation

ellatrix
Copy link
Member

What?

In #66544 @t-hamano observed that a bit too many styles have been removed in #66432. Indeed, it should have kept loading editor.css files defined by blocks because they target both content and UI outside the canvas. The remaining styles should still be removed though.

One light problem is that all the styles we want to remove are added as dependencies of wp-edit-blocks. So restoring wp-edit-blocks will add back all the styles we don't want. To fix the issue we can register a separate handle wp-block-library-editor, which exclusively loads the editor styles.

Why?

Fix a regression from #66432.

How?

Testing Instructions

In content only mode, select an image and click the "alternative text" button in the toolbar.

Testing Instructions for Keyboard

Screenshots or screencast

@ellatrix ellatrix added the [Type] Regression Related to a regression in the latest release label Oct 29, 2024
Copy link

github-actions bot commented Oct 29, 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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <[email protected]>
Co-authored-by: t-hamano <[email protected]>

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

@t-hamano
Copy link
Contributor

This PR works for me.

My only concern is that deleting wp-edit-blocks or changing the handle name would be a breaking change. For example, block developers might apply their own styles to block sidebars, etc. with code like this:

wp_enqueue_style(
	'my-block-common',
	'path/to/block-common.css'
	array( 'wp-edit-blocks' )
);

I searched the WP Directory and it seems that a lot of plugins enqueue styles that depend on the wp-edit-blocks handle.

https://wpdirectory.net/search/01JBC821K2ZBFBMPF7QQSP7W8K

@t-hamano t-hamano added the [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") label Oct 29, 2024
@ellatrix
Copy link
Member Author

@t-hamano

  1. Using wp-edit-blocks will still work. It's used in the canvas. So if you add dependencies to wp-edit-blocks, it should still work.
  2. Blocks should never add wp-edit-blocks as a dependency. It should be the opposite: wp-edit-blocks should contain all the blocks' style sheets as dependencies.

@ellatrix
Copy link
Member Author

What I mean is: nothing about wp-edit-blocks changes. It's all still there.

@t-hamano
Copy link
Contributor

t-hamano commented Oct 29, 2024

Using wp-edit-blocks will still work. It's used in the canvas.

If developers are adding a wp-edit-blocks handle to a dependency to enqueue a style outside of the canvas, the style won't be loaded outside of the canvas (root document), right?

Relying on wp-edit-blocks to apply styles outside of the canvas may not be a recommended use case, but I thought some dev notes might be needed.

@ellatrix
Copy link
Member Author

@t-hamano I'm not sure I understand. Do you mean:

  • Someone adds wp-edit-blocks as a dependency to their style? Even in trunk, this will not make it load outside the canvas.

Or:

  • Someone adds their style as a dependency to wp-edit-blocks? Indeed, then the style will not load. But it's generally hard to to change the dependencies of a handle that you did not create (in this case wp-edit-blocks). How would this be done?

@t-hamano
Copy link
Contributor

Sorry, maybe I misunderstood. I don't think this PR is a breaking change. Let me explain a bit more.

  • In trunk, the style with a handle wp-edit-blocks is not loaded outside of the canvas.
  • A third-party developer tries to apply a style outside of the canvas via code like this:
    function my_enqueue_block_editor_assets() {
      wp_enqueue_style(
    		'my-block-style',
    		plugin_dir_url( __FILE__ ) . 'style.css',
    		array( 'wp-edit-blocks' )
    	);
    }
    add_action( 'enqueue_block_editor_assets', 'my_enqueue_block_editor_assets' );
    • What I misunderstood: their style will be not loaded outside of the canvas.
    • Actual: Both the styles with the handle wp-edit-blocks and their styles are loaded outside of the canvas.

Is my understanding correct?

Also, if we go ahead with this PR, do we also need a backport PR to core?

@ellatrix
Copy link
Member Author

@t-hamano Ah, in that case, this PR will not make any difference? Because merely adding wp-edit-blocks as a dependency does not cause it to load wherever wp-edit-blocks is enqueued? In other words removing wp-edit-blocks outside the canvas does not change anything for this code.

Yes, I'll add it to WordPress/wordpress-develop#7643 :)

@ellatrix
Copy link
Member Author

In fact, it will actually undo the removal of this PR because the action is called outside the canvas: https://github.com/WordPress/wordpress-develop/blob/695476ea5e51d1c92f389ac236b138ceeaee8a99/src/wp-admin/site-editor.php#L177

Copy link

Flaky tests detected in 4c7d42e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11578911527
📝 Reported issues:

@t-hamano t-hamano self-requested a review October 30, 2024 13:43
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thank you for the detailed explanation.

I may not understand everything correctly, but if this PR does not affect backward compatibility, I think it's okay to ship it.

If this PR is shipped, will WordPress/wordpress-develop#7643 be updated?

@t-hamano
Copy link
Contributor

BTW, should this PR be backported to Gutenberg 19.6? It looks like 19.6 RC1 is just about ready.

@ellatrix
Copy link
Member Author

@t-hamano Yes, I'll update the core PR. Thank you for the review!

@ellatrix ellatrix merged commit 9d46c69 into trunk Oct 30, 2024
65 checks passed
@ellatrix ellatrix deleted the fix/site-editor-block-lib-edit-styles branch October 30, 2024 16:34
@github-actions github-actions bot added this to the Gutenberg 19.7 milestone Oct 30, 2024
@ellatrix
Copy link
Member Author

BTW, should this PR be backported to Gutenberg 19.6? It looks like 19.6 RC1 is just about ready.

I'll check with the person doing the release.

@cbravobernal cbravobernal added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Oct 30, 2024
@cbravobernal
Copy link
Contributor

I just cherry-picked this PR to the release/19.6 branch to get it included in the next release: 3736840

cbravobernal pushed a commit that referenced this pull request Oct 30, 2024
@cbravobernal cbravobernal removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Oct 30, 2024
@Mamaduka
Copy link
Member

I think this introduced the following warning in the editors.

Screenshot

CleanShot 2024-10-31 at 09 55 21

@ellatrix
Copy link
Member Author

@Mamaduka Ah, will fix

@ellatrix
Copy link
Member Author

@Mamaduka Fixed in #66628.

karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants