Skip to content

QueryClient.setQueryData does not use custom queryKeyHashFn #1343

@schottra

Description

@schottra

Describe the bug
When initializing queryClient with a custom hash function via defaultOptions.queries.querykeyHashFn, subsequent calls to queryClient.setQueryData do not use the custom hash function to generate a query hash. This results in a mismatch of query keys when attempting to consume the data.

To Reproduce
Steps to reproduce the behavior:

  1. Initialize a queryClient with a custom query hash function.
  2. Use queryClient.setQueryData to insert a value for a given QueryKey
  3. Use queryClient.fetchQuery or useQuery with the same query key and staleTime: Infinity (or any other value that should result in usage of the cached value without performing a fetch).

Expected behavior
The fetchQuery or useQuery calls should return the cached value, no fetch should occur.

Actual behavior
setQueryData does not use the custom hash function, resulting in a different query hash being generated. useQuery creates a second query object and issues a fetch/calls the queryFn.

Version
3.2.0-beta.29

Here's a Codesandbox demonstrating the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions