MCPcopy Create free account
hub / github.com/TanStack/query / #updateStaleTimeout

Method #updateStaleTimeout

packages/query-core/src/queryObserver.ts:354–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

352 }
353
354 #updateStaleTimeout(): void {
355 this.#clearStaleTimeout()
356 const staleTime = resolveStaleTime(
357 this.options.staleTime,
358 this.#currentQuery,
359 )
360
361 if (
362 environmentManager.isServer() ||
363 this.#currentResult.isStale ||
364 !isValidTimeout(staleTime)
365 ) {
366 return
367 }
368
369 const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)
370
371 // The timeout is sometimes triggered 1 ms before the stale time expiration.
372 // To mitigate this issue we always add 1 ms to the timeout.
373 const timeout = time + 1
374
375 this.#staleTimeoutId = timeoutManager.setTimeout(() => {
376 if (!this.#currentResult.isStale) {
377 this.updateResult()
378 }
379 }, timeout)
380 }
381
382 #computeRefetchInterval() {
383 return (

Callers 2

setOptionsMethod · 0.95
#updateTimersMethod · 0.95

Calls 6

#clearStaleTimeoutMethod · 0.95
updateResultMethod · 0.95
resolveStaleTimeFunction · 0.90
isValidTimeoutFunction · 0.90
timeUntilStaleFunction · 0.90
setTimeoutMethod · 0.80

Tested by

no test coverage detected