File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -4971,6 +4971,29 @@ describe('useQuery', () => {
4971
4971
expect ( renders ) . toBe ( hashes )
4972
4972
} )
4973
4973
4974
+ it ( 'should hash query keys that contain bigints given a supported query hash function' , async ( ) => {
4975
+ const key = [ queryKey ( ) , 1n ]
4976
+
4977
+ function queryKeyHashFn ( x : any ) {
4978
+ return JSON . stringify ( x , ( _ , value ) => {
4979
+ if ( typeof value === 'bigint' ) return value . toString ( )
4980
+ return value
4981
+ } )
4982
+ }
4983
+
4984
+ function Page ( ) {
4985
+ useQuery ( { queryKey : key , queryFn : ( ) => 'test' , queryKeyHashFn } )
4986
+ return null
4987
+ }
4988
+
4989
+ renderWithClient ( queryClient , < Page /> )
4990
+
4991
+ await sleep ( 10 )
4992
+
4993
+ const query = queryClient . getQueryCache ( ) . get ( queryKeyHashFn ( key ) )
4994
+ expect ( query ?. state . data ) . toBe ( 'test' )
4995
+ } )
4996
+
4974
4997
it ( 'should refetch when changed enabled to true in error state' , async ( ) => {
4975
4998
const queryFn = vi . fn < ( ...args : Array < unknown > ) => unknown > ( )
4976
4999
queryFn . mockImplementation ( async ( ) => {
Original file line number Diff line number Diff line change @@ -70,7 +70,9 @@ export function useBaseQuery<
70
70
useClearResetErrorBoundary ( errorResetBoundary )
71
71
72
72
// this needs to be invoked before creating the Observer because that can create a cache entry
73
- const isNewCacheEntry = ! client . getQueryState ( options . queryKey )
73
+ const isNewCacheEntry = ! client
74
+ . getQueryCache ( )
75
+ . get ( defaultedOptions . queryHash )
74
76
75
77
const [ observer ] = React . useState (
76
78
( ) =>
You can’t perform that action at this time.
0 commit comments