跳转到内容

进阶与上线

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
  • 列表高频切换场景默认开启取消策略。
  1. 路由切换前执行 prefetch,降低首屏等待。
  2. 网络波动使用有限重试(例如 1-2 次),业务错误不重试。
  3. 通过 select 裁剪渲染字段,减少无关更新。
  4. 统一处理取消,不把 AbortError 计入告警。