Skip to content

Commit ae838b4

Browse files
committed
remove replacer param in favor of handling bigints inside of defaultSerializeQueryArgs
1 parent e2dff71 commit ae838b4

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

packages/toolkit/src/query/defaultSerializeQueryArgs.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const cache: WeakMap<any, string> | undefined = WeakMap
99
export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
1010
endpointName,
1111
queryArgs,
12-
replacer,
1312
}) => {
1413
let serialized = ''
1514

@@ -19,8 +18,8 @@ export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
1918
serialized = cached
2019
} else {
2120
const stringified = JSON.stringify(queryArgs, (key, value) => {
22-
// Use custom replacer first before applying key-sorting behavior:
23-
value = replacer ? replacer(key, value) : value
21+
// Handle bigints
22+
value = typeof value === 'bigint' ? { $bigint: value.toString() } : value
2423
// Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
2524
value = isPlainObject(value)
2625
? Object.keys(value)
@@ -44,14 +43,10 @@ export type SerializeQueryArgs<QueryArgs, ReturnType = string> = (_: {
4443
queryArgs: QueryArgs
4544
endpointDefinition: EndpointDefinition<any, any, any, any>
4645
endpointName: string
47-
// Allows for a custom stringify replacer while keeping key-sorting behavior. e.g. for serializing bigint.
48-
replacer?: (key: string, value: any) => {}
4946
}) => ReturnType
5047

5148
export type InternalSerializeQueryArgs = (_: {
5249
queryArgs: any
5350
endpointDefinition: EndpointDefinition<any, any, any, any>
5451
endpointName: string
55-
// Allows for a custom stringify replacer while keeping key-sorting behavior. e.g. for serializing bigint.
56-
replacer?: (key: string, value: any) => {}
5752
}) => QueryCacheKey

packages/toolkit/src/query/react/buildHooks.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,17 +761,14 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
761761
subscriptionSelectorsRef.current =
762762
returnedValue as unknown as SubscriptionSelectors
763763
}
764-
const bigIntReplacer = (_: string, value: any) =>
765-
typeof value === 'bigint' ? { $bigint: value.toString() } : value
766764
const stableArg = useStableQueryArgs(
767765
skip ? skipToken : arg,
768766
// Even if the user provided a per-endpoint `serializeQueryArgs` with
769767
// a consistent return value, _here_ we want to use the default behavior
770768
// so we can tell if _anything_ actually changed. Otherwise, we can end up
771769
// with a case where the query args did change but the serialization doesn't,
772770
// and then we never try to initiate a refetch.
773-
(params) =>
774-
defaultSerializeQueryArgs({ replacer: bigIntReplacer, ...params }),
771+
defaultSerializeQueryArgs,
775772
context.endpointDefinitions[name],
776773
name,
777774
)

0 commit comments

Comments
 (0)