[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
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start with observer.trackResult(result) in createBaseQuery.svelte.js around line 29, then the #trackedProps check in queryObserver.js around lines 395-403, and the onPropTracked hook. Check the linked pull request #12487 first, since it already targets this bug. Done means the minimal case shows a b after about 300 ms, with a test that reads a key for the first time after the query has settled.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Versions: @tanstack/svelte-query 6.3.1, @tanstack/query-core 5.104.1, Svelte 5.
What happens
When notifyOnChangeProps is unset, createBaseQuery wraps the result in observer.trackResult(result) (createBaseQuery.svelte.js:29). QueryObserver.updateResult then notifies only when a key in #trackedProps changes (queryObserver.js:395-403).
The observer does add a key to its tracked set when a template first reads it. But the component's reactive copy is updated only through those notifications. If a query settles while the template has read only some of its keys, the update is skipped and the component keeps its copy of the old result. A key that the template reads later is then read from that stale copy, and nothing updates it again, because the query has already settled.
Minimal case
<script lang="ts">
import { createQuery } from '@tanstack/svelte-query';
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
const a = createQuery(() => ({ queryKey: ['a'], queryFn: () => wait(300).then(() => 'a') }));
const b = createQuery(() => ({ queryKey: ['b'], queryFn: () => Promise.resolve('b') }));
</script>
{#if a.isError || b.isError}
<p>error</p>
{:else if a.data === undefined || b.data === undefined}
<p>loading</p>
{:else}
<p>{a.data} {b.data}</p>
{/if}
Expected: a b after about 300 ms.
Actual: loading stays forever. b settles first, while the template has read only b.isError, because the || short-circuits before b.data. The change to b.data doesn't notify, so the component's copy of b keeps data: undefined. When a settles, the template reads b.data from that stale copy.
Workaround
Set notifyOnChangeProps: 'all' in the client's default query options, or read every key before branching.
Suggestion
Pass onPropTracked to trackResult and refresh the component's copy when a key is first tracked, or skip tracking in the Svelte adapter, since Svelte already re-renders key by key.
- Ngôn ngữ chính
- TypeScript
- Star
- 50.5k
- Fork
- 4.2k
- Merge trung bình
- 11 giờ 6 phút
- Pull request đã merge (30 ngày)
- 492
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/query
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Có thể làm lại được @LeonxLJX đã nhận 60 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TanStack/query#11358 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[query-broadcast-client-experimental] broadcastQueryClient: an `added` event overwrites a receiving query that has no data (e.g. in error) with the sender's empty stateCó thể đã có người làm @lazerg đã nhận 14 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
-
solid-query 6.0.0-rc.5: onCacheEvent throws NotReadyError during a Solid 2 (rc.14+) transition landingCó thể làm lại được @UzumakiODZ đã nhận 19 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
TanStack/query#12031 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
solid-query: EFFECT_RELAY_TEAR on Solid 2 when a query key changes — useBaseQuery relays the result through a version signal written from a render effectCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
TanStack/query#11903 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/query
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
bug needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DSpace/dspace-angular#6511 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: frontend area:byok bug severity:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Phone app shows Unknown for a remote machine whose key changedCó thể đã có người làm @janicduplessis đã nhận hôm nay. Đang mởarea: mobile priority: P3 type: bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
appandflow/stim#5006 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area - Local to Cloud Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
microsoft/vscode-mssql#23209 ·
Maintainer thường phản hồi trong vòng 1 ngày