-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add _doing_it_wrong() notices for missing script, style, and script module dependencies
#10545
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
Add _doing_it_wrong() notices for missing script, style, and script module dependencies
#10545
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Let's make sure to add unit tests for these changes as well. |
|
This is looking good to me. I will plan to finish reviewing and commit by next week. |
|
I'm testing this with the following plugin code: add_action(
'wp_enqueue_scripts',
static function () {
wp_enqueue_script( 'bad-script', '/bad.js', array( 'nope' ) );
wp_enqueue_style( 'bad-style', '/bad.css', array( 'nope' ) );
wp_enqueue_script_module( 'bad-module', '/bad.mjs', array( 'nope' ) );
}
);I get the following log entries:
The duplication of the notices is indeed not great. I think what I'll do is just add a private member variable to the classes to keep track of what has been flagged with What's also confusing is the functions being flagged are unrelated to the functions which may have been called incorrectly by the user. So I think I'll update these to use the Also, I'll add quotes around the initial handle ID. |
|
There, I think it is more developer-friendly now. When registering a script, style, and script module with missing dependencies, I now get just three notices:
|
| global $wp_version; | ||
| $wp_version = '99.9.9'; | ||
|
|
||
| $this->setExpectedIncorrectUsage( 'WP_Script_Modules::sort_item_dependencies' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method shouldn't have emitted an incorrect notice to begin with. I see it was due to a typo in this line:
| $deregister( array( 'b', 'c ' ) ); |
Note the extra space after c.
_doing_it_wrong() notices for missing script and script module dependencies_doing_it_wrong() notices for missing script, style, and script module dependencies
…t module with missing dependencies. Developed in #10545 Follow-up to [60999]. Props deepakprajapati, westonruter. See #63486. Fixes #64229. git-svn-id: https://develop.svn.wordpress.org/trunk@61323 602fd350-edb4-49c9-b593-d223f7449a82
…t module with missing dependencies. Developed in WordPress/wordpress-develop#10545 Follow-up to [60999]. Props deepakprajapati, westonruter. See #63486. Fixes #64229. Built from https://develop.svn.wordpress.org/trunk@61323 git-svn-id: http://core.svn.wordpress.org/trunk@60635 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…t module with missing dependencies. Developed in WordPress/wordpress-develop#10545 Follow-up to [60999]. Props deepakprajapati, westonruter. See #63486. Fixes #64229. Built from https://develop.svn.wordpress.org/trunk@61323 git-svn-id: https://core.svn.wordpress.org/trunk@60635 1a063a9b-81f0-0310-95a4-ce76da25c4cd



This PR adds developer-facing _doing_it_wrong() notices when a script or script module is enqueued with dependencies that have not been registered.
Currently, WordPress silently skips printing such assets, which makes dependency issues difficult to diagnose. This change improves debugging clarity during development.
What’s changed
✅ Classic scripts (WP_Scripts)
✅ Script modules (WP_Script_Modules)
Both implementations:
Trac ticket: https://core.trac.wordpress.org/ticket/64229