进阶与上线
Infinite Query 与窗口控制
Section titled “Infinite Query 与窗口控制”import { createInfiniteQueryStore } from '@iostore/svelte';
export const feedStore = createInfiniteQueryStore({ key: ['feed', 'home'], initialPageParam: null as string | null, queryFn: ({ signal, pageParam }) => fetch('/api/feed?cursor=' + (pageParam ?? ''), { signal }).then((r) => r.json()), getNextPageParam: (lastPage) => lastPage.nextCursor ?? null, maxPages: 5, cancelOnUnsubscribe: true,});- 通过
maxPages控制内存窗口,避免无限累积。 - 滚动触底触发前先检查
isFetchingNextPage。 - 列表高频切换场景默认开启取消策略。
预取、重试与性能策略
Section titled “预取、重试与性能策略”- 路由切换前执行
prefetch,降低首屏等待。 - 网络波动使用有限重试(例如 1-2 次),业务错误不重试。
- 通过
select裁剪渲染字段,减少无关更新。 - 统一处理取消,不把
AbortError计入告警。