Skip to content
Source
Sign inSign up
TanStack/query

fix(svelte-query): read result properties first accessed after the query settled from the current result #12487

Openlazerg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12487/headopened

🎯 Changes

Fixes #12485

When notifyOnChangeProps isn't set, the observer only notifies for properties that were already read. In Svelte the component reads from the result we stored at the last update, so a property read for the first time after a change it wasn't tracked for (like b.data behind a short-circuited ||) got the old value and never refreshed. The tracked result now reads from the observer's current result, which is always up to date even when no notification went out.

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

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a stale-value issue in Svelte Query: when a query result property is first accessed after the query settles, it now reflects the latest result. This also helps ensure dependent queries show their resolved data correctly when they finish at different times.
    1. 🦋 Changeset detected

      Latest commit: bfde03d50e37640d175e8f6464202b024fbef7a8

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

      This PR includes changesets to release 4 packages
      NameType
      @tanstack/svelte-queryPatch
      @tanstack/svelte-query-devtoolsPatch
      @tanstack/svelte-query-persist-clientPatch
      @tanstack/vue-query-devtoolsPatch

      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. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 73c5686de77b3d6767e853d2d623453c477d3b88 and bfde03d50e37640d175e8f6464202b024fbef7a8.

      Files selected for processing: 3
      • .changeset/svelte-late-tracked-property.md
      • packages/svelte-query/src/createBaseQuery.svelte.ts
      • packages/svelte-query/tests/createQuery/createQuery.svelte.test.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

      The Svelte query adapter now reads tracked properties from the observer’s current result. A test covers two independently resolving queries, and a changeset declares a patch release.

      Changes: Svelte query result tracking

      Layer / File(s)Summary
      Current-result property tracking
      packages/svelte-query/src/createBaseQuery.svelte.ts, packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts, .changeset/svelte-late-tracked-property.md
      When notifyOnChangeProps is set, createResult returns the optimistic result without tracking. Otherwise, its proxy reads properties from the observer’s current result. The test checks the combined state of two queries as they resolve. The changeset declares a patch release.

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

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: lachlancollins, sukvvon

      Merge Risk: Minimal · up to bfde0

      The change addresses stale late-read query properties. No actionable merge-blocking risk was identified.

      Pre-merge checks: Passed 5
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main fix: reading Svelte query-result properties from the current result after the query settles.
      Description checkPassedThe description follows the required template, explains the stale-result issue and motivation, confirms testing and contribution-policy checks, and records the generated changeset.
      Linked Issues checkPassedIssue #12485 requires current values for result properties first read after an untracked query change. createBaseQuery.svelte.ts now proxies tracked reads to currentObserver.getCurrentResult(). Th…
      Out of Scope Changes checkPassedThe changed files are limited to the Svelte query result implementation, its regression test, and a Svelte Query patch changeset. Each change supports the fix for issue #12485.
      Docstring CoveragePassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
      Full details: Linked Issues check

      Explanation

      Issue #12485 requires current values for result properties first read after an untracked query change. createBaseQuery.svelte.ts now proxies tracked reads to currentObserver.getCurrentResult(). The added test reproduces the short-circuit case with two queries and verifies data1 data2 after the delayed query settles. The implementation and automated test satisfy the coding requirement.

      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

      Finishing Touches
      Generate unit tests (beta)
      • Create a new PR
      • 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

Sign in to join this conversation.