Repository navigation
Conversation
forget() deletes the stored credential with remove(), which resolved once the delete request succeeded. A transaction that then aborted left the credential in IndexedDB while forget() reported it gone. remove() now settles with its transaction, as write() does.
There was a problem hiding this comment.
Code Review
This pull request updates the browser state store's remove method to wait for the IndexedDB transaction to complete or abort before settling, and adds corresponding test coverage. The review feedback suggests adding a tx.onerror handler to prevent unhandled transaction errors from bubbling up globally, and replacing the Node-specific setImmediate with setTimeout in the tests to ensure compatibility with standard browser environments.
| 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); | ||
| }); |
There was a problem hiding this comment.
In IndexedDB, if a request or transaction error is not caught and event.preventDefault() is not called, the error bubbles up to the global scope (triggering window.onerror or global error events). This can cause false positives in error monitoring tools (like Sentry) or cause some test runners to fail. Consider adding a tx.onerror handler that calls event.preventDefault() to prevent the error from bubbling up globally.
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.
Keeping this as is. The default action of an IndexedDB error event is to abort the transaction: in the spec's "fire an error event" steps, the transaction is aborted only when the event was not canceled. A tx.onerror that calls preventDefault() would let the transaction carry on and commit after a failed delete, so remove() would resolve through oncomplete while the record is still there, which is the case this change exists to report. The event bubbles from the request to the transaction and the IDBDatabase, and onabort still turns it into a rejection that forget() sees. write() settles the same way (oncomplete / onabort, no onerror), and the two should stay alike.
| opened.onsuccess(); | ||
| await queued; | ||
| deleted.onsuccess(); | ||
| await new Promise<void>((resolve) => setImmediate(resolve)); |
There was a problem hiding this comment.
setImmediate is a non-standard, Node.js-specific global and is not supported in standard browser environments. Since this is a browser-targeted state store test, using setImmediate can 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 using setTimeout(resolve, 0) for cross-platform compatibility.
| await new Promise<void>((resolve) => setImmediate(resolve)); | |
| await new Promise<void>((resolve) => setTimeout(resolve, 0)); |
There was a problem hiding this comment.
This file only runs under node --test (npm test runs node --test 'build/**/*.test.js'), and it imports node:test and node:assert/strict, so it does not run in a browser runner. The write() test above it, already on main, yields with the same setImmediate line, so I kept the two tests alike.
forget()deletes the saved credential with the state store'sremove(). In the browser store,remove()resolved as soon as the IndexedDB delete request succeeded, before its transaction committed. If the transaction then aborted,forget()reported the credential gone while it was still stored.remove()now settles on the transaction'soncompleteand rejects ononabort(with the transaction's error, or a generic one when it has none), aswrite()already does since #936.The new test drives the transaction by hand: the delete request succeeds first, and the test checks that
remove()has not settled until the transaction commits or aborts. It failed on the previous behavior for all three outcomes.Validation: type checking (
tsconfig.json, test and webapp-test configs) is clean, and the state tests pass. In the full SDK suite, the only failures are the two Windows-only tests that fail without this change too (SIGTERM handling and file mode), plus one load-dependent timeout inbiscuit.test.tsthat passes when run alone on this branch and on main.