Skip to content

fix(db): improve IndexedDB error handling and optimization#1433

Merged
fadi-george merged 8 commits intomainfrom
fg/db-error-fix
Mar 3, 2026
Merged

fix(db): improve IndexedDB error handling and optimization#1433
fadi-george merged 8 commits intomainfrom
fg/db-error-fix

Conversation

@fadi-george
Copy link
Copy Markdown
Contributor

@fadi-george fadi-george commented Mar 3, 2026

Description

1 Line Summary

Improves IndexedDB error handling by adding database availability checks during initialization and optimizes database operations by replacing the idb library with a lightweight custom implementation.

See ticket: https://app.asana.com/1/780103692902078/project/1208777190614537/task/1213397971882709?focus=true

Details

IndexedDB is our local storage system for preserving info on subscription, user, and other details. Currently when a user goes to chrome settings to delete data from site:
Screenshot 2026-03-02 at 9 21 49 PM
Screenshot 2026-03-02 at 9 20 27 PM

It will corrupt the IDB so when going back to the tab and refreshing, the developer might see:
image

New changes will just one check in init and use our Log helper if there's an error. Screenshot 2026-03-02 at 9 17 48 PM

  • Adds early database availability validation in OneSignal initialization to prevent crashes when IndexedDB is unavailable. Replaces the external idb dependency with a custom lightweight IndexedDB wrapper to reduce bundle size and give use more control.
  • Moves external id logic (from UserNamespace) to User class since if IDB is not available, then we don't want to use Model info which may rely on IDB.
  • Updates IDB/client test to use our simpler IDB promise methods
  • Updates init call to check against db promise to see if IDB can loaded otherwise will return early. OneSignal.User.<some-action really on user class being loaded in init but will remain undefined if IDB fails to load. Calls like OneSIgnal.User.PushSubscription.optIn (not reliant on user class) use awaitOneSignalInitAndSupported which will be a floating/unresolvable promise. This means it won't preform any action/updates if IDB fails to load.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

Database client tests updated to work with the new custom IndexedDB implementation while maintaining existing functionality.

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. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Checklist

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

Related Tickets



This change is Reviewable

@fadi-george fadi-george force-pushed the fg/db-error-fix branch 8 times, most recently from 7ef5e34 to 510377d Compare March 3, 2026 06:14
@fadi-george fadi-george merged commit e71732b into main Mar 3, 2026
4 checks passed
@fadi-george fadi-george deleted the fg/db-error-fix branch March 3, 2026 18:08
@github-actions github-actions Bot mentioned this pull request Mar 5, 2026
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