Skip to content
Source
Sign inSign up
TanStack/query

fix(react): allow using `enabled` when using `useQuery().promise` #8501

ClosedKATT(GitHub profile, opens in a new tab)wants to merge 15 commits intomain fromrefs/pull/8501/headopened View on GitHub

Showing 3 changed files with 115 additions and 4 deletions.

x
0 of 3 viewed, 3 left
36 additions and 0 deletionspackages/query-core/src/__tests__/queryObserver.test.tsxModified
View file
@@ -1,3 +1,4 @@
+import { waitFor } from '@testing-library/dom'
import {
afterEach,
beforeEach,
@@ -8,6 +9,7 @@
vi,
} from 'vitest'
import { QueryObserver, focusManager } from '..'
+import { pendingThenable } from '../thenable'
import { createQueryClient, queryKey, sleep } from './utils'
import type { QueryClient, QueryObserverResult } from '..'
​
@@ -1271,4 +1273,38 @@
unsubscribe()
+​
+ test('switching enabled state should reuse the same promise', async () => {
+ const key = queryKey()
+​
+ const observer = new QueryObserver(queryClient, {
+ queryKey: key,
+ enabled: false,