Skip to content

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

Open
JexanJoel wants to merge 2 commits intopowersync-ja:mainfrom
JexanJoel:fix/replace-unload-with-pagehide
Open

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

Conversation

@JexanJoel
Copy link
Copy Markdown

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

⚠️ No Changeset found

Latest commit: 8f6dcf5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@JexanJoel
Copy link
Copy Markdown
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 on lines +74 to 81
export type WebPowerSyncDatabaseOptionsWithAdapter = WithWebSyncOptions
WithWebFlags<PowerSyncDatabaseOptionsWithDBAdapter>
>;
export type WebPowerSyncDatabaseOptionsWithOpenFactory = WithWebSyncOptions<
export type WebPowerSyncDatabaseOptionsWithOpenFactory = WithWebSyncOptions
WithWebFlags<PowerSyncDatabaseOptionsWithOpenFactory>
>;
export type WebPowerSyncDatabaseOptionsWithSettings = WithWebSyncOptions<
export type WebPowerSyncDatabaseOptionsWithSettings = WithWebSyncOptions
WithWebFlags<WithWebEncryptionOptions<PowerSyncDatabaseOptionsWithSettings>>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did these change, isn't this just a syntax error now?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry about that, it got mangled during editing. fixed now!

Comment thread packages/web/src/db/PowerSyncDatabase.ts
}
}
}
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please run this file through prettier.

Copy link
Copy Markdown
Author

@JexanJoel JexanJoel Apr 7, 2026

Choose a reason for hiding this comment

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

Done, ran it through, should be clean now. And thanks for testing it manually, appreciate it! Happy to wait for Steven's review.

@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
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

2 participants