@@ -2,6 +2,7 @@ import { describe, expect, expectTypeOf, it, vi } from 'vitest'
2
2
import {
3
3
ErrorBoundary ,
4
4
Match ,
5
+ Suspense ,
5
6
Switch ,
6
7
createEffect ,
7
8
createMemo ,
@@ -11,6 +12,7 @@ import {
11
12
} from 'solid-js'
12
13
import { fireEvent , render , waitFor } from '@solidjs/testing-library'
13
14
import { reconcile } from 'solid-js/store'
15
+ import { MemoryRouter , Route , createMemoryHistory } from '@solidjs/router'
14
16
import { QueryCache , QueryClientProvider , keepPreviousData , useQuery } from '..'
15
17
import {
16
18
Blink ,
@@ -6045,4 +6047,79 @@ describe('useQuery', () => {
6045
6047
6046
6048
await waitFor ( ( ) => rendered . getByText ( 'Status: custom client' ) )
6047
6049
} )
6050
+
6051
+ // See https://github.com/tannerlinsley/react-query/issues/8469
6052
+ it ( 'should correctly manage dependent queries' , async ( ) => {
6053
+ const queryCache = new QueryCache ( )
6054
+ const queryClient = createQueryClient ( { queryCache } )
6055
+
6056
+ const history = createMemoryHistory ( )
6057
+
6058
+ const errorHandler = vi . fn < ( err : unknown ) => void > ( )
6059
+
6060
+ function App ( ) {
6061
+ return (
6062
+ < ErrorBoundary
6063
+ fallback = { ( err ) => {
6064
+ errorHandler ( err )
6065
+ return err . message
6066
+ } }
6067
+ >
6068
+ < Suspense >
6069
+ < MemoryRouter history = { history } >
6070
+ < Route path = "/" component = { Index } />
6071
+ < Route path = "/sub" component = { Sub } />
6072
+ </ MemoryRouter >
6073
+ </ Suspense >
6074
+ </ ErrorBoundary >
6075
+ )
6076
+ }
6077
+
6078
+ queryClient . setQueryData ( [ 'parent' ] , { id : 123 } )
6079
+
6080
+ function Index ( ) {
6081
+ return 'Index'
6082
+ }
6083
+
6084
+ function Sub ( ) {
6085
+ const parent = useQuery ( ( ) => ( {
6086
+ queryKey : [ 'parent' ] ,
6087
+ async queryFn ( ) {
6088
+ await new Promise ( ( r ) => setTimeout ( r , 100 ) )
6089
+ return {
6090
+ id : 123 ,
6091
+ }
6092
+ } ,
6093
+ } ) )
6094
+
6095
+ const childQuery = useQuery ( ( ) => ( {
6096
+ queryKey : [ 'sub' , parent . data ?. id ] ,
6097
+ async queryFn ( ) {
6098
+ await new Promise ( ( r ) => setTimeout ( r , 200 ) )
6099
+ return Promise . resolve ( 'child' + parent . data ?. id )
6100
+ } ,
6101
+ } ) )
6102
+ return < pre > { childQuery . data } </ pre >
6103
+ }
6104
+
6105
+ const rendered = render ( ( ) => (
6106
+ < QueryClientProvider client = { queryClient } >
6107
+ < App />
6108
+ </ QueryClientProvider >
6109
+ ) )
6110
+
6111
+ await waitFor ( ( ) => rendered . getByText ( 'Index' ) )
6112
+
6113
+ history . set ( {
6114
+ value : '/sub' ,
6115
+ } )
6116
+
6117
+ await sleep ( 200 )
6118
+
6119
+ expect ( errorHandler ) . not . toHaveBeenCalled ( )
6120
+
6121
+ await waitFor ( ( ) => {
6122
+ expect ( rendered . getByText ( 'child123' ) ) . toBeInTheDocument ( )
6123
+ } )
6124
+ } )
6048
6125
} )
0 commit comments