Opened 5 months ago
Closed 3 weeks ago
#9299 closed enhancement (fixed)
Unload event handler in buddypress-notifications.js breaks bfcache
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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)
Change History (6)
#1
@
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
#2
@
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
unloadevent is deprecated and will be removed from Chrome - Using
unloadmakes pages ineligible for bfcache (back/forward cache) pagehideis 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
pagehideevent handler is registered (1 handler) - Confirmed
unloadevent 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.
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.