Skip to content

Deduplicate queries by id #619

@evanob

Description

@evanob

One thing I love about TanStack DB is that it has such parallels to TanStack Query that it's simple to swap from Query to DB, making it easy to adopt incrementally. One significant challenge though is that while Query deduplicates queries by queryKey, DB does not. That means we can't just swap our useVendorsQuery for a useLiveVendorsQuery; we need to be careful that useLiveVendorsQuery isn't called 20 times on the same page (e.g. in a table view), or else the query will run 20 times.

TanStack Query solves this problem with a QueryCache and a QueryObserver for every call to the same key. It uses an array for the key because they need to think about query invalidation, but a simple string would probably be fine here because we don't need to worry about invalidation.

We can work around this by hoisting the query higher up the component tree and share the results explicitly, but it makes adoption a little less simple.

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