Web: Flush IndexedDB after transactions and RETURNING statements - #3865
Merged
simolus3 merged 1 commit intoSep 16, 2026
Merged
Conversation
The COMMIT statement runs while isInTransaction is still set, so changes made in a transaction were never flushed. Check sqlite3's autocommit state instead, and also flush after selects since they can write too.
simolus3
approved these changes
Sep 15, 2026
Comment on lines
+379
to
+380
| // Selects can write too (e.g. with a RETURNING clause). Flushing without | ||
| // pending writes is cheap. |
Owner
There was a problem hiding this comment.
Good call. I have thought about checking CommonPreparedStatement.isReadOnly for this, but since this doesn't do anything apart from checking the work list in the VFS, it should be fine.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #3864
When using IndexedDB storage,
_WasmDelegateonly flushes ifisInTransactionis false. The problem is that the COMMIT goes throughrunCustomwhile that flag is still true, and the flag only gets reset in_release()after the commit finished. Since the file system is opened withwriteAutomatically: false, nothing written in a transaction ends up in IndexedDB until some unrelated write happens later. If the page is reloaded before that, the transaction is gone.I ran into this in our app where the first-run setup creates the admin account in a transaction. On the deployed web build, refreshing right after setup always sent us back to setup because the account table was empty.
This PR checks
database.autocommitinstead, which is already true once the COMMIT (or ROLLBACK) statement has run, and is false for savepoints inside an outer transaction.While looking at this I noticed
runSelectnever flushes either, so writes with a RETURNING clause (insertReturningetc.) had the same problem even outside of a transaction. I added an override for that too.flush()returns right away when there's no pending work, so plain selects shouldn't be affected.I added a web integration test that inserts in a transaction and with
insertReturning, reloads the page without any delay and checks both rows are still there. I ran the Firefox / dart2js tests locally, the new test fails ondevelopand passes with this change. I haven't been able to run the Chrome ones locally.