TanStack / TanStack/db

Deduplicate queries by `id`

Open
#619 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the useLiveVendorsQuery entry point and trace how repeated calls create and execute queries. Compare the desired behavior with TanStack Query's QueryCache and QueryObserver model, then define how calls with the same id share one query while each caller receives results. Done means repeated calls for the same id execute once without requiring callers to hoist the query.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.