Agent SkillsMelvynx/Parler › optimizer

optimizer

GitHub

指导 NowStack (TanStack Start + Convex) 应用开发的最佳实践,涵盖 Zustand 状态管理、URL 状态、数据获取、表单处理及异步生命周期。

web-app/.agents/skills/optimizer/SKILL.md Melvynx/Parler

触发场景

优化性能 添加状态管理 使用 Zustand 配置 URL 状态 实现乐观更新

安装

npx skills add Melvynx/Parler --skill optimizer -g -y
更多选项

非标准路径

npx skills add https://github.com/Melvynx/Parler/tree/main/web-app/.agents/skills/optimizer -g -y

不安装直接使用

npx skills use Melvynx/Parler@optimizer

指定 Agent (Claude Code)

npx skills add Melvynx/Parler --skill optimizer -a claude-code -g -y

安装 repo 全部 skill

npx skills add Melvynx/Parler --all -g -y

预览 repo 内 skill

npx skills add Melvynx/Parler --list

SKILL.md

Frontmatter
{
    "name": "optimizer",
    "description": "This skill should be used when the user asks to \"optimize\", \"improve performance\", \"add state management\", \"add URL state\", or mentions Zustand, TanStack Form, client-side fetching with Convex, optimistic updates, or custom async mutation\/query hooks. Provides best practices for state management, URL state via TanStack Router, data fetching with Convex queries, and forms."
}
Guide optimal patterns for NowStack application development. Covers Zustand for global UI state, direct Convex React hooks for live server data, TanStack Form for form handling, TanStack Router search params for URL state, TanStack Query mutations for imperative async lifecycle state, and local `useAsyncQuery` helpers for non-Convex async reads. This stack is **TanStack Start + Convex** — there are no Next.js Server Components, no `"use cache"` directive, and no `cacheTag`/`revalidateTag` semantics here.

If the optimization target is Convex database bandwidth, documents read vs returned, .filter() scans, index design, or expensive Convex query syntax, use convex-cost-optimizer first.

<quick_start> <decision_tree> Choose the right tool:

Need Solution Reference
Shared UI state between components Zustand store references/state-management.md
LocalStorage-persisted state Zustand with persist middleware references/state-management.md
URL state (filters, pagination) TanStack Router search params (useSearch) references/client-side-fetch.md
Server data on a route Server guard/loader + Convex useQuery references/client-side-fetch.md
Live-updating server data useQuery(api.x.y, args) from convex/react references/client-side-fetch.md
Convex mutation useMutation(api.x.y) from convex/react references/client-side-fetch.md
Non-reactive async read useAsyncQuery references/client-side-fetch.md
Imperative async mutation lifecycle TanStack Query useMutation or useAction references/client-side-fetch.md
Optimistic mutation Convex .withOptimisticUpdate(...) references/client-side-fetch.md
Form handling TanStack Form references/forms.md

</decision_tree>

<zustand_quick>

import { create } from "zustand";

type MyStore = {
  value: string;
  setValue: (value: string) => void;
};

export const useMyStore = create<MyStore>((set) => ({
  value: "",
  setValue: (value) => set({ value }),
}));

</zustand_quick>

<convex_query_quick>

import { useQuery } from "convex/react";
import { api } from "@convex/_generated/api";

const subscription = useQuery(
  api.subscriptions.queries.getActiveByOrganization,
  org.id ? { organizationId: org.id } : "skip",
);

</convex_query_quick>

<tanstack_form_quick>

import { useForm, Form } from "@/features/form/tanstack-form";

const form = useForm({
  schema: MySchema,
  defaultValues: { field: "" },
  onSubmit: async ({ value }) => {
    await mutation.mutateAsync(value);
  },
});

<Form form={form}>
  <form.AppField name="field">{(field) => <field.Input />}</form.AppField>
  <form.SubmitButton>Submit</form.SubmitButton>
</Form>;

</tanstack_form_quick> </quick_start>

<core_principles> <zustand_when> Use Zustand when:

  • Sharing UI state between multiple components (open/closed dialogs, sidebars, preferences)
  • Persisting client-side state to localStorage
  • State must be reachable from outside React (e.g. dialogManager.confirm(...))

Do NOT use Zustand for:

  • Server data — use Convex useQuery / useMutation
  • URL state — use TanStack Router search params
  • Form state — use TanStack Form </zustand_when>

<query_when> Use Convex React hooks when:

  • Fetching Convex data from React components
  • You want live subscription updates
  • Multiple components read the same backend data
  • You need Convex optimistic updates

Do NOT use React Query for:

  • One-off computed values that don't hit Convex (use useMemo)
  • Data that has zero re-render value (compute it inline)
  • Convex subscriptions already handled by convex/react

Use TanStack Query mutations for:

  • Imperative form submissions that need isPending, mutateAsync, onSuccess, or onError
  • Wrapping Convex mutations/actions when the UI needs lifecycle callbacks </query_when>

<form_when> ALWAYS use TanStack Form for new forms:

  • Validates with Zod
  • Handles loading states
  • Integrates with mutations
  • Pre-built field components in @/features/form/tanstack-form

Legacy: A few existing components still use useZodForm from @/components/ui/form (react-hook-form). Don't propagate that pattern — convert if you touch the file. </form_when> </core_principles>

<anti_patterns> Using useState for state that lives in multiple components:

// BAD - state duplicated in each component
const [isOpen, setIsOpen] = useState(false);
```tsx // GOOD - single source of truth const isOpen = useDialogStore((s) => s.isOpen); ``` Fetching in `useEffect`: ```tsx // BAD - no caching, no loading state, no live updates useEffect(() => { fetch("/api/data").then(setData); }, []); ``` ```ts // GOOD - Convex query through convex/react const feedback = useQuery(api.feedbacks.queries.listAdmin, {}); ``` Calling Convex directly with raw `fetch` to the Convex HTTP endpoint: ```ts // BAD - bypasses auth wiring const res = await fetch(`${convexUrl}/api/run/...`); ``` ```ts // GOOD - authenticated server-to-Convex calls import { fetchAuthQuery, fetchAuthMutation } from "@/lib/auth-server"; const data = await fetchAuthQuery(api.feedbacks.queries.list, {}); ```

<reference_guides>

  • references/client-side-fetch.md — Convex queries, route loaders, search params, optimistic mutations
  • references/state-management.md — Zustand store patterns and persistence
  • references/forms.md — TanStack Form patterns, validation, auto-save </reference_guides>

<success_criteria>

  • Zustand used for shared UI state, never for server data
  • All client-side Convex data is fetched via useQuery(api.x.y, args) from convex/react
  • TanStack Form used for new forms, with Zod validation
  • URL state lives in route search params, not local component state
  • Convex mutations rely on reactive subscriptions, with optimistic updates only when the UI needs instant local feedback </success_criteria>

版本历史

  • 1aaa38b 当前 2026-08-20 07:35

同 Skill 集合

web-app/.agents/skills/add-documentation/SKILL.md
web-app/.agents/skills/apex/SKILL.md
web-app/.agents/skills/convex-cost-optimizer/SKILL.md
web-app/.agents/skills/convex-create-component/SKILL.md
web-app/.agents/skills/convex-migration-helper/SKILL.md
web-app/.agents/skills/convex-performance-audit/SKILL.md
web-app/.agents/skills/convex-quickstart/SKILL.md
web-app/.agents/skills/convex-setup-auth/SKILL.md
web-app/.agents/skills/convex/SKILL.md
web-app/.agents/skills/create-saas-idea/SKILL.md
web-app/.agents/skills/create-tests/SKILL.md
web-app/.agents/skills/dev-browser/SKILL.md
web-app/.agents/skills/init-project/SKILL.md
web-app/.agents/skills/intercepted-route-using-tanstack-start/SKILL.md
web-app/.agents/skills/org-api-route/SKILL.md
web-app/.agents/skills/publish-to-production/SKILL.md
web-app/.agents/skills/setup-stripe/SKILL.md
web-app/.agents/skills/sync-with-nowstack/SKILL.md
web-app/.agents/skills/exa-search/SKILL.md
web-app/.agents/skills/find-docs/SKILL.md

元信息

文件数
0
版本
1aaa38b
Hash
5ac279c8
收录时间
2026-08-20 07:35

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-09 21:48
浙ICP备14020137号-1 $访客地图$