Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More graceful failures when heartbeat.js is not available #687

Open
boonebgorges opened this issue Mar 9, 2021 · 2 comments
Open

More graceful failures when heartbeat.js is not available #687

boonebgorges opened this issue Mar 9, 2021 · 2 comments
Milestone

Comments

@boonebgorges
Copy link
Owner

We use WP's Heartbeat API to power the 'Are you still editing?' feature. But this causes problems when Heartbeat is disabled broadly, as it is by WPEngine and perhaps others. See #477.

In these cases, we should fail more gracefully. I think this means something like this:

  • Don't make the main bp-docs js files dependent on 'heartbeat' when enqueuing scripts. Attempt to load it separately.
  • In JS, check that heartbeat is available before initializing the 'idle' checker.
@boonebgorges boonebgorges added this to the Some day milestone Mar 9, 2021
@dcavins
Copy link
Collaborator

dcavins commented Mar 10, 2021

Boone, I wanted to check with WP Engine directly to understand what they're doing. After some back and forth with their support staff, they sent me their logic that deregisters heartbeat on most pages. Here it is:

`<?php
/**

  • WP Engine Heartbeat Throttle
  • @Package wpengine/common-mu-plugin
    */

/**

  • A class for throttling back the heartbeat of a WordPress page. This class controls

  • the heartbeat rate and even disables the heartbeat for all pages except post editing

  • pages.
    */
    class WPE_Heartbeat_Throttle {

    /**

    • Register the actions/hooks that make this throttle work.
      */
      public function register() {
      add_action( 'init', array( $this, 'check_heartbeat_allowed' ), 1 );
      }

    /**

    • Check that heartbeat is allowed for this page and deregeister it if not.
      */
      public function check_heartbeat_allowed() {
      global $pagenow;

      /**

      • Filter the pages where heartbeat.js is allowed to load.
      • @SInCE 2.1.13
      • @param array $heartbeat_allowed_pages Array of pages where the heartbeat.js file is allowed to be loaded.
        */
        $heartbeat_allowed_pages = apply_filters( 'wpe_heartbeat_allowed_pages', array( 'edit.php', 'post.php', 'post-new.php', 'site-health.php' ) );

      if ( ! in_array( $pagenow, $heartbeat_allowed_pages, true ) ) {
      wp_deregister_script( 'heartbeat' );
      }
      }
      }`

I was thinking we could get in before their code runs to unhook it on our edit pages, but init at 1 is pretty early. I've asked if they could just use wp_dequeue_script instead of deregistering it. Otherwise, we could just re-register it when we need it.

@boonebgorges
Copy link
Owner Author

Thanks for researching this. I think it's worth thinking about this as a specific solution for people who are on WPE and want to have the heartbeat functionality turned on for buddypress-docs. Maybe a useful thing for the wiki. But I still think we need to have a more graceful failure, as there are likely to be cases where heartbeat is disabled in ways other than this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants