tanstack
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTanStack Developer Guide
TanStack开发者指南
This SKILL.md is a dispatcher, not an encyclopedia. The load-bearing detail (code patterns, anti-patterns, edge cases, full checklists) lives in . The tripwires below exist so you can detect violations during scanning — they are not the contract.
references/*.md本SKILL.md是一个调度文档,而非百科全书。核心细节(代码模式、反模式、边缘案例、完整检查清单)存于中。以下注意事项用于在扫描时识别违规情况——它们并非正式规范。
references/*.mdRequired Reading Router
必读路由指南
Match the task to the row. Read the listed file(s) in full before producing output. They are not appendices — they are the contract. Inline content in this SKILL.md is a pointer, not a substitute.
| Task | MUST read |
|---|---|
| |
| Typed collections, live queries, optimistic collection mutations | |
| Forms, field components, validation, async checks | |
| Routes, search params, loaders, navigation, auth-protected layouts, router setup | |
| Server functions, middleware, sessions, SSR streaming, env, deploy adapters | |
| Anything that touches two or more layers (e.g. route loader + server fn + form) | Each file from the relevant rows — read all before designing |
将任务与对应行匹配。在输出内容前务必完整阅读列出的文件。它们不是附录——而是必须遵循的规范。本SKILL.md中的内联内容仅作为指引,不能替代参考文件。
| 任务 | 必须阅读的文件 |
|---|---|
| |
| 类型化集合、实时查询、乐观集合突变 | |
| 表单、字段组件、验证、异步检查 | |
| 路由、搜索参数、加载器、导航、受认证保护的布局、路由设置 | |
| 服务器函数、中间件、会话、SSR 流式传输、环境变量、部署适配器 | |
| 涉及两个或多个层级的操作(例如路由加载器 + 服务器函数 + 表单) | 对应行中的所有文件——设计前需全部阅读 |
Reference Index
参考索引
| File | What you get |
|---|---|
| Vanilla Query: key factories + |
| DB collections: 5 critical rules, collection setup, live queries with joins, optimistic updates, shared collection instances, persistence handlers, common anti-patterns, advanced patterns (computed, aggregations, pagination) |
| Form: |
| Router: |
| Start: |
| 文件 | 涵盖内容 |
|---|---|
| 基础Query:键工厂 + |
| DB集合:5条关键规则、集合设置、带关联的实时查询、乐观更新、共享集合实例、持久化处理程序、常见反模式、高级模式(计算、聚合、分页) |
| 表单: |
| Router: |
| Start:带Zod验证器的 |
Tripwires (not the contract)
注意事项(非正式规范)
These bullets exist so you can spot likely violations during a scan. They are deliberately incomplete. The full rules, examples, and edge cases live in the reference files. If a tripwire triggers, you must consult the referenced file before fixing.
这些要点用于在扫描时识别可能的违规情况。它们故意不完整。完整规则、示例和边缘案例请查看参考文件。如果触发了注意事项,修复前必须查阅对应的参考文件。
Query / DB
Query / DB
- Vanilla Query and DB collections are different paradigms — never mix them on the same entity.
- (default) refetches on every mount. Tune by data volatility.
staleTime: 0 - Optimistic mutations without + rollback context will get overwritten by in-flight refetches.
cancelQueries
STOP. Read in full before writing a , , prefetch, or SSR hydration boundary. STOP. Read in full before creating a collection, live query, or persistence handler. The three bullets above only flag the most common slip-ups.
references/query-patterns.mduseQueryuseMutationreferences/db-patterns.md- 基础Query和DB集合是不同的范式——切勿在同一实体上混用。
- (默认值)会在每次挂载时重新获取数据。请根据数据的易变性调整。
staleTime: 0 - 未搭配+ 回滚上下文的乐观突变会被进行中的重新获取覆盖。
cancelQueries
停止操作。在编写、、预取或SSR水合边界前,请完整阅读。 停止操作。在创建集合、实时查询或持久化处理程序前,请完整阅读。 以上三个要点仅标记最常见的失误。
useQueryuseMutationreferences/query-patterns.mdreferences/db-patterns.mdForm
Form
- drives type inference — manual generics fight it.
defaultValues - Async validators without hammer the network.
asyncDebounceMs - Reuse Zod schemas across form + server function (in ).
*.shared.ts
STOP. Read in full before building or modifying a form, field component, or validator. Field-level a11y attributes, setup, and array-field patterns are not in this body.
references/form-patterns.mdcreateFormHook- 驱动类型推断——手动泛型会与之冲突。
defaultValues - 未设置的异步验证器会频繁请求网络。
asyncDebounceMs - 在中复用表单和服务器函数的Zod模式。
*.shared.ts
停止操作。在构建或修改表单、字段组件或验证器前,请完整阅读。 字段级无障碍属性、设置和数组字段模式未包含在本文中。
references/form-patterns.mdcreateFormHookRouter
Router
- Without ,
declare module '@tanstack/react-router' { interface Register { router: typeof router } }/Link/useNavigatesilently degrade touseParams.unknown - Sequential s in a loader create waterfalls — fan out with
await.Promise.all - Throw /
notFound()from loaders, not genericredirect().Error
STOP. Read in full before adding a route, changing router setup, writing a loader, or modifying search-param validation. Defaults (, , global error/404), pathless layouts, masks, and deferred loaders all live in the reference.
references/router-patterns.mddefaultPreloadscrollRestoration- 如果没有,
declare module '@tanstack/react-router' { interface Register { router: typeof router } }/Link/useNavigate会静默降级为useParams类型。unknown - 加载器中的顺序会导致请求瀑布——使用
await并行处理。Promise.all - 从加载器中抛出/
notFound(),而非通用redirect()。Error
停止操作。在添加路由、修改路由设置、编写加载器或修改搜索参数验证前,请完整阅读。 默认值(、、全局错误/404页面)、无路径布局、掩码和延迟加载器均在参考文件中。
references/router-patterns.mddefaultPreloadscrollRestorationStart
Start
- Server logic belongs in with a Zod
createServerFn— not rawvalidator()+ API routes.fetch - Auth uses HTTP-only cookies. localStorage is XSS-bait.
- SSR loaders should only critical data; stream the rest via
await+prefetchQuery.Suspense
STOP. Read in full before writing a server function, middleware, session helper, or SSR loader. Cookie settings, middleware composition order, hydration-safety pitfalls, and adapter trade-offs are not in this body.
references/start-patterns.md- 服务器逻辑应放在带Zod 的
validator()中——而非原生createServerFn+ API路由。fetch - 认证使用HTTP-only Cookie。localStorage易受XSS攻击。
- SSR加载器应仅关键数据;其余数据通过
await+prefetchQuery流式传输。Suspense
停止操作。在编写服务器函数、中间件、会话助手或SSR加载器前,请完整阅读。 Cookie设置、中间件组合顺序、水合安全陷阱和适配器权衡未包含在本文中。
references/start-patterns.mdEnd-of-task checklist
任务结束检查清单
Each reference file has a scoped checklist with the real validation criteria. This umbrella confirms you actually consulted them:
- For each layer you touched, the corresponding reference file was read in full, not skimmed
- The scoped checklist in that reference file passes
- No mixed Query/DB paradigms on the same entity
- and
pnpm run typecheckpasspnpm run test
If you cannot point to which reference file you read for a given change, the change is not done.
每个参考文件都有一个范围明确的检查清单,包含真正的验证标准。本总清单确认你确实查阅了这些文件:
- 对于你涉及的每个层级,已完整阅读对应的参考文件,而非略读
- 该参考文件中的范围检查清单已通过
- 同一实体上未混用Query/DB范式
- 和
pnpm run typecheck执行通过pnpm run test
如果你无法指出针对某一变更所阅读的参考文件,那么该变更未完成。