The PR fetches a resource with ['user', id] or 'user-'+id typed in the component. The repo already has a query-key factory (queryKeys.user.detail(id), or a similar helper) that list, detail, and mutation hooks share. The new key does not match, so a successful mutation leaves the list stale, or two hooks for the same entity sit in different cache slots.
I've started treating a handmade query key as a cache bug waiting to happen when a factory exists. The fetch may work in the happy path. Invalidation is why the factory is there.
Why the loose key shows up
Examples online use a string or a short array in the hook. The model can write that without finding queryKeys or keys.ts. Your factory may live next to the API client, which is easy to miss if the prompt only says "load the user."
You also skip the list/detail relationship: a mutation should invalidate the same prefix the list query uses, not a close-looking array the author just invented.
A simple query-key policy
- New queries and mutations use the existing key factory
- Do not type a raw
['resource', id]array in a component - Invalidation uses the factory's prefix helpers, not a newly guessed key
- A new resource key is a factory change, with a test or a comment at the factory
If the repo does not have a factory yet, adding one is a separate, small PR. Do not invent a second key style in a feature file.
What to put in the prompt
Use the existing query-key factory for this query and its invalidation. Do not hardcode a string or a raw array key in the component. Invalidate with the factory helper that already covers this resource. If this is a new resource, add the key to the factory; do not start a second pattern. Paste the factory file or one existing hook. In review, search the diff for raw key arrays, string concatenation in queryKey, and invalidateQueries calls that do not import the factory.
Reject / send back
Reject
- A new hook whose key is a handmade array or string
- A mutation that invalidates a guessed key and leaves the list stale
- A second key helper added next to the existing factory
- Query keys that include unstable object literals
Accept
- A query or mutation that uses the existing factory
- A factory PR that adds a documented resource key
- A bugfix that switches a handmade key over to the factory
