Skip to content

Commit ea5ea71

Browse files
committed
update comments for increased locality to described behavior
1 parent 7204cdd commit ea5ea71

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/toolkit/src/query/defaultSerializeQueryArgs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
1818
serialized = cached
1919
} else {
2020
const stringified = JSON.stringify(queryArgs, (key, value) =>
21+
// Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
2122
isPlainObject(value)
2223
? Object.keys(value)
2324
.sort()
@@ -32,7 +33,6 @@ export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
3233
}
3334
serialized = stringified
3435
}
35-
// Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
3636
return `${endpointName}(${serialized})`
3737
}
3838

@@ -48,7 +48,9 @@ export const bigIntSafeSerializeQueryArgs: SerializeQueryArgs<any> = ({
4848
serialized = cached
4949
} else {
5050
const stringified = JSON.stringify(queryArgs, (key, value) => {
51+
// Translate bigint fields to a serializable value
5152
value = typeof value === 'bigint' ? { $bigint: value.toString() } : value
53+
// Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
5254
value = isPlainObject(value)
5355
? Object.keys(value)
5456
.sort()

0 commit comments

Comments
 (0)