Skip to content

Commit

Permalink
fix(setQueryData): setQueryData(notInstantiatedQueryKey) now assigns …
Browse files Browse the repository at this point in the history
…Promise.resolve() instead of new Promise(noop) that caused a never ending promise en certain scenarios. Ref bug #639 (#645)
  • Loading branch information
franleplant committed Jun 28, 2020
1 parent 11a9fd5 commit 5546670
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/queryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function makeQueryCache() {

if (!queries.length && typeof queryKey !== 'function') {
queries = [
cache._buildQuery(queryKey, undefined, () => new Promise(noop), {
cache._buildQuery(queryKey, undefined, () => Promise.resolve(), {
...defaultConfigRef.current,
...config,
}),
Expand Down
11 changes: 11 additions & 0 deletions src/tests/queryCache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,15 @@ describe('queryCache', () => {
expect(newQuery.state.markedForGarbageCollection).toBe(false)
expect(newQuery.state.data).toBe('data')
})

// this covers bug https://github.com/tannerlinsley/react-query/issues/639
test('setQueryData of not instatiated query uses a resolved promise as queryFn', async () => {
let promiseIsResolved = false
const queryCache = makeQueryCache()
const queryKey = 'notInstantiated'
queryCache.setQueryData(queryKey, "data")
await queryCache.refetchQueries(queryKey, { force: true });
promiseIsResolved = true
expect(promiseIsResolved).toBe(true)
})
})

0 comments on commit 5546670

Please sign in to comment.