Commit 051398c
committed
Fix optimistic state not being replaced by server data in writeInsert
Fixes #814
When writeInsert() is called from within an onInsert handler, the
transaction is in 'persisting' state. Previously, commitPendingTransactions()
would re-apply optimistic state from persisting transactions after syncing
server data, causing server-generated fields to be overwritten with
optimistic client-side values.
This fix excludes 'persisting' transactions from having their optimistic
state re-applied during commitPendingTransactions(). This ensures that
when writeInsert() syncs server data (e.g., server-generated IDs), that
data is not immediately overwritten by the optimistic state.
The flow now works correctly:
1. User inserts item with temporary ID -> optimistic state shows temp ID
2. Transaction commits -> onInsert handler called (state = 'persisting')
3. Handler calls writeInsert(serverItem) with real ID
4. commitPendingTransactions() syncs server data
5. Optimistic state from persisting transaction is NOT re-applied
6. UI now shows server data with real ID
7. Transaction completes -> optimistic state is cleared1 parent 5fb76fe commit 051398c
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
668 | 668 | | |
669 | 669 | | |
670 | 670 | | |
671 | | - | |
| 671 | + | |
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
| |||
0 commit comments