fix(solid-query): don't bump the query version on observer-only cache events by S-jooyoung · Pull Request #12126 · TanStack/query · GitHub
Skip to content

fix(solid-query): don't bump the query version on observer-only cache events - #12126

Open
S-jooyoung wants to merge 1 commit into
TanStack:solid-query-v6-prefrom
S-jooyoung:fix/solid-query-key-switch-relay
Open

S-jooyoung wants to merge 1 commit into
TanStack:solid-query-v6-prefrom
S-jooyoung:fix/solid-query-key-switch-relay

Conversation

@S-jooyoung

Copy link
Copy Markdown
Contributor

🎯 Changes

Closes #11903.

onCacheEvent bumped version for every cache event on the hook's hash. After a key switch, observer.setOptions in the options render effect emits observer events (observerAdded, observerOptionsUpdated, observerResultsUpdated), so the data projection ran a second time in a later flush. That second run is what Solid's diagnostics report as EFFECT_RELAY_TEAR.

version now moves only on state events (added, removed, updated). observerResultsUpdated still has to reach isStale, since it is how a query going stale by time is reported (two existing useQuery.test.tsx tests fail without it), so it bumps a separate signal that only isStale reads.

The new tests in useQuery-semantics.test.tsx pin one data-projection recompute per switch to a cached key (and back), counted through select: [2, 2, 2] before (observer + projection twice), [2, 2] after.

Checked locally with @solidjs/diagnostics@2.0.0-rc.13 (not added to the repo): the cached and switch-back scenarios from the issue no longer log EFFECT_RELAY_TEAR, with identical rendered output. Not covered:

  • a memo reading query.isStale still recomputes twice on a key switch;
  • the stale-key back-and-forth case from the issue comment (staleTime: 0) still logs ABANDONED_FLIGHTS and EFFECT_RELAY_TEAR (same output before and after this change).

Note: this PR description was drafted with AI assistance. The AI policy box is left unchecked for that reason.

✅ 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).

… events

`setOptions` in the options render effect emits observer events
(`observerAdded`, `observerResultsUpdated`, ...) after a key switch.
`onCacheEvent` bumped `version` for all of them, so the data projection
ran a second time in a later flush and Solid's diagnostics reported
EFFECT_RELAY_TEAR.

Bump `version` only for state events (`added`, `removed`, `updated`).
`observerResultsUpdated` is still how a query going stale by time reaches
`isStale`, so it bumps a separate signal that only `isStale` reads.

Closes TanStack#11903
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant