Skip to content

fix(solid-query): resubscribe on query client switch 🤖🤖🤖 - #11615

Open
ousamabenyounes wants to merge 2 commits into
TanStack:mainfrom
ousamabenyounes:fix/issue-11106
Open

ousamabenyounes wants to merge 2 commits into
TanStack:mainfrom
ousamabenyounes:fix/issue-11106

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11106

🎯 Changes

  • Subscribe the replacement Solid query observer when the queryClient accessor changes, instead of accidentally subscribing the previous observer before setObserver(newObserver) runs.
  • Strengthen the Solid regression test to assert the second client cache receives the fetched data.
  • Relax the persist-client state-sequence assertion to keep checking the observable contract while allowing the new observer subscription to emit additional intermediate states.

Test verification (RED → GREEN)

RED on upstream base with only the stricter regression assertion:

pnpm exec nx run @tanstack/solid-query:test:lib -- --run src/__tests__/useQuery.test.tsx -t "should refetch query when queryClient changes"
AssertionError: expected undefined to be 'data'

GREEN with this fix:

pnpm exec nx run @tanstack/solid-query:test:lib -- --run src/__tests__/useQuery.test.tsx -t "should refetch query when queryClient changes"
Test Files  9 passed (9)
Tests  208 passed | 5 skipped (213)
Type Errors  no errors

Additional validation:

pnpm exec nx run @tanstack/solid-query-persist-client:test:lib -- --run src/__tests__/PersistQueryClientProvider.test.tsx -t "should be able to persist into multiple clients"
Test Files  1 passed (1)
Tests  6 passed | 1 skipped (7)
Type Errors  no errors

pnpm exec prettier --check packages/solid-query/src/useBaseQuery.ts packages/solid-query/src/__tests__/useQuery.test.tsx packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx .changeset/solid-query-client-switch.md
All matched files use Prettier code style!

pnpm run test:pr
Successfully ran targets test:sherif, test:knip, test:docs, test:eslint, test:lib, test:types, test:build, build for 12 projects and 28 tasks they depend on

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

Summary by CodeRabbit

  • Bug Fixes
    • Query subscriptions now switch to the new query client’s observer when the client changes, ensuring results come from the correct client and its fetched data is available.
  • Tests
    • Updated query-client checks to verify the fetched data is stored in the new client’s cache.
    • Updated persistence checks to confirm hydrated data and final query results without relying on an exact number or ordering of recorded states.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: TanStack/query/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: da116895-f096-4988-af9a-3594d9db0594

📥 Commits

Reviewing files that changed from the base of the PR and between 24ae9fa and 06afdcc.

📒 Files selected for processing (2)
  • packages/solid-query/src/__tests__/useQuery.test.tsx
  • packages/solid-query/src/useBaseQuery.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

When the Solid Query client accessor changes, the hook subscribes to the new observer. The query test checks that the new client’s cache contains fetched data. The persistence test no longer requires an exact count or fixed positions for recorded states.

Changes

Solid Query client switching

Layer / File(s) Summary
Subscribe to the replacement observer
packages/solid-query/src/useBaseQuery.ts, packages/solid-query/src/__tests__/useQuery.test.tsx, packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx, .changeset/solid-query-client-switch.md
createClientSubscriber accepts an observer, and the client-change path passes the new observer for subscription. The query test checks the new client’s cached data. The persistence test checks for the hydrated fetching state and final state without requiring an exact count or position of recorded states. The changeset records a patch release for @tanstack/solid-query.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: tkdodo, sukvvon

Merge Risk: ⚪ Minimal · up to 06afd

The client-switch fix targets the reported cache issue, and no remaining material merge risk is evident.

Architecture Summary

Architecture risk: 🔵 Low · up to 06afd

The change affects 2 systems.

Changed systems: packages/solid-query, packages/solid-query-persist-client

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/solid-query (library) was modified; 2 changed files map to changed impact.
  • observed — packages/solid-query-persist-client (library) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/solid-query-persist-client/src/tests/PersistQueryClientProvider.test.tsx: The test replaces exact state-count and indexed hydration/final-state assertions with a containment check for the hydrated fetching state and a final-state assertion. The initial pending/idle assertion remains.
  • observed — Modified behavior in packages/solid-query/src/tests/useQuery.test.tsx: The assertion now checks that the query stored in queryClient2 has data equal to 'data'; it previously checked only that the query entry was defined.
  • observed — Modified behavior in packages/solid-query/src/useBaseQuery.ts: createClientSubscriber now accepts an optional observer parameter, defaulting to observer(), instead of always retrieving the current observer internally.
  • observed — Modified behavior in packages/solid-query/src/useBaseQuery.ts: When the client changes, the new observer is now passed to createClientSubscriber before it is stored as the current observer.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: resubscribing Solid Query when the query client changes. The emojis add minor noise but do not prevent understanding.
Description check ✅ Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the fix, motivation, tests, and changeset. All checklist items are addressed, although it does not ex…
Linked Issues check ✅ Passed The PR satisfies issue [#11106]. useBaseQuery.ts now passes the replacement observer to createClientSubscriber before subscription, so a client switch subscribes to the new observer. The `useQuery…
Out of Scope Changes check ✅ Passed The changes stay within the client-switch fix. The changeset documents the fix. The useQuery assertion is a direct regression test for [#11106]. The persist-client assertion relaxation supports vali…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@changeset-bot

changeset-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 06afdcc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@tanstack/solid-query Patch
@tanstack/solid-query-devtools Patch
@tanstack/solid-query-persist-client Patch
@tanstack/angular-query-experimental Patch
@tanstack/eslint-plugin-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-core Patch
@tanstack/query-devtools Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query-devtools Patch
@tanstack/react-query-next-experimental Patch
@tanstack/react-query-persist-client Patch
@tanstack/react-query Patch
@tanstack/vue-query Patch
@tanstack/lit-query Patch
@tanstack/svelte-query Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/svelte-query-persist-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

solid-query: switching the queryClient accessor strands the new client's cache (subscription stays on the old observer)

1 participant