--- name: performance description: "MUST be used whenever fixing performance issues in a Flows app. This skill finds AND fixes performance problems — re-renders, inefficient queries, missing pagination, unbounded fetches, large bundles, and memory leaks. It does not just report them. Always measure before and after. Triggers: performance, slow, laggy, optimize, re-render, bundle size, load time, CDF query, large list, memory leak, debounce, virtualize, lazy load, code split." allowed-tools: Read, Glob, Grep, Shell, Write metadata: argument-hint: "[file, component, or area to optimize — e.g. 'src/components/AssetTable.tsx']" --- # Performance Fix Systematically find and fix performance issues in **$ARGUMENTS** (or the whole app if no argument is given). Always measure first — never optimize blindly. --- ## Step 1 — Measure baseline before touching anything Run the production build and capture metrics before making any changes: ```bash pnpm run build pnpm run preview ``` Open the app in Chrome and capture: - **Lighthouse score** (Performance tab → Run audit) - **React Profiler** (React DevTools → Profiler → Record an interaction) - Note the components with the longest render times and highest render counts Record baseline numbers. Every fix must be measured against these. --- ## Step 2 — Find and fix unnecessary re-renders Read the component tree (start from `src/App.tsx`) and search for these patterns: ```bash grep -rn --include="*.tsx" \ -E "value=\{\{|onClick=\{\(\)" src/ ``` For each instance found, **apply the fix directly**: **Inline object/array creation in JSX → wrap with `useMemo`:** ```tsx // BAD — new object on every render causes children to re-render // FIX — wrap with useMemo const chartOptions = useMemo(() => ({ color: "red" }), []); ``` **Event handlers recreated on every render → wrap with `useCallback`:** ```tsx // BAD