Exclude the plugin's scripts from Hummingbird's optimizations - #332
Conversation
Hummingbird's Asset Optimization combines the tracker with other scripts and moves (or duplicates) the inline script that initializes it. That can leave the inline plausible() calls, e.g. the search queries event, without the plausible.init() call, so window.plausible is still the tracker's placeholder object: "plausible is not a function". It also serves its own copy of the (proxied) tracker, which goes stale when the plugin updates the local file, and in our tests sent the search event twice. Return our handles (plausible-*) to WordPress untouched through wphb_dont_add_handle_to_collection, which Hummingbird itself uses to leave GTranslate's scripts alone, and exclude them from Delay JavaScript through wphb_delay_js_exclusions (matched against each script tag, including its inline code).
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe plugin registers Hummingbird filters to exclude Plausible scripts from Asset Optimization and Delay JavaScript. Integration tests cover the exclusions, and the 2.6.3 changelog notes the compatibility. ChangesHummingbird compatibility
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to The change adds targeted Hummingbird compatibility while preserving existing exclusions. No actionable merge-blocking risk is identified; it is ready to merge subject to normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The inspected callbacks make narrowly scoped compatibility changes without adding script sources or privileges. Risk is low, but Hummingbird’s downstream handling of the exclusions has not been verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
A user reported
plausible is not a functionon their search results page, caused by Hummingbird (WPMU DEV). In their page source, theplausible-analytics-js-afterinline script only contained the search queries event: thewindow.plausiblestub and theplausible.init(...)call that normally precede it were gone.Cause
"Not a function" (rather than "not defined") means the tracker did load: it leaves
window.plausibleas a placeholder object untilplausible.init()runs, so without the init the queuedplausible('WP Search Queries', …)fails.Reproduced with Hummingbird 3.21.2 (free), Asset Optimization on (default "speedy" mode), on 2.6.2:
/**handles:wpml-cookie,plausible-analytics**/) and copies our inline script to that group as well, so the stub, the init and the search event ran twice (and the search event was sent twice);hummingbird-assets/, which goes stale when the plugin updates the local file.The exact split in the user's page depends on their Hummingbird configuration and other plugins; in every case the fix is the same: keep Hummingbird away from our scripts, like we already do for WP Rocket, LiteSpeed, SG Optimizer, Autoptimize, W3TC and WP-Optimize.
Changes
wphb_dont_add_handle_to_collection: return our handles (plausible-*) to WordPress untouched. This is the filter Hummingbird itself uses to leave GTranslate's scripts alone.wphb_delay_js_exclusions: exclude them from Delay JavaScript. Exclusions are matched (as regex) against each script tag including its inline code, soplausiblecovers our handles, URLs and inline code.Testing
plausible-*scripts keep their original URLs and attributes (trackerasync), the inline script appears once,window.plausibleis a function, and exactly 2 events are sent (pageview + search). Hummingbird keeps optimizing the site's other scripts.Utils::is_member()), so that part is covered by the unit test only.Summary by CodeRabbit