Skip to content

Ensure OnyxDB store is created & recover from corrupted database#684

Merged
mountiny merged 3 commits into
Expensify:mainfrom
blazejkustra:fix/initializing-onyxdb
Oct 3, 2025
Merged

Ensure OnyxDB store is created & recover from corrupted database#684
mountiny merged 3 commits into
Expensify:mainfrom
blazejkustra:fix/initializing-onyxdb

Conversation

@blazejkustra

@blazejkustra blazejkustra commented Sep 29, 2025

Copy link
Copy Markdown
Contributor

Description

Fixes: Expensify/App#69862

Context

The LeanConvert script loads as an HTML <script> and accesses OnyxDB’s IndexedDB store.
The bug occurred because it attempted to open OnyxDB when it didn’t exist. In doing so, it created the database without the required store, which corrupted our storage and froze the app.

More details in the issue. This was already fixed by the Convert team.

However, some clients may still have corrupted databases on their machines. To address this, when opening the database in Onyx, we now check if the store exists, and if not, create it. This ensures the database is no longer corrupted. The solution adds almost no overhead and reduces the chance of similar errors in the future.

Test steps

  1. Run npm run build in the Onyx repo and copy the code to the app.
  2. Open the app with Chrome DevTools.
  3. Go to Application tab → Storage and clear site data.
  4. Manually corrupt the Onyx database by creating OnyxDB without the store:
indexedDB.open('OnyxDB');
  1. Verify that the database exists but has no store:
CleanShot 2025-10-01 at 11 07 21
  1. Refresh the page and confirm that the store is created and the app opens properly.

@blazejkustra blazejkustra marked this pull request as ready for review October 1, 2025 09:10
@blazejkustra blazejkustra requested a review from a team as a code owner October 1, 2025 09:10
@blazejkustra blazejkustra changed the title Add IDBKeyValProvider with createStore function for manual store crea… Ensure OnyxDB store is created when missing to recover from corrupted databases Oct 1, 2025
@blazejkustra blazejkustra changed the title Ensure OnyxDB store is created when missing to recover from corrupted databases Ensure OnyxDB store is created when missing to recover from corrupted database Oct 1, 2025
@melvin-bot melvin-bot Bot requested review from Beamanator and removed request for a team October 1, 2025 09:11
@blazejkustra blazejkustra changed the title Ensure OnyxDB store is created when missing to recover from corrupted database Ensure OnyxDB store is created & recover from corrupted database Oct 1, 2025
@fabioh8010

Copy link
Copy Markdown
Contributor

Hold for my review

@mountiny mountiny self-requested a review October 1, 2025 20:00
Comment thread lib/storage/providers/IDBKeyValProvider/createStore.ts Outdated
Comment thread lib/storage/providers/IDBKeyValProvider/createStore.ts Outdated
Comment thread lib/storage/providers/IDBKeyValProvider/createStore.ts Outdated
Comment thread lib/storage/providers/IDBKeyValProvider/createStore.ts Outdated
}

logInfo(`Store ${storeName} does not exist in database ${dbName}.`);
const nextVersion = db.version + 1;

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 do we need to do this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IndexedDB only allows creating object stores during a version upgrade. If the store is missing (e.g., first run, cleared storage, or a previous version didn’t create it)

Comment thread lib/storage/providers/IDBKeyValProvider/createStore.ts Outdated
@blazejkustra

Copy link
Copy Markdown
Contributor Author

All yours @mountiny

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

Looks good for me 🚀

@staszekscp staszekscp left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

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

Thanks! Will move this one ahead

@mountiny

mountiny commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

@blazejkustra Lets make sure to get a checklist and testing on the App PR

@mountiny mountiny merged commit 9a90e38 into Expensify:main Oct 3, 2025
5 checks passed
@os-botify

os-botify Bot commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

🚀 Published to npm in 3.0.2 🎉

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.

[Due for payment 2025-10-17] Web App stuck on the splash screen

5 participants