()
| 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 ( |
no test coverage detected