-
Notifications
You must be signed in to change notification settings - Fork 95
Unify how merge and set handles AbortErrors #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NicolasBonet
merged 4 commits into
Expensify:main
from
callstack-internal:fix/handle-aborted-transactions
Jun 9, 2026
+102
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,18 @@ import type {StorageKeyValuePair} from '../types'; | |
| const DB_NAME = 'OnyxDB'; | ||
| const STORE_NAME = 'keyvaluepairs'; | ||
|
|
||
| /** | ||
| * Awaits an IndexedDB write transaction. idb-keyval's promisifyRequest rejects with | ||
| * `transaction.error`, which is `null` for an abort not caused by its own request | ||
| * (connection close / versionchange / a sibling transaction aborting). Normalize that | ||
| * `null` into a tagged AbortError. | ||
| */ | ||
| function promisifyWriteTransaction(transaction: IDBTransaction): Promise<void> { | ||
| return IDB.promisifyRequest(transaction).catch((error) => { | ||
| throw error ?? new DOMException('IDB write transaction aborted without an error', 'AbortError'); | ||
| }); | ||
| } | ||
|
|
||
| const provider: StorageProvider<UseStore | undefined> = { | ||
| // We don't want to initialize the store while the JS bundle loads as idb-keyval will try to use global.indexedDB | ||
| // which might not be available in certain environments that load the bundle (e.g. electron main process). | ||
|
|
@@ -38,7 +50,13 @@ const provider: StorageProvider<UseStore | undefined> = { | |
| return provider.removeItem(key); | ||
| } | ||
|
|
||
| return IDB.set(key, value, provider.store); | ||
| // Drive the write through the manual store transaction so promisifyWriteTransaction can | ||
| // normalize a null abort error — idb-keyval's IDB.set() awaits the raw transaction and | ||
| // would propagate the unclassifiable "Error: null". | ||
| return provider.store('readwrite', (store) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sosek108 Let's measure if we are going to have performance impact by doing this change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done #796 (comment) |
||
| store.put(value, key); | ||
| return promisifyWriteTransaction(store.transaction); | ||
| }); | ||
| }, | ||
| multiGet(keysParam) { | ||
| if (!provider.store) { | ||
|
|
@@ -71,7 +89,7 @@ const provider: StorageProvider<UseStore | undefined> = { | |
| } | ||
| } | ||
|
|
||
| return IDB.promisifyRequest(store.transaction); | ||
| return promisifyWriteTransaction(store.transaction); | ||
| }); | ||
| }); | ||
| }, | ||
|
|
@@ -93,7 +111,7 @@ const provider: StorageProvider<UseStore | undefined> = { | |
| } | ||
| } | ||
|
|
||
| return IDB.promisifyRequest(store.transaction); | ||
| return promisifyWriteTransaction(store.transaction); | ||
| }); | ||
| }, | ||
| clear() { | ||
|
|
@@ -133,14 +151,22 @@ const provider: StorageProvider<UseStore | undefined> = { | |
| throw new Error('Store not initialized!'); | ||
| } | ||
|
|
||
| return IDB.del(key, provider.store); | ||
| return provider.store('readwrite', (store) => { | ||
| store.delete(key); | ||
| return promisifyWriteTransaction(store.transaction); | ||
| }); | ||
| }, | ||
| removeItems(keysParam) { | ||
| if (!provider.store) { | ||
| throw new Error('Store not initialized!'); | ||
| } | ||
|
|
||
| return IDB.delMany(keysParam, provider.store); | ||
| return provider.store('readwrite', (store) => { | ||
| for (const key of keysParam) { | ||
| store.delete(key); | ||
| } | ||
| return promisifyWriteTransaction(store.transaction); | ||
| }); | ||
| }, | ||
| getDatabaseSize() { | ||
| if (!provider.store) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
setItemis called withnull(a supported path, used to remove the key), the earlier branch still delegates toremoveItem, which usesIDB.deland awaits idb-keyval's raw transaction. In the same versionchange/connection-close abort cases this PR is handling,Storage.setItem(key, null)can still reject with a literalnullwhile the non-null set path is normalized; route the delete branch through the same manual transaction helper or normalizeremoveItemas well.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should consider adding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think we need to normalize removeItem too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to
removeItemandremoveItems