-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useStableQueryArgs
chokes on BigInt
#4279
Comments
Worth noting that currently the My thoughts on how to approach it:
|
To me, it is surprising that changing how cache keys are created doesn't affect refetching and cache lifecycles. The example documenting the per-endpoint version reinforces this:
The API client isn't likely to change and as a user, I don't expect it to trigger new requests if it does. If I understand correctly (and I very well might not), the reason to not just use the user-provided In my mind, the ideal API would be to use the user-provided Alternately, if two separate cache key implementations really are useful; it might be best to allow users to override either one. Conceptually, I would think of them as: |
My apologies, I may have misrepresented the intention of the change here. I believe the reason Regardless, I do agree mostly with what you have said, it does seem inherently at odds to allow a user supplied I am exploring further whether I can make any reasonable trigger from the export function useStableQueryArgs<T>(
queryArgs: T,
serialize: SerializeQueryArgs<any>,
endpointDefinition: EndpointDefinition<any, any, any, any>,
endpointName: string,
) {
const incoming = useMemo(
() => ({
queryArgs,
serialized:
typeof queryArgs == 'object'
? serialize({ queryArgs, endpointDefinition, endpointName })
: queryArgs,
}),
[queryArgs, serialize, endpointDefinition, endpointName],
)
const cache = useRef(incoming)
useEffect(() => {
if (cache.current.serialized !== incoming.serialized) {
cache.current = incoming
}
}, [incoming])
return cache.current.serialized === incoming.serialized
? cache.current.queryArgs
: queryArgs
} But I do think that potentially the alternative is to provide an additional option for the user to handle the refetching or arg changes |
Since the serialization for |
Anything I can do to facilitate a code review / merging of my PR above? |
Unfortunately, right now we're just all pretty preoccupied - we'll get around to the PR eventually, but I'm sorry I can't guarantee a time frame on it. |
I appreciate the pointer to the CodeSandbox preview. It's definitely a better workaround than I had landed on -- and something I totally overlooked as a possibility. Will follow-up on other comments in the PR! |
When serializing a query object that includes a
BigInt
, rktQuery blows up with:This seems to be due to this code in
buildQueryHooks
:Which uses
defaultSerializeQueryArgs
instead of user-supplied overrides (i.e.serializeQueryArgs
) -- where users could override the behavior and make bigints safe to serialize.The text was updated successfully, but these errors were encountered: