Visitar URL original
fix(svelte-query): read result properties first accessed after the query settled from the current result by lazerg · Pull Request #12487 · TanStack/query · GitHub
Skip to content

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

Open
lazerg wants to merge 1 commit into
TanStack:mainfrom
lazerg:fix/issue-12485-svelte-late-tracked-key
Open

lazerg wants to merge 1 commit into
TanStack:mainfrom
lazerg:fix/issue-12485-svelte-late-tracked-key

Conversation

@lazerg

@lazerg lazerg commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🎯 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.

@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bfde03d

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

This PR includes changesets to release 4 packages
Name Type
@tanstack/svelte-query Patch
@tanstack/svelte-query-devtools Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/vue-query-devtools 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

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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 73c5686 and bfde03d.

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 name Status Explanation
Title check Passed The title clearly and concisely describes the main fix: reading Svelte query-result properties from the current result after the query settles.
Description check Passed The 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 check Passed 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(). Th…
Out of Scope Changes check Passed The 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 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 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

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.

[svelte-query] A result key first read after the query settled stays stale: the component's copy refreshes only on a change of an already-tracked key

1 participant