Fix GOOWOO-4: allow scripts and styles to share an asset handle#3477
Open
gabriel-fuentes wants to merge 1 commit into
Open
Fix GOOWOO-4: allow scripts and styles to share an asset handle#3477gabriel-fuentes wants to merge 1 commit into
gabriel-fuentes wants to merge 1 commit into
Conversation
AssetsHandler stored assets in a flat handle -> Asset map and threw InvalidAsset on any duplicate handle. WordPress core keeps separate registries for scripts and styles so same-handle pairs are normal there, and the original report calls out registering a ScriptAsset and StyleAsset under the same handle. The strict throw also caused a fatal in production when multiple code paths registered the same handle within a single request (Zendesk #11272914 with Enhanced Media Library active). Change AssetsHandler::$assets to array<string, Asset[]> so a handle can hold multiple assets of different classes. Same handle + same class is now a silent no-op, matching wp_register_script / wp_register_style. The public interface (AssetsHandlerInterface) is unchanged. Adds PHPUnit coverage for the new behavior and the idempotency case. Fixes: https://linear.app/a8c/issue/GOOWOO-4
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3477 +/- ##
===========================================
+ Coverage 66.7% 67.5% +0.9%
- Complexity 5514 5520 +6
===========================================
Files 923 531 -392
Lines 28735 22058 -6677
Branches 1694 0 -1694
===========================================
- Hits 19164 14899 -4265
+ Misses 9319 7159 -2160
+ Partials 252 0 -252
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this Pull Request:
Closes #129.
AssetsHandlerstored assets in a flathandle -> Assetmap and threwInvalidAsseton any duplicate handle. WordPress core keeps separate registries for scripts and styles so same-handle pairs are normal there. The original report describes that case, and Zendesk #11272914 confirms a real fatal in production when GfW is active alongside Enhanced Media Library (~70K installs): two code paths register the same handle within a single request, the second one throws, and the customer hits a white screen onwp-admin/options-general.php?page=media.Change
AssetsHandler::$assetstoarray<string, Asset[]>so a handle can hold multiple assets of different classes. Same handle + same class is now a silent no-op (idempotent), matching WordPress's ownwp_register_script/wp_register_stylebehavior.AssetsHandlerInterfaceis unchanged, so existing callers see no signature change.Screenshots:
n/a (no UI change).
Detailed test instructions:
PHPUnit (covers the AC + idempotency):
composer installvendor/bin/phpunit --bootstrap vendor/autoload.php --no-configuration tests/Unit/Assets/AssetsHandlerTest.phpManual repro of Zendesk #11272914:
wp-admin/options-general.php?page=mediaas an admin.InvalidAsset: The asset handle "google-listings-and-ads" already exists.The AC scenario (registering a
ScriptAssetand aStyleAssetunder the same handle) is covered bytest_allows_script_and_style_with_same_handleand friends.Additional details:
The fix also lets future GfW code register a
StyleAssetunder the same handle as its matching script, which is what the issue's original AC asks for. The currentgoogle-listings-and-adsscript +google-listings-and-ads-cssstyle split was a workaround for this limitation.Changelog entry
Created during the Woo Bug Blitz with Claude Code via team Ceres'
/bug-blitzskill.Drafted with AI; reviewed by me.