Skip to content

Provide helpers to detect different app versions across tabs #1107

Open

Description

@simolus3

A web app using PowerSync shares state across tabs by default. This includes PowerSync-specific features like the sync worker, but also the database (and thus its schema).

A challenge specific to the web is that when a new version of the app is released, users might run multiple versions in different tabs. Especially when the new version changes the database schema, this can cause older tabs which still expect old tables and columns to break.

This problem can't be fixed in the PowerSync SDK, but we can at least inform app developers about it and give them an opportunity to handle this case. An app could then prompt a user to close other tabs, or use a broadcast channel to instruct other tabs to reload if they're idle.

Detecting this problem can be done with navigator locks: For its entire lifetime, a tab would request a shared lock named powersync-version-$appVersion. Before opening PowerSync databases, navigator.locks.query can be used to detect older app locks, allowing tabs to detect other versions.

Obtaining the current app version would be the responsibility of the app developer, but we might be able to use the current script URI as a default since popular bundlers append a hash to filenames for cache busting. This can both be exposed as a standalone API (e.g. const hasConflictingVersions = await checkForAppVersionsInOtherTabs()) and as an option on PowerSyncDatabase to prevent opening the database if different tabs exist.

This is also relevant for our Dart web SDK.

Activity

  1. added
    enhancement
    on Sep 16, 2026
  2. rkistner commented on Sep 16, 2026

    @rkistner
    Contributor

    On the versioning: Would it make sense to version based on the schema, rather than "app version"? Different app versions should generally be compatible as long as the schemas are the same. We can also fairly easily compute a hash of the schema JSON inside the SDK, and that covers cases that don't use hash-based filenames.

    Then in terms of conflict notifications, could we design the API to favor new versions over old versions? If the user loads a new version in a new tab, and the app blocks access because of a version conflict, it doesn't give the user an option to recover other than closing all existing tabs. While if we can detect on an existing tab that the schema has been replaced by a newer version, we (or the app developer) can do something like close the database and/or refresh the page.

    There is also some prior art with IndexeDB, for example the onversionchange event: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#version_changes_while_a_web_app_is_open_in_another_tab

    We should also explicitly consider what happens when multiple tabs with different schemas use the same database in a shared worker. In that case we may have more control over what we do with old tabs, for example sending a direct notification or even closing the database connection.

    One limitation with using schema hashes, is that it's not a definite indication of a newer version, it just indicates there is a different version. We should be able to generally assume that the last used schema hash is the latest version, but that assumption might not hold up if an old tab reconnects.

  3. simolus3 commented on Sep 17, 2026

    @simolus3
    ContributorAuthor

    Different app versions should generally be compatible as long as the schemas are the same

    We have also seen issue reports where, after an app developer has released a new version updating the PowerSync SDK, their bundler generates a different file name for the shared worker. Having both versions open then leads to both workers being active, but of course only one of them will be able to acquire the sync locks.

    So IMO, coming up with ways to make this less disrupting to end users but then triggering it for more kinds of updates feels better.

    While if we can detect on an existing tab that the schema has been replaced by a newer version, we (or the app developer) can do something like close the database and/or refresh the page

    I agree, there should be a notification mechanism developers can use to react to this from an old tab as well 👍

    We should also explicitly consider what happens when multiple tabs with different schemas use the same database in a shared worker. In that case we may have more control over what we do with old tabs, for example sending a direct notification or even closing the database connection.

    Even without a shared worker, we can send notifications over a broadcast channel. I think closing the database is a fairly destructive operation though, sending an event for the app developer to react to (which may involve closing the database when it's safe to do so) should accomplish the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions