Skip to content

fix(web): remove unload event listener to fix Chrome 146+ deprecation#924

Merged
simolus3 merged 4 commits intopowersync-ja:mainfrom
JexanJoel:fix/replace-unload-with-pagehide
Apr 21, 2026
Merged

fix(web): remove unload event listener to fix Chrome 146+ deprecation#924
simolus3 merged 4 commits intopowersync-ja:mainfrom
JexanJoel:fix/replace-unload-with-pagehide

Conversation

@JexanJoel
Copy link
Copy Markdown
Contributor

Fixes #912

Based on maintainer feedback in #912, the unload event listeners have been removed entirely rather than replaced with pagehide.

pagehide is not appropriate here because close() is a terminal action - if the tab is restored from bfcache, the database would remain closed.

Since navigator locks now reliably handle tab detection, the unload listeners are no longer needed.

Changes in packages/web/src/db/PowerSyncDatabase.ts:

  • Removed unloadListener property
  • Removed window.addEventListener('unload', ...) block from constructor
  • Removed window.removeEventListener('unload', ...) block from close()

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 4, 2026

🦋 Changeset detected

Latest commit: a0eba9c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@powersync/web Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@JexanJoel
Copy link
Copy Markdown
Contributor Author

Based on the discussion in #912, I've removed the unload listeners entirely since navigator locks now handle tab detection. Happy to revert or adjust if more testing is needed before this is merged.

@JexanJoel JexanJoel force-pushed the fix/replace-unload-with-pagehide branch from 6af1e0a to 1ced517 Compare April 4, 2026 19:32
Copy link
Copy Markdown
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

I ran a quick manual test of these changes in the react supabase todolist demo app. Closing a tab providing the database for the sync worker still makes it retry with a different tab, so it looks like the unload listeners indeed aren't necessary anymore.

I'd like to wait for Steven to also take a look once he's back, in case he finds additional issues to look out for.

Comment thread packages/web/src/db/PowerSyncDatabase.ts Outdated
Comment thread packages/web/src/db/PowerSyncDatabase.ts
Comment thread packages/web/src/db/PowerSyncDatabase.ts Outdated
@simolus3 simolus3 requested a review from stevensJourney April 7, 2026 07:34
@JexanJoel JexanJoel force-pushed the fix/replace-unload-with-pagehide branch from a4d3558 to 8f6dcf5 Compare April 7, 2026 09:46
@simolus3 simolus3 force-pushed the fix/replace-unload-with-pagehide branch from 8f6dcf5 to 61c6d28 Compare April 21, 2026 08:10
stevensJourney
stevensJourney previously approved these changes Apr 21, 2026
@simolus3 simolus3 merged commit c730604 into powersync-ja:main Apr 21, 2026
5 checks passed
@simolus3
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

@JexanJoel
Copy link
Copy Markdown
Contributor Author

Thank you! Happy to contribute to PowerSync 🙌

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.

Replace unload event with pagehide — Chrome 146+ deprecation causes Permissions Policy violation

3 participants