feat: move inline heartbeat JS to a standalone enqueued script - #169
feat: move inline heartbeat JS to a standalone enqueued script#169i-am-chitti wants to merge 3 commits into
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. |
▶ Preview in WordPress PlaygroundBoots a fresh WordPress with this PR's presence-api build, seeds 5 demo users, and drops you on the dashboard. Stress-test variant: 40 demo users · Built from |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #169 +/- ##
============================================
+ Coverage 28.56% 31.08% +2.51%
Complexity 161 161
============================================
Files 15 15
Lines 1817 1821 +4
============================================
+ Hits 519 566 +47
+ Misses 1298 1255 -43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Currently, the script handling heartbeat pings is outputted directly as a multi-line HEREDOC string inside
wp_presence_enqueue_heartbeat_ping()viawp_add_inline_script(). This brings a few challenges:This PR addresses this by:
includes/heartbeat.phpto a new standalone fileassets/js/presence-ping.js.wp_enqueue_script()withjqueryandheartbeatas dependencies.wpPresenceConfigviawp_add_inline_script()attached to the script as abeforedependency.Fixes
Proposed Changes
assets/js/presence-ping.jsincludes/heartbeat.phpwp_add_inline_script()block withwp_enqueue_script()pointing to the new standalone assets file.wpPresenceConfigto the script handle instead.tests/test-heartbeat.phptest_wp_presence_enqueue_heartbeat_ping()unit test to verify that the script is enqueued and the inline configuration data is attached properly.How to Test / Verification
Run the test suite in
wp-env:npm run testVerify that all unit tests pass successfully.
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.5 Flash
Used for: Extracting inline HEREDOC JavaScript into
assets/js/presence-ping.js, and writing unit tests to cover script enqueuing.