File tree 1 file changed +10
-4
lines changed
services/data/src/react/hooks
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ export const useDataQuery = (
30
30
lazy : initialLazy = false ,
31
31
} : QueryOptions = { }
32
32
) : QueryRenderInput => {
33
+ const variablesHash = useRef < string | null > ( null )
33
34
const [ variables , setVariables ] = useState ( initialVariables )
34
35
const [ enabled , setEnabled ] = useState ( ! initialLazy )
35
36
const [ staticQuery ] = useStaticInput < Query > ( query , {
@@ -104,9 +105,13 @@ export const useDataQuery = (
104
105
}
105
106
106
107
if ( newVariables ) {
107
- const merged = { ...variables , ...newVariables }
108
- const identical =
109
- stableValueHash ( variables ) === stableValueHash ( merged )
108
+ // Use cached hash if it exists
109
+ const currentHash =
110
+ variablesHash . current || stableValueHash ( variables )
111
+
112
+ const mergedVariables = { ...variables , ...newVariables }
113
+ const mergedHash = stableValueHash ( mergedVariables )
114
+ const identical = currentHash === mergedHash
110
115
111
116
if ( identical ) {
112
117
// If the variables are identical we'll need to trigger the refetch manually
@@ -115,7 +120,8 @@ export const useDataQuery = (
115
120
throwOnError : false ,
116
121
} ) . then ( ( { data } ) => data )
117
122
} else {
118
- setVariables ( merged )
123
+ variablesHash . current = mergedHash
124
+ setVariables ( mergedVariables )
119
125
}
120
126
}
121
127
You can’t perform that action at this time.
0 commit comments