Skip to content

Query keys with object property set to undefined are not considered equal to missing property during invalidation #3741

@chekrd

Description

@chekrd

Describe the bug

Query keys with object property set to undefined are not considered equal to missing property. Based on the docs, it should be the same: https://react-query.tanstack.com/guides/query-keys#query-keys-are-hashed-deterministically

Your minimal, reproducible example

https://codesandbox.io/s/react-query-trz8sx?file=/src/App.tsx

Steps to reproduce

  1. Open the codesandbox link
  2. Show codesandbox console
  3. There are two queries rendered, the first fetch all items, and the second fetch filtered ones.
  4. You can see two buttons with invalidation hooks. The first one invalidates both queries, the second one invalidates only non-filtered results. See the console for refetch logs.

Expected behavior

I expect both keys should invalidate the same records no matter of filter: undefined as mentioned in react-query docs.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS v12.4
Chrome 103

react-query version

Both v3.39.1 and v4.0.0-beta.23

TypeScript version

v4.7.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions