Skip to content
Source
Sign inSign up
TanStack/query

fix(solid-query): prevent suspense trigger with pre-cached data #10053

Closedshinseongsu(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/10053/headopened

When using refetchOnMount: false with pre-cached data, the first setQueryData call would incorrectly trigger a Suspense fallback. This happened because the Proxy handler was calling queryResource() even when cached data was available.

This fix ensures that:

  1. The resource resolves immediately when data is already available, regardless of the isLoading state
  2. The Proxy handler returns cached data directly when isFetching is false and data exists, avoiding unnecessary resource access

Closes #9883

🎯 Changes

useBaseQuery.ts (line 263): Added || observerResult.data !== undefined condition to resolve the resource immediately when cached data exists, even if isLoading is true

useBaseQuery.ts (line 378-390): Modified the Proxy handler to check isFetching state before accessing queryResource(). When isFetching is false and data exists in either state or observerResult, return it directly without triggering Suspense

suspense.test.tsx: Added test case to verify that Suspense is never triggered when using refetchOnMount: false with pre-cached data, including initial render and subsequent setQueryData calls

result

https://github.com/user-attachments/assets/2518236a-1b99-406f-9a52-e7dce58894f2

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 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

    • Improved Suspense mode handling to better manage pre-cached query data, preventing unnecessary suspension during data mutations.
    • Enhanced data retrieval logic to prioritize available cached data and optimize loading state detection.
  • Tests

    • Added comprehensive test coverage for Suspense mode behavior with pre-cached data and disabled refetch on mount.
✏️ Tip: You can customize this high-level summary in your review settings.
    1. 🦋 Changeset detected

      Latest commit: c76a14f28e4f91a857835dcb5358bac5632344b0

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

      This PR includes changesets to release 1 package
      NameType
      @tanstack/solid-queryPatch

      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

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-query

    3. Review in Change Stack →

      Caution

      Review failed

      The pull request is closed.

      Walkthrough

      Fixes a bug where mutations with refetchOnMount: false incorrectly trigger suspense when data is already cached. Modifies data retrieval precedence and loading conditions in Solid Query's base hook to prevent unnecessary suspense activation.

      Changes

      Cohort / File(s)Summary
      Test Addition
      packages/solid-query/src/__tests__/suspense.test.tsx
      Adds test case verifying suspense is not triggered when setQueryData mutates a pre-cached key with refetchOnMount: false, validating both initial render and subsequent mutations.
      Core Logic Modification
      packages/solid-query/src/useBaseQuery.ts
      Relaxes server/client resolver loading condition to resolve when observerResult.data exists. Enhances data accessor precedence to check observerResult.data before falling back to queryResource()?.data, using isFetching instead of isLoading for cached data returns.

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      • TanStack/query#9772: Modifies data tracking behavior to prefer observerResult.data and avoid suspense triggers when cached data exists, addressing the same underlying observer behavior.
      • TanStack/query#9822: Updates useBaseQuery.ts server-side render and data-resolution logic with different resolver/data-return strategies on the same file.

      Suggested labels

      package: solid-query

      Suggested reviewers

      • TkDodo
      🚥 Pre-merge checks | ✅ 4 | ❌ 1
      ❌ Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 33.33% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title accurately summarizes the main change: preventing suspense triggers when using pre-cached data, which is the core issue being fixed.
      Linked Issues check✅ PassedThe PR successfully implements all coding requirements from issue #9883: it prevents suspense triggers with pre-cached data when refetchOnMount is false, modifies the resource resolution logic to check for cached data, and includes a comprehensive test.
      Out of Scope Changes check✅ PassedAll changes are directly related to fixing the suspense trigger bug described in issue #9883. The test addition, resolver logic changes, and proxy handler modifications are all within scope.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      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
    4. Closing since the linked issue #9883 was marked as a duplicate of #9955, which #11230 addresses more broadly. Thanks!

Sign in to join this conversation.