Repository navigation
sdk/js: wait for a browser state delete to commit #982
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,11 @@ export function openState(location: string): StateStore { | |
| }, | ||
| async remove(name) { | ||
| const tx = (await open()).transaction(STORE, "readwrite"); | ||
| await request(tx.objectStore(STORE).delete(name)); | ||
| await new Promise<void>((resolve, reject) => { | ||
| tx.oncomplete = () => resolve(); | ||
| tx.onabort = () => reject(tx.error ?? new Error("IndexedDB delete transaction aborted")); | ||
| tx.objectStore(STORE).delete(name); | ||
| }); | ||
|
Comment on lines
+61
to
+65
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. In IndexedDB, if a request or transaction error is not caught and await new Promise<void>((resolve, reject) => {
tx.oncomplete = () => resolve();
tx.onabort = () => reject(tx.error ?? new Error("IndexedDB delete transaction aborted"));
tx.onerror = (event) => event.preventDefault();
tx.objectStore(STORE).delete(name);
}); |
||
| }, | ||
| }; | ||
| } | ||
|
|
||
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.
setImmediateis a non-standard, Node.js-specific global and is not supported in standard browser environments. Since this is a browser-targeted state store test, usingsetImmediatecan cause runtime errors if the tests are executed in a real browser environment (e.g., via Karma, Web Test Runner, or Playwright) without a polyfill. Consider usingsetTimeout(resolve, 0)for cross-platform compatibility.