Trigger immediate heartbeat tick on page load#18
Merged
Conversation
Fixes #14. On screens other than the post editor, the first heartbeat tick can be up to 60 seconds away, leaving a user's reported screen stale right after they navigate. Call wp.heartbeat.connectNow() on DOMContentLoaded so the first presence ping fires right away, and again on bfcache restore (pageshow with event.persisted), where DOMContentLoaded does not fire.
There was a problem hiding this comment.
Pull request overview
This PR reduces “stale screen” presence reporting by triggering a Heartbeat tick immediately after navigation, rather than waiting for the next Heartbeat interval (which can be ~60s on some wp-admin screens).
Changes:
- Add a DOM-ready callback that calls
wp.heartbeat.connectNow()to force an immediate first tick. - Add a
pageshowlistener that re-triggersconnectNow()only for BFCache restores (event.persisted === true) to handle back/forward navigation without double-ticking on normal loads.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
westonruter
reviewed
May 13, 2026
westonruter
reviewed
May 13, 2026
Tightens the connectNow guard via optional chaining and expands the pageshow callback to the multi-line brace form. Per Weston's review on PR #18.
westonruter
approved these changes
May 14, 2026
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.
Closes #14.
On screens other than the post editor, the first heartbeat tick can be up to 60 seconds away, leaving a user's reported screen stale right after they navigate.
Change
Extend the inline script attached to the
heartbeathandle with two small additions:wp.heartbeat.connectNow()onDOMContentLoadedso the first presence ping fires right away.pageshowwhenevent.persisted === true(the bfcache-restore case, whereDOMContentLoadeddoes not fire again).A non-persisted
pageshowis intentionally ignored —DOMContentLoadedalready handles that path, and we don't want to double-tick.Files
includes/heartbeat.phpVerification
With wp-env running, log in as admin in window A and as editor in window B. As the editor, navigate from
wp-admin/towp-admin/upload.php. In window A's Who's Online widget, the editor's listed screen should update within a couple of seconds — not up to 60.