@tanstack/query-core 5.90.14 → 5.90.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/mutation.ts CHANGED
@@ -278,14 +278,22 @@ export class Mutation<
278
278
  this as Mutation<unknown, unknown, unknown, unknown>,
279
279
  mutationFnContext,
280
280
  )
281
+ } catch (e) {
282
+ void Promise.reject(e)
283
+ }
281
284
 
285
+ try {
282
286
  await this.options.onError?.(
283
287
  error as TError,
284
288
  variables,
285
289
  this.state.context,
286
290
  mutationFnContext,
287
291
  )
292
+ } catch (e) {
293
+ void Promise.reject(e)
294
+ }
288
295
 
296
+ try {
289
297
  // Notify cache callback
290
298
  await this.#mutationCache.config.onSettled?.(
291
299
  undefined,
@@ -295,7 +303,11 @@ export class Mutation<
295
303
  this as Mutation<unknown, unknown, unknown, unknown>,
296
304
  mutationFnContext,
297
305
  )
306
+ } catch (e) {
307
+ void Promise.reject(e)
308
+ }
298
309
 
310
+ try {
299
311
  await this.options.onSettled?.(
300
312
  undefined,
301
313
  error as TError,
@@ -303,10 +315,12 @@ export class Mutation<
303
315
  this.state.context,
304
316
  mutationFnContext,
305
317
  )
306
- throw error
307
- } finally {
308
- this.#dispatch({ type: 'error', error: error as TError })
318
+ } catch (e) {
319
+ void Promise.reject(e)
309
320
  }
321
+
322
+ this.#dispatch({ type: 'error', error: error as TError })
323
+ throw error
310
324
  } finally {
311
325
  this.#mutationCache.runNext(this)
312
326
  }
@@ -172,33 +172,49 @@ export class MutationObserver<
172
172
  } satisfies MutationFunctionContext
173
173
 
174
174
  if (action?.type === 'success') {
175
- this.#mutateOptions.onSuccess?.(
176
- action.data,
177
- variables,
178
- onMutateResult,
179
- context,
180
- )
181
- this.#mutateOptions.onSettled?.(
182
- action.data,
183
- null,
184
- variables,
185
- onMutateResult,
186
- context,
187
- )
175
+ try {
176
+ this.#mutateOptions.onSuccess?.(
177
+ action.data,
178
+ variables,
179
+ onMutateResult,
180
+ context,
181
+ )
182
+ } catch (e) {
183
+ void Promise.reject(e)
184
+ }
185
+ try {
186
+ this.#mutateOptions.onSettled?.(
187
+ action.data,
188
+ null,
189
+ variables,
190
+ onMutateResult,
191
+ context,
192
+ )
193
+ } catch (e) {
194
+ void Promise.reject(e)
195
+ }
188
196
  } else if (action?.type === 'error') {
189
- this.#mutateOptions.onError?.(
190
- action.error,
191
- variables,
192
- onMutateResult,
193
- context,
194
- )
195
- this.#mutateOptions.onSettled?.(
196
- undefined,
197
- action.error,
198
- variables,
199
- onMutateResult,
200
- context,
201
- )
197
+ try {
198
+ this.#mutateOptions.onError?.(
199
+ action.error,
200
+ variables,
201
+ onMutateResult,
202
+ context,
203
+ )
204
+ } catch (e) {
205
+ void Promise.reject(e)
206
+ }
207
+ try {
208
+ this.#mutateOptions.onSettled?.(
209
+ undefined,
210
+ action.error,
211
+ variables,
212
+ onMutateResult,
213
+ context,
214
+ )
215
+ } catch (e) {
216
+ void Promise.reject(e)
217
+ }
202
218
  }
203
219
  }
204
220
 
package/src/query.ts CHANGED
@@ -658,6 +658,9 @@ export class Query<
658
658
  fetchFailureReason: error,
659
659
  fetchStatus: 'idle',
660
660
  status: 'error',
661
+ // flag existing data as invalidated if we get a background error
662
+ // note that "no data" always means stale so we can set unconditionally here
663
+ isInvalidated: true,
661
664
  }
662
665
  case 'invalidate':
663
666
  return {