Skip to content
Source
Sign inSign up
TanStack/query

fix(solid-query): ignore observer cache events in useBaseQuery #12720

Opentranhoangtu-it(GitHub profile, opens in a new tab)wants to merge 1 commit intosolid-query-v6-pre fromrefs/pull/12720/headopened View on GitHub

🎯 Changes

Closes #12466

useBaseQueryLayer's onCacheEvent was bumping version() on every QueryCache event matching the active query hash, including observer lifecycle/sync events (observerAdded, observerRemoved, observerOptionsUpdated, and observerResultsUpdated). Those events don't modify QueryState, yet bumping version() forces computeData (select) and metaProjection to recompute — which on Solid 2 can cause a <Show> gated on q.data whose child subscribes to the same query key to loop mounting new observers.

With this change:

  • Only state-changing cache events (added, removed, updated) bump version.
  • Because QueryObserver's stale timer notifies via observerResultsUpdated without mutating QueryState, isStale() tracks a dedicated staleVersion signal (created unconditionally alongside primed to preserve SSR/client hydration ID parity) and bumps it only on observerResultsUpdated when this hook's computed isStale boolean flips.
  • Sibling mounts, option changes, stale timer ticks, and unmounts leave version (and thus select, data, and meta) untouched.
  • Added regression coverage in packages/solid-query/src/__tests__/observer-cache-events.test.tsx (tested locally across @tanstack/solid-query: oxfmt, test:oxlint, compile, test:types across TS 5.7–7.1, build, test:build, vitest run 31/31 files / 408 passed, and test:docs).

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).
    1. Pushed38c9056

Sign in to join this conversation.