Are nested query keys serialised deterministically? #3052
-
It's established that a queryArgs is sorted by I am trying to find if the same behaviour is guaranteed in case on nested queryKeys. For example - does the above arg is serialised to Thanks in advance and a happy new year 🎉 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Looking at the implementation of export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
endpointName,
queryArgs,
}) => {
// Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
return `${endpointName}(${JSON.stringify(queryArgs, (key, value) =>
isPlainObject(value)
? Object.keys(value)
.sort()
.reduce<any>((acc, key) => {
acc[key] = (value as any)[key]
return acc
}, {})
: value
)})`
} |
Beta Was this translation helpful? Give feedback.
Looking at the implementation of
defaultSerializeQueryArgs
, looks like we only go one level deep: