@tanstack/query-core 5.79.1 → 5.79.2

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/query.ts CHANGED
@@ -18,7 +18,6 @@ import type {
18
18
  FetchStatus,
19
19
  InitialDataFunction,
20
20
  OmitKeyof,
21
- QueryFunction,
22
21
  QueryFunctionContext,
23
22
  QueryKey,
24
23
  QueryMeta,
@@ -431,48 +430,59 @@ export class Query<
431
430
  const queryFn = ensureQueryFn(this.options, fetchOptions)
432
431
 
433
432
  // Create query function context
434
- const queryFnContext: OmitKeyof<
435
- QueryFunctionContext<TQueryKey>,
436
- 'signal'
437
- > = {
438
- client: this.#client,
439
- queryKey: this.queryKey,
440
- meta: this.meta,
433
+ const createQueryFnContext = (): QueryFunctionContext<TQueryKey> => {
434
+ const queryFnContext: OmitKeyof<
435
+ QueryFunctionContext<TQueryKey>,
436
+ 'signal'
437
+ > = {
438
+ client: this.#client,
439
+ queryKey: this.queryKey,
440
+ meta: this.meta,
441
+ }
442
+ addSignalProperty(queryFnContext)
443
+ return queryFnContext as QueryFunctionContext<TQueryKey>
441
444
  }
442
445
 
443
- addSignalProperty(queryFnContext)
446
+ const queryFnContext = createQueryFnContext()
444
447
 
445
448
  this.#abortSignalConsumed = false
446
449
  if (this.options.persister) {
447
450
  return this.options.persister(
448
- queryFn as QueryFunction<any>,
449
- queryFnContext as QueryFunctionContext<TQueryKey>,
451
+ queryFn,
452
+ queryFnContext,
450
453
  this as unknown as Query,
451
454
  )
452
455
  }
453
456
 
454
- return queryFn(queryFnContext as QueryFunctionContext<TQueryKey>)
457
+ return queryFn(queryFnContext)
455
458
  }
456
459
 
457
460
  // Trigger behavior hook
458
- const context: OmitKeyof<
459
- FetchContext<TQueryFnData, TError, TData, TQueryKey>,
460
- 'signal'
461
- > = {
462
- fetchOptions,
463
- options: this.options,
464
- queryKey: this.queryKey,
465
- client: this.#client,
466
- state: this.state,
467
- fetchFn,
461
+ const createFetchContext = (): FetchContext<
462
+ TQueryFnData,
463
+ TError,
464
+ TData,
465
+ TQueryKey
466
+ > => {
467
+ const context: OmitKeyof<
468
+ FetchContext<TQueryFnData, TError, TData, TQueryKey>,
469
+ 'signal'
470
+ > = {
471
+ fetchOptions,
472
+ options: this.options,
473
+ queryKey: this.queryKey,
474
+ client: this.#client,
475
+ state: this.state,
476
+ fetchFn,
477
+ }
478
+
479
+ addSignalProperty(context)
480
+ return context as FetchContext<TQueryFnData, TError, TData, TQueryKey>
468
481
  }
469
482
 
470
- addSignalProperty(context)
483
+ const context = createFetchContext()
471
484
 
472
- this.options.behavior?.onFetch(
473
- context as FetchContext<TQueryFnData, TError, TData, TQueryKey>,
474
- this as unknown as Query,
475
- )
485
+ this.options.behavior?.onFetch(context, this as unknown as Query)
476
486
 
477
487
  // Store state in case the current fetch needs to be reverted
478
488
  this.#revertState = this.state