@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
22import { queryKey , sleep } from '@tanstack/query-test-utils'
33import { QueryClient } from '../queryClient'
44import { QueryCache } from '../queryCache'
5+ import { QueryObserver } from '../queryObserver'
56import { dehydrate , hydrate } from '../hydration'
67import { MutationCache } from '../mutationCache'
78import { executeMutation , mockOnlineManagerIsOnline } from './utils'
@@ -960,6 +961,47 @@ describe('dehydration and rehydration', () => {
960961 } )
961962 } )
962963
964+ test ( 'should hydrate over an existing disabled query shell' , async ( ) => {
965+ const key = queryKey ( )
966+
967+ const prefetchClient = new QueryClient ( )
968+ const prefetchPromise = prefetchClient . prefetchQuery ( {
969+ queryKey : key ,
970+ queryFn : ( ) => sleep ( 10 ) . then ( ( ) => 'prefetched' ) ,
971+ } )
972+ await vi . advanceTimersByTimeAsync ( 10 )
973+ await prefetchPromise
974+ const dehydrated = dehydrate ( prefetchClient )
975+
976+ const hydrationClient = new QueryClient ( )
977+ const observer = new QueryObserver ( hydrationClient , {
978+ queryKey : key ,
979+ queryFn : ( ) => Promise . resolve ( 'client' ) ,
980+ enabled : false ,
981+ } )
982+ const unsubscribe = observer . subscribe ( vi . fn ( ) )
983+
984+ const disabledShellQuery = hydrationClient . getQueryCache ( ) . find ( { queryKey : key } )
985+
986+ expect ( disabledShellQuery ?. state ) . toMatchObject ( {
987+ data : undefined ,
988+ fetchStatus : 'idle' ,
989+ status : 'pending' ,
990+ } )
991+ expect ( disabledShellQuery ?. isDisabled ( ) ) . toBe ( true )
992+
993+ hydrate ( hydrationClient , dehydrated )
994+
995+ expect ( hydrationClient . getQueryCache ( ) . find ( { queryKey : key } ) ?. state ) . toMatchObject ( {
996+ data : 'prefetched' ,
997+ status : 'success' ,
998+ } )
999+
1000+ unsubscribe ( )
1001+ prefetchClient . clear ( )
1002+ hydrationClient . clear ( )
1003+ } )
1004+
9631005 test ( 'should transform promise result' , async ( ) => {
9641006 const key = queryKey ( )
9651007 const queryClient = new QueryClient ( {
0 commit comments