refactor!: cleanup Asset_Loader and add error checking#458
refactor!: cleanup Asset_Loader and add error checking#458dkotter merged 7 commits intoWordPress:developfrom
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
Refactors Asset_Loader to dedupe asset-loading logic and introduce admin/_doing_it_wrong() feedback when enqueued build assets are missing/invalid.
Changes:
- Refactor
Asset_Loaderinternals: centralize.asset.phploading, add handle prefix constant, add admin notice +_doing_it_wrong()reporting. - Update
enqueue_style()signature to accept explicit style dependencies (rather than reading deps from.asset.php). - Add new integration tests covering valid/invalid/missing asset metadata scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
includes/Asset_Loader.php |
Refactors enqueue/localize logic, adds centralized asset metadata loading and admin notice/error logging. |
tests/Integration/Includes/Asset_LoaderTest.php |
Adds integration tests for enqueue/localize behavior and error handling around missing/invalid asset metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #458 +/- ##
=============================================
+ Coverage 67.72% 68.52% +0.80%
+ Complexity 959 958 -1
=============================================
Files 60 60
Lines 4836 4861 +25
=============================================
+ Hits 3275 3331 +56
+ Misses 1561 1530 -31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What?
This PR dedupes the internal logic inside of Asset_Loader and adds both admin notices and
_doing_it_wrong()notices when a bad asset is enqueued.Additionally, tests have been backfilled to provide full coverage for the class.
Why?
@wordpress/buildas we proceed with the eventual migration.(On a personal note, this happened to me when I was switching branches and took me too long to notice they were still in the old
builddir.)How?
$asset_dataargument was removed (on::enqueue_stylesit was replaced withstring[] $dependencies]. If there's really a need for us to enqueue an asset that's not in our build flow, we can reintroduce it then.::enqueue_*()instead of renaming them to::register_*()and then using nativewp_enqueue_*()when the assets are actually required, and skipped introducing an::enqueue_script_module()since at the moment this also feels like YANGI and can be done with forward-compat.More specific hardening changes (using consts for reusable strings, making the class final, docblock typo) in the diff.
Use of AI Tools
tearDown()Testing Instructions
rm -rf build-scriptsWP_DEBUG_DISPLAYon you'll also see the_doing_it_wrong. Otherwise see it intests/_output/debug.log.npm run buildand refesh the screen, to confirm the notice goes away.Screenshots or screencast
Changelog Entry
Asset_Loaderclass and add error checking when dependencies are missing.