Skip to content
Source
Sign inSign up
TanStack/query

Query not updating when Set used in query key #7336

ClosedBrendanC23(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

I am trying to make a react-query call that involves using a set as a query key. However, updating the set (changing the reference passed in, not just adding an element to the set) does not cause the query to re-run.

/** @param {Set} set */
const useSetQuery = (set) => {
  return useQuery({
    queryKey: ['set-query', set],
    queryFn: () => {
      return Array.from(set.values());
    },
  });
};

See this TRPC issue for further discussion.

Your minimal, reproducible example

https://stackblitz.com/edit/github-wgxcnf?file=src%2Findex.jsx

Steps to reproduce

  1. Click "Add Item"

This creates a copy of a set and adds a new element. The set is used as a query key, but changes to the set do not cause the query to trigger. The "React State" list updates with the new values, but the "RQ Data" list does not.

Expected behavior

The query should re-run when the button is clicked, and the data returned from react-query should contain the most up-to-date list of the set content.

How often does this bug happen?

Every time

Screenshots or Videos

https://github.com/TanStack/query/assets/4711227/72954e24-434e-46b2-84ea-4b46f6c0a6cd

Platform

  • Chrome 124.0.6367.61
  • Linux (Codesandbox)
  • Windows 10

Tanstack Query adapter

react-query

TanStack Query version

5.32.0

TypeScript version

No response

Additional context

No response

  1. we only support json serializable values in the key. If you need something more, you can provide your own queryKeyHashFn and use something like superjson to serialize Sets.

  2. TkDodo closed this

  3. TkDodo added labelsworks as designed

  4. TkDodo added labelsknown limitation

Sign in to join this conversation.