#53569 closed defect (bug) (fixed)
Block widgets editor is hidden if a block enqueues 'wp-edit-post' stylesheet
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.8 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Widgets | Keywords: | has-patch dev-reviewed fixed-major commit |
Focuses: | Cc: |
Description
On a client site of mine, a custom block has been developed whose editor_style
includes wp-edit-post
as a dependency.
When this block loads in the block widgets editor, and the wp-edit-post
stylesheet is enqueued, then a CSS rule is added that causes the editor to be hidden. Specifically:
body.block-editor-page #wpbody-content > div:not(.block-editor):not(#screen-meta) { display: none; }
This example block registration should demonstrate the issue:
<?php add_action( 'init', function () { wp_register_style( 'my-block-style', 'https://example.com', array( 'wp-edit-post' ) ); register_block_type( 'my-namespace/my-block', array( 'editor_style' => 'my-block-style', ) ); } );
Although it also seems to be as simple as:
<?php add_action( 'init', function () { wp_enqueue_style( 'wp-edit-post' ); } );
I'll defer to the editor team as to whether using wp-edit-post
as a style dependency is doing it wrong.
Attachments (2)
Change History (22)
#1
@
4 years ago
- Milestone changed from Awaiting Review to 5.8.1
Thanks for this report, @dlh! I've flagged this in the #feature-widgets-block-editor room on Slack for attention.
I'm moving this to 5.8.1 for now, but we can consider including a fix in 5.8 if we find that this is a common practice.
#3
follow-up:
↓ 4
@
4 years ago
I'll defer to the editor team as to whether using wp-edit-post as a style dependency is doing it wrong.
Yes I think so. wp-edit-post
(@wordpress/edit-post
) is the package containing scripts and styles that implement the post block editor (edit.php
). It shouldn't be enqueued in the widgets block editor (widgets.php
).
#4
in reply to:
↑ 3
@
4 years ago
wp-edit-post
(@wordpress/edit-post
) is the package containing scripts and styles that implement the post block editor (edit.php
). It shouldn't be enqueued in the widgets block editor (widgets.php
).
Enqueuing wp-edit-post
would be one thing, but, in this case, the offending block only declared it as a dependency so as to define the load order of stylesheets in the editor.
True, under the hood, declaring it as a dependency amounts to the same thing as enqueuing it. Until now, it has been harmless to do so, and if there's documentation from previous releases advising against it, then I just missed it.
So, if providing backwards compatibility is as straightforward as the patch by @manzurahammed suggests, then I would still hope that core could provide that affordance to developers to save them a surprise.
Alternatively, if core knows that wp-edit-post
shouldn't be enqueued in the widgets block editor, perhaps there should be protections in core against that happening, although I don't know what kind of precedent there is for such protections.
This ticket was mentioned in PR #1481 on WordPress/wordpress-develop by adamziel.
4 years ago
#5
## Description
Solves https://github.com/WordPress/gutenberg/issues/33203
Related to https://core.trac.wordpress.org/ticket/53569
Situation: packages/editor
is exposed as window.wp.editor
in wp-admin
Problem: there is quite some code expecting to see a different (legacy) object under window.wp.editor
Proposed solution: export all the members of legacy window.wp.editor from this new module to maintain backward compatibility
As @noisysocks noticed in https://github.com/WordPress/gutenberg/pull/33228:
Makes me wonder if a “fix” could be to add code to Core which fires off doing_it_wrong() if you enqueue wp-editor or wp-edit-post in the widgets screen.
This PR contains no such code, I will spin a new one to add these deprecations as there may be some discussion needed about the best way of adding them.
## How has this been tested?
- Activate classic widgets plugins.
- Insert text widget
- Add some text to widget.
- Deactivate classic widgets plugins.
- Go to widget screen.
- There is an error message if this PR is not applied.
- There are no error messages if this PR is applied.
## Screenshots
<img width="1904" alt="124498441-3f40df80-ddb4-11eb-99e1-581b287f96de" src="https://user-images.githubusercontent.com/205419/124633716-d9bd2380-de85-11eb-9228-742facbacaf9.png">
(Credits for the screenshot and the test plan to @spacedmonkey)
## Types of changes
Bug fix (non-breaking change which fixes an issue)
#6
@
4 years ago
I proposed a way of allowing wp-editor
and wp-edit-post
on the new widgets editor screen https://github.com/WordPress/wordpress-develop/pull/1481
It has certain shortcomings and I think we should be deprecating wp.editor
, but I think it's our best shot at improving the situation in 5.8.
#7
@
4 years ago
- Milestone changed from 5.8.1 to 5.8
Moving to 5.8 for consideration, though I am a bit hesitant to make this change so late. I defer to @noisysocks' judgement on this one.
#17
in reply to:
↑ 13
@
4 years ago
@desrosj, thanks for this! I've spent the last couple hours trying to find out any information on this - presumably as it's new.
Could you point us in the direction of a fix please? I've narrowed the issue down to the code in our agency's blocks plugin:
add_action( 'enqueue_block_editor_assets', 'enqueue_editor_assets' ); function enqueue_editor_assets() { wp_enqueue_script( 'block-editor-assets', plugins_url('dist/editor_script.js', __FILE__), array( 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-edit-post', // this looks like the problem ?? 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-keycodes', 'wp-plugins', ), BGB_VERSION ); }
Replying to desrosj:
In 51393:
#18
follow-up:
↓ 20
@
3 years ago
Hi all, I'm afraid I still see this message.
With debug mode activated, I can see this PHP warning in /wp-admin/widgets.php:
<?php Notice: wp_enqueue_script() was called incorrectly. "wp-editor" script should not be enqueued together with the new widgets editor (wp-edit-widgets or wp-customize-widgets). Please see Debugging in WordPress for more information. (This message was added in version 5.8.0.) in /home/user/domain.com/wp-includes/functions.php on line 5663
No plugins activated.
PHP 8
WordPress 5.8.2
Twenty Twenty-One 1.4
Twentig plugin 1.3.8
This ticket was mentioned in Slack in #themereview by utz119. View the logs.
3 years ago
#20
in reply to:
↑ 18
@
3 years ago
I am experiencing this problem as well and wondering if a solution has been identified. My apologies if it is listed here already.
Thank you.
Replying to ArtGoddess:
Hi all, I'm afraid I still see this message.
With debug mode activated, I can see this PHP warning in /wp-admin/widgets.php:
<?php Notice: wp_enqueue_script() was called incorrectly. "wp-editor" script should not be enqueued together with the new widgets editor (wp-edit-widgets or wp-customize-widgets). Please see Debugging in WordPress for more information. (This message was added in version 5.8.0.) in /home/user/domain.com/wp-includes/functions.php on line 5663No plugins activated.
PHP 8
WordPress 5.8.2
Twenty Twenty-One 1.4
Twentig plugin 1.3.8
The "blank" block widgets editor