Skip to content

Comments

Conditionally add unload event listener (enable bfcache)#127

Merged
nikrom17 merged 3 commits intomainfrom
feature/pagehide
Jan 7, 2026
Merged

Conditionally add unload event listener (enable bfcache)#127
nikrom17 merged 3 commits intomainfrom
feature/pagehide

Conversation

@nikrom17
Copy link
Member

@nikrom17 nikrom17 commented Jan 6, 2026

This PR implements BFCache (Back/Forward Cache) compatibility for smart payment buttons by replacing blocking beforeunload and unload event listeners with BFCache-compatible pagehide events. This enables instant back/forward navigation for users, improving the browsing experience by allowing browsers to cache entire pages in memory.

https://paypal.atlassian.net/browse/DTPPCPSDK-2854

@nikrom17 nikrom17 requested a review from a team as a code owner January 6, 2026 19:36
@nikrom17 nikrom17 force-pushed the feature/pagehide branch 3 times, most recently from ccdffc8 to 4565da1 Compare January 6, 2026 21:07
window.addEventListener("pagehide", () => win.close());
window.addEventListener("unload", () => win.close());
window.addEventListener("beforeunload", () => win.close());
window.addEventListener("beforeunload", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see beforeunload kept here. From previously testing, beforeunload is required to ensure the popup is closed when the user closes the merchant page.

@nikrom17 nikrom17 merged commit 55e5fcb into main Jan 7, 2026
1 check passed
@nikrom17 nikrom17 deleted the feature/pagehide branch January 7, 2026 20:40
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.

2 participants