File tree 2 files changed +27
-6
lines changed
2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ describe('mutations', () => {
252
252
const onSettled = vi . fn ( )
253
253
254
254
queryClient . setMutationDefaults ( key , {
255
- mutationFn : ( text : string ) => Promise . resolve ( text ) ,
255
+ mutationFn : ( text : string ) => sleep ( 10 ) . then ( ( ) => text ) ,
256
256
onMutate,
257
257
onSuccess,
258
258
onSettled,
@@ -290,7 +290,23 @@ describe('mutations', () => {
290
290
submittedAt : 1 ,
291
291
} )
292
292
293
- await queryClient . resumePausedMutations ( )
293
+ void queryClient . resumePausedMutations ( )
294
+ await vi . advanceTimersByTimeAsync ( 0 )
295
+
296
+ // check that the mutation is correctly resumed
297
+ expect ( mutation . state ) . toEqual ( {
298
+ context : 'todo' ,
299
+ data : undefined ,
300
+ error : null ,
301
+ failureCount : 1 ,
302
+ failureReason : 'err' ,
303
+ isPaused : false ,
304
+ status : 'pending' ,
305
+ variables : 'todo' ,
306
+ submittedAt : 1 ,
307
+ } )
308
+
309
+ await vi . advanceTimersByTimeAsync ( 20 )
294
310
295
311
expect ( mutation . state ) . toEqual ( {
296
312
context : 'todo' ,
Original file line number Diff line number Diff line change @@ -162,6 +162,10 @@ export class Mutation<
162
162
}
163
163
164
164
async execute ( variables : TVariables ) : Promise < TData > {
165
+ const onContinue = ( ) => {
166
+ this . #dispatch( { type : 'continue' } )
167
+ }
168
+
165
169
this . #retryer = createRetryer ( {
166
170
fn : ( ) => {
167
171
if ( ! this . options . mutationFn ) {
@@ -175,9 +179,7 @@ export class Mutation<
175
179
onPause : ( ) => {
176
180
this . #dispatch( { type : 'pause' } )
177
181
} ,
178
- onContinue : ( ) => {
179
- this . #dispatch( { type : 'continue' } )
180
- } ,
182
+ onContinue,
181
183
retry : this . options . retry ?? 0 ,
182
184
retryDelay : this . options . retryDelay ,
183
185
networkMode : this . options . networkMode ,
@@ -188,7 +190,10 @@ export class Mutation<
188
190
const isPaused = ! this . #retryer. canStart ( )
189
191
190
192
try {
191
- if ( ! restored ) {
193
+ if ( restored ) {
194
+ // Dispatch continue action to unpause restored mutation
195
+ onContinue ( )
196
+ } else {
192
197
this . #dispatch( { type : 'pending' , variables, isPaused } )
193
198
// Notify cache callback
194
199
await this . #mutationCache. config . onMutate ?.(
You can’t perform that action at this time.
0 commit comments