Skip to content
Source
Sign inSign up
TanStack/query

:bug: Fix restore loading not working when clicked repeatedly #5311

Mergedprateek3255(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/5311/headmerged by TkDodo View on GitHub

Showing 2 changed files with 61 additions and 0 deletions.

x
0 of 2 viewed, 2 left
52 additions and 0 deletionspackages/react-query-devtools/src/__tests__/devtools.test.tsxModified
View file
@@ -1091,4 +1091,56 @@
expect(screen.getByText('No error, success')).toBeInTheDocument()
+​
+ it('should not refetch when already restoring a query', async () => {
+ const { queryClient } = createQueryClient()
+​
+ let count = 0
+ let resolvePromise: (value: unknown) => void = () => undefined
+​
+ function App() {
+ const { data } = useQuery(['key'], () => {
+ count++
+​
+ // Resolve the promise immediately when
+ // the query is fetched for the first time
+ if (count === 1) {
+ return Promise.resolve('test')
+ }
+​
+ return new Promise((resolve) => {
+ // Do not resolve immediately and store the
+ // resolve function to resolve the promise later
+ resolvePromise = resolve
+ })