Skip to content

Trigger immediate heartbeat tick on page load#18

Merged
josephfusco merged 2 commits into
mainfrom
feat/14-immediate-heartbeat-tick
May 15, 2026
Merged

Trigger immediate heartbeat tick on page load#18
josephfusco merged 2 commits into
mainfrom
feat/14-immediate-heartbeat-tick

Conversation

@josephfusco
Copy link
Copy Markdown
Collaborator

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 heartbeat handle with two small additions:

  • Call wp.heartbeat.connectNow() on DOMContentLoaded so the first presence ping fires right away.
  • Re-fire on pageshow when event.persisted === true (the bfcache-restore case, where DOMContentLoaded does not fire again).

A non-persisted pageshow is intentionally ignored — DOMContentLoaded already handles that path, and we don't want to double-tick.

Files

  • includes/heartbeat.php

Verification

With wp-env running, log in as admin in window A and as editor in window B. As the editor, navigate from wp-admin/ to wp-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.

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pageshow listener that re-triggers connectNow() 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.

@josephfusco josephfusco marked this pull request as ready for review May 13, 2026 15:31
@josephfusco josephfusco requested a review from westonruter May 13, 2026 15:31
Comment thread includes/heartbeat.php Outdated
Comment thread includes/heartbeat.php Outdated
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.
@josephfusco josephfusco merged commit dedd54d into main May 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heartbeat delays reporting presence on pages other than post editing

3 participants