Skip to content

fix: [SDK-5377] close IndexedDB on versionchange and open newer versions - #1575

Open
fadi-george wants to merge 3 commits into
mainfrom
fadi/sdk-5377-idb-versionchange
Open

fadi-george wants to merge 3 commits into
mainfrom
fadi/sdk-5377-idb-versionchange

Conversation

@fadi-george

@fadi-george fadi-george commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Close IndexedDB connections on versionchange, open a DB a newer SDK already upgraded, and only flag new visitors when the DB is created.

Details

Found while reviewing #1571, which bumps the DB to v8.

  • No connection handled versionchange, so a tab or worker on an older SDK held its connection open and a newer SDK's upgrade stayed blocked. blocked() only logs and the op timeout guard does not cover open, so init() and SW DB calls hung until the old tab closed. Connections now close on versionchange and reopen.
  • Once the DB was upgraded, older code opening at its own VERSION hit VersionError and every DB op failed (rollbacks, mixed tabs). It now reopens the DB at its current version.
  • upgrade() set OneSignal._isNewVisitor on every upgrade, so a version bump showed the bell prenotify badge to returning unsubscribed visitors. Now only when oldVersion === 0.
  • Size limits: OneSignalSDK.page.es6.js to 47.12 kB and OneSignalSDK.sw.js to 13.68 kB.

Limitation: tabs on the currently released SDK do not have the handler and still block an upgrade. This needs to ship in a release before the v8 bump in #1571 to protect that transition.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

New tests: a newer version can upgrade while a connection is open, opening a DB a newer version already upgraded, and _isNewVisitor not set on upgrade. All three fail without the fix.

vp check clean (only existing warnings), full vp run test passes (1035), vp run build:prod passes.

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map.
  • Avoid using global OneSignal accessor for context if possible.

Screenshots

Info

No UI changes.

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets

SDK-5377


🤖 Generated with Claude Code

@fadi-george
fadi-george force-pushed the fadi/sdk-5377-idb-versionchange branch from fbcb571 to f38f021 Compare November 13, 2026 00:21
@fadi-george
fadi-george changed the base branch from new-session-events to main November 13, 2026 00:21
@sherwinski

sherwinski commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Can we hold off on merging this until after IV is released?

@sherwinski sherwinski left a comment

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.

Holding until IV release

@sherwinski sherwinski left a comment

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.

  • Non-blocking: src/shared/database/client.ts:136, if dbWedged is already true, a versionchange reopen leaves dbPromise pending and db.* hangs before guard() checks dbWedged. Let's check for dbWedged before awaiting dbPromise.
  • Non-blocking: src/shared/database/client.ts:87, void getDb() has no catch, so a failed reopen on an idle tab or SW gives an unhandled rejection. Consider adding a catch with a debug log.
  • Non-blocking: src/shared/database/idb-lite.ts:60, versionchange also fires for deleteDatabase (where newVersion == null). Then, the reopen recreates the DB and sets _isNewVisitor. Consider skippiing the reopen when newVersion is null.

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.

3 participants