fix(svelte-query): read result properties first accessed after the query settled from the current result #12487
main fromrefs/pull/12487/head·opened 🎯 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
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/query
- Branch: main
- File: .coderabbit.yaml
- Commit: 73c5686
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2677560f-d79c-4c4b-b46e-d081ed9fab82
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.mdpackages/svelte-query/src/createBaseQuery.svelte.tspackages/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.mdWhen notifyOnChangePropsis set,createResultreturns 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 tobfde0-
The change addresses stale late-read query properties. No actionable merge-blocking risk was identified.
Pre-merge checks:
5-
Check name Status Explanation Title check The title clearly and concisely describes the main fix: reading Svelte query-result properties from the current result after the query settles. Description check 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 Issue #12485requires current values for result properties first read after an untracked query change.createBaseQuery.svelte.tsnow proxies tracked reads tocurrentObserver.getCurrentResult(). Th…Out of Scope Changes check 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 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
#12485requires current values for result properties first read after an untracked query change.createBaseQuery.svelte.tsnow proxies tracked reads tocurrentObserver.getCurrentResult(). The added test reproduces the short-circuit case with two queries and verifiesdata1 data2after 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.
-
lazerg(GitHub profile, opens in a new tab) linked this to fix #12485
Sign in to join this conversation.
🦋 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
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