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

Enqueued script warning for wp-editor on widgets screen #531

Merged
merged 2 commits into from
Feb 23, 2022

Conversation

robindevitt
Copy link
Contributor

This PR fixes the original issue reported in #482 where the below error shown when on the widgets page:

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.)

Steps to confirm:

  1. Login to the site
  2. View the widgets page
  3. View query Monitor, you shouldn't see the error mentioned above that wp_enqueue_script() was called incorrectly.

@robindevitt
Copy link
Contributor Author

@shadyvb I have created this as a draft just to share my initial implementation.

I may be overthinking this, but I feel there could be more to it rather than what I have implemented.

There may be a possibility that we'll need to factor in the new edit-site and edit-navigation packages with WP 5.9.

Initially I was thought to potentially have a function to return the script dependancy as a solution but I was hesitant to go that route, however long term it may be a better option?

The fix used in this module will be used to carry out across the rest of the modules.


global $pagenow;

$dependants = [
Copy link
Contributor

Choose a reason for hiding this comment

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

It's dependencies rather than dependents, the other way around.

Suggested change
$dependants = [
$dependencies = [

Copy link
Contributor

@shadyvb shadyvb left a comment

Choose a reason for hiding this comment

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

Variable name update.

@shadyvb
Copy link
Contributor

shadyvb commented Feb 21, 2022

I'd do the following to understand expected behavior:

  • Check where the notice is coming from, to understand the rules.
  • Check what others did to fix the same issue, by Googling the error message.

So I looked up where the notice is coming from to understand what is expected, this is where the check happens, which says wp-editor cannot be enqueued within either the customizer or the widget screen. ref: https://github.com/wordpress/wordpress/blob/master/wp-includes/widgets.php#L2073

Then I checked how others are handling it, Jetpack comes up: code: https://github.com/Automattic/jetpack/blob/master/projects/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php#L311 , ref: Automattic/jetpack#20357

Re future-proof solution, we'll cross that bridge when we come to it. It's fine to target the current issue for now.

@robindevitt
Copy link
Contributor Author

Thanks for the feedback and direction.

I do like that way of handling it! I feel this method can be used dependant on the module it's being implemented for and the effects it may have, so I will determine it per module basis.

@shadyvb
Copy link
Contributor

shadyvb commented Feb 22, 2022

Hmmmm, the last change is a change in direction, you were changing the dependency earlier, but now you're not loading the asset at all. Is this expected ? Do we not want to load that specific resource on customizer/widget-editor screens ?

@robindevitt
Copy link
Contributor Author

Correct, so I figured that when the script is being called but un-needed in the customizer/ widgets screen then it could return early. In cases where the asset/s are needed then changing the dependency would be preferred.

@shadyvb
Copy link
Contributor

shadyvb commented Feb 22, 2022

@robindevitt I can approve this if you're finished with it and can confirm it is functionally tested.

@robindevitt
Copy link
Contributor Author

Thanks @shadyvb

I'm looking for what issues come up if I return the function early, so far Im not facing any issues. Which concerns me that I am maybe missing something else.

I did identify this issue today with Reusable Blocks so there might be a need for the dependency?

The automated tests all return successfully when running them.

@shadyvb
Copy link
Contributor

shadyvb commented Feb 22, 2022

It doesn't seem related from looking at the actual js file we're using. you can confirm so by rolling back your change and checking the bug again.

@robindevitt
Copy link
Contributor Author

Rolling back to the previous changes Im getting the same test results.

I feel there is more value at the moment in returning early rather than changing the dependencies.

@robindevitt robindevitt marked this pull request as ready for review February 22, 2022 13:43
@robindevitt robindevitt requested a review from shadyvb February 22, 2022 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants