@@ -149,15 +149,20 @@ export class QueryClient {
149149 ) : Promise < TData > {
150150 const defaultedOptions = this . defaultQueryOptions ( options )
151151 const query = this . #queryCache. build ( this , defaultedOptions )
152+ const cachedData = query . state . data
153+
154+ if ( cachedData === undefined ) {
155+ return this . fetchQuery ( options )
156+ }
152157
153158 if (
154159 options . revalidateIfStale &&
155160 query . isStaleByTime ( resolveStaleTime ( defaultedOptions . staleTime , query ) )
156161 ) {
157- void this . query ( options ) . catch ( noop )
162+ void this . prefetchQuery ( options )
158163 }
159164
160- return this . query ( { ... options , staleTime : 'static' } )
165+ return Promise . resolve ( cachedData )
161166 }
162167
163168 getQueriesData <
@@ -393,8 +398,22 @@ export class QueryClient {
393398 TPageParam
394399 > ,
395400 ) : Promise < TData > {
396- return this . query ( options )
401+ const defaultedOptions = this . defaultQueryOptions ( options )
402+
403+ // https://github.com/tannerlinsley/react-query/issues/652
404+ if ( defaultedOptions . retry === undefined ) {
405+ defaultedOptions . retry = false
406+ }
407+
408+ const query = this . #queryCache. build ( this , defaultedOptions )
409+
410+ return query . isStaleByTime (
411+ resolveStaleTime ( defaultedOptions . staleTime , query ) ,
412+ )
413+ ? query . fetch ( defaultedOptions )
414+ : Promise . resolve ( query . state . data as TData )
397415 }
416+
398417 prefetchQuery <
399418 TQueryFnData = unknown ,
400419 TError = DefaultError ,
@@ -403,7 +422,7 @@ export class QueryClient {
403422 > (
404423 options : FetchQueryOptions < TQueryFnData , TError , TData , TQueryKey > ,
405424 ) : Promise < void > {
406- return this . query ( options ) . then ( noop ) . catch ( noop )
425+ return this . fetchQuery ( options ) . then ( noop ) . catch ( noop )
407426 }
408427
409428 infiniteQuery <
@@ -445,7 +464,7 @@ export class QueryClient {
445464 TPageParam
446465 > ,
447466 ) : Promise < InfiniteData < TData , TPageParam > > {
448- return this . infiniteQuery ( options )
467+ return this . fetchQuery ( options as any )
449468 }
450469
451470 prefetchInfiniteQuery <
@@ -463,7 +482,7 @@ export class QueryClient {
463482 TPageParam
464483 > ,
465484 ) : Promise < void > {
466- return this . infiniteQuery ( options ) . then ( noop ) . catch ( noop )
485+ return this . fetchInfiniteQuery ( options ) . then ( noop ) . catch ( noop )
467486 }
468487
469488 ensureInfiniteQueryData <
0 commit comments