Skip to content

fix(solid-query): avoid stale-notification resuspend - #11037

Open
Gujiassh wants to merge 1 commit into
TanStack:mainfrom
Gujiassh:fix/solid-query-stale-notify-no-resuspend-11024
Open

fix(solid-query): avoid stale-notification resuspend#11037
Gujiassh wants to merge 1 commit into
TanStack:mainfrom
Gujiassh:fix/solid-query-stale-notify-no-resuspend-11024

Conversation

@Gujiassh

@GujiasshGujiassh commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • stop cycling the Solid resource for already-settled observer notifications in useBaseQuery
  • keep Suspense/error semantics for genuine loading and error transitions by still using refetch() when the resource must re-enter those states
  • add a cache-warm staleTime regression test that proves a stale-only notification no longer re-suspends the subtree and drops input focus

Closes#11024.

Testing

  • cd packages/solid-query && pnpm exec vitest run src/__tests__/suspense.test.tsx --environment jsdom
  • pnpm --filter @tanstack/solid-query test:types:tscurrent
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Improved query behavior so cached results don’t re-trigger loading states when they become stale.
    • Preserved focus and prevented unnecessary UI remounts during stale transitions.
    • Reduced the chance of updates running after a view has already unsubscribed.
  • Tests

    • Added coverage for stale cached queries in Suspense, including focus stability and DOM preservation checks.

@coderabbitai

coderabbitaiBot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d412b86-de49-4b7b-958f-df9c276f3de8

📥 Commits

Reviewing files that changed from the base of the PR and between 64241b8 and 5861e77.

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

📝 Walkthrough

Walkthrough

Modifies the client subscriber microtask logic in useBaseQuery.ts to distinguish between results requiring a resource refetch (pending resolver, loading, or error) versus settled results, which now update state via setStateWithReconciliation instead of triggering a refetch. Adds a corresponding Suspense test.

Changes

Suspense re-suspend fix

Layer / File(s)Summary
Subscriber microtask branching fix
packages/solid-query/src/useBaseQuery.ts
Adds early return when unsubscribed, and branches to refetch only when a resolver is pending or the result is loading/error, otherwise updates state via setStateWithReconciliation.
Suspense stability test
packages/solid-query/src/__tests__/suspense.test.tsx
Adds a test preloading the cache, rendering a query inside Suspense, and asserting via MutationObserver and focus checks that no re-suspension or DOM removal occurs when the query transitions to stale.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
participant Observer
participant ClientSubscriber
participant Resource
participant Store
Observer->>ClientSubscriber: notify(result)
ClientSubscriber->>ClientSubscriber: queueMicrotask
alt no active unsubscribe
ClientSubscriber-->>ClientSubscriber: return early
else resolver pending or loading/error
ClientSubscriber->>Resource: refetch()
Resource->>Store: trigger Suspense read
else settled result
ClientSubscriber->>Store: setStateWithReconciliation(result)
end
Loading

Possibly related PRs

  • TanStack/query#10759: Both PRs modify useBaseQuery to change how queued subscription updates behave once the query is unsubscribed, preventing inappropriate state changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Description check⚠️ WarningThe description covers the summary and testing, but it omits the required Changes, Checklist, and Release Impact sections.Add the missing template sections and include the requested checklist and release-impact details.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly matches the core change: preventing stale Solid Query notifications from re-suspending.
Linked Issues check✅ PassedThe code update and regression test match the issue's requirements for settled notifications and stale-only Suspense behavior.
Out of Scope Changes check✅ PassedThe changes are confined to the Solid Query fix and its regression test, with no unrelated scope indicated.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for freeto 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: every observer notification cycles the internal resource, re-triggering ancestor Suspense and detaching live DOM (focus/scroll loss)

1 participant

@Gujiassh