Skip to:
Content

BuddyPress.org

Opened 5 months ago

Closed 3 weeks ago

#9299 closed enhancement (fixed)

Unload event handler in buddypress-notifications.js breaks bfcache

Reported by: westonruter's profile westonruter Owned by: espellcaste's profile espellcaste
Milestone: 14.5.0 Priority: normal
Severity: normal Version: 3.0.0
Component: Toolbar & Notifications Keywords:
Cc:

Description

The use of the unload event handler in buddypress-notifications.js is currently making the Notifications page ineligible for bfcache. This event is unreliable, and it will be deprecated and removed from Chrome. A more appropriate event should be used, such as pagehide. This was done in core with #55491.

The addition of unload goes far back to commit 193538d on July 12, 2016 in buddypress/next-template-packs and merged for 3.0.0-RC1.

Enabling bfcache in WordPress while being logged-in is enabled via the No-cache BFCache which is a feature plugin to implement #63636.

Aside: I blogged about bfcache in WordPress in this post: Instant Back/Forward Navigations in WordPress.

Attachments (1)

9299.patch (700 bytes) - added by vapvarun 4 weeks ago.

Download all attachments as: .zip

Change History (6)

#1 @espellcaste
4 weeks ago

  • Component changed from Core to Toolbar & Notifications
  • Milestone changed from Awaiting Review to 15.0.0
  • Type changed from defect (bug) to enhancement

Thanks! I was not aware of that. We will patch this up. Since it is not super urgent, IMO. I'll schedule to BP 15.0.

#2 @vapvarun
4 weeks ago

Attaching a patch that replaces the unload event with pagehide in buddypress-notifications.js.

The Change:

// Before
$( window ).on( 'unload', this.resetFilter );

// After
$( window ).on( 'pagehide', this.resetFilter );

Why This Matters:

  • The unload event is deprecated and will be removed from Chrome
  • Using unload makes pages ineligible for bfcache (back/forward cache)
  • pagehide is the modern replacement that allows bfcache to work properly
  • WordPress core made the same change in #55491

Testing:

Verified on a local BuddyPress 15.0.0-alpha installation:

  • Confirmed pagehide event handler is registered (1 handler)
  • Confirmed unload event handler is NOT registered (0 handlers)
  • Confirmed resetFilter() function works correctly - filter value resets from 5 to 0
  • Notifications page loads and functions normally

The functionality remains identical - the filter is still reset when leaving the page.

@vapvarun
4 weeks ago

#3 @espellcaste
3 weeks ago

In 14180:

Administration: Remove deprecated unload event handlers with pagehide.

For a more deeper understanding about this change, refer to https://core.trac.wordpress.org/ticket/55491.

Props westonruter and vapvarun.

See #9299 (14.0).

#4 @espellcaste
3 weeks ago

  • Milestone changed from 15.0.0 to 14.5.0

Moving this to 14.5 instead.

#5 @espellcaste
3 weeks ago

  • Owner set to espellcaste
  • Resolution set to fixed
  • Status changed from new to closed

In 14181:

Administration: Remove deprecated unload event handlers with pagehide.

For a more deeper understanding about this change, refer to https://core.trac.wordpress.org/ticket/55491.

Props westonruter and vapvarun.

Fixes #9299 (trunk).

Note: See TracTickets for help on using tickets.