File tree Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @tanstack/db " : patch
3
+ ---
4
+
5
+ Ensure that all transactions are given an id, fixes a potential bug with direct mutations
Original file line number Diff line number Diff line change @@ -15,21 +15,8 @@ let transactionStack: Array<Transaction<any>> = []
15
15
export function createTransaction <
16
16
TData extends object = Record < string , unknown > ,
17
17
> ( config : TransactionConfig < TData > ) : Transaction < TData > {
18
- if ( typeof config . mutationFn === `undefined` ) {
19
- throw `mutationFn is required when creating a transaction`
20
- }
21
-
22
- let transactionId = config . id
23
- if ( ! transactionId ) {
24
- transactionId = crypto . randomUUID ( )
25
- }
26
- const newTransaction = new Transaction < TData > ( {
27
- ...config ,
28
- id : transactionId ,
29
- } )
30
-
18
+ const newTransaction = new Transaction < TData > ( config )
31
19
transactions . push ( newTransaction )
32
-
33
20
return newTransaction
34
21
}
35
22
@@ -74,7 +61,10 @@ export class Transaction<
74
61
}
75
62
76
63
constructor ( config : TransactionConfig < T > ) {
77
- this . id = config . id !
64
+ if ( typeof config . mutationFn === `undefined` ) {
65
+ throw `mutationFn is required when creating a transaction`
66
+ }
67
+ this . id = config . id ?? crypto . randomUUID ( )
78
68
this . mutationFn = config . mutationFn
79
69
this . state = `pending`
80
70
this . mutations = [ ]
You can’t perform that action at this time.
0 commit comments