File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
packages/query-core/src/__tests__ Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1510,6 +1510,32 @@ describe('queryObserver', () => {
15101510 expect ( result . isEnabled ) . toBe ( true )
15111511 } )
15121512
1513+ test ( 'should update currentResult when getOptimisticResult is called with changed data' , ( ) => {
1514+ const key = queryKey ( )
1515+
1516+ const observer = new QueryObserver ( queryClient , {
1517+ queryKey : key ,
1518+ queryFn : ( ) => 'data' ,
1519+ } )
1520+
1521+ const defaultedOptions = queryClient . defaultQueryOptions ( {
1522+ queryKey : key ,
1523+ queryFn : ( ) => 'data' ,
1524+ } )
1525+
1526+ // First render: no data yet
1527+ const initialResult = observer . getOptimisticResult ( defaultedOptions )
1528+ expect ( initialResult . data ) . toBeUndefined ( )
1529+
1530+ // Another component sets data (e.g., dependent query resolved)
1531+ queryClient . setQueryData ( key , 'updated' )
1532+
1533+ // Re-render: getOptimisticResult should pick up the new data and update currentResult
1534+ const updatedResult = observer . getOptimisticResult ( defaultedOptions )
1535+ expect ( updatedResult . data ) . toBe ( 'updated' )
1536+ expect ( observer . getCurrentResult ( ) . data ) . toBe ( 'updated' )
1537+ } )
1538+
15131539 describe ( 'StrictMode behavior' , ( ) => {
15141540 it ( 'should deduplicate calls to queryFn' , async ( ) => {
15151541 const key = queryKey ( )
You can’t perform that action at this time.
0 commit comments