Skip to content

ericrisco/rsc-harness / skills/react

Use when building or reviewing a client-side React SPA bundled by Vite (React 19.2): components, where state lives, hooks, server data fetching, client routing, re-render and effect bugs. NOT App Router / server components / SSR (that is `nextjs`); NOT native screens (that is `react-native`).

FileKindSize
SKILL.mdskill md12.7 KB
evals/README.mdmarkdown783 B
evals/cases.yamlconfig2.5 KB
references/data-and-state.mdmarkdown5.1 KB
references/performance.mdmarkdown3.0 KB
references/routing.mdmarkdown3.5 KB
scripts/verify.shexecutablescript4.4 KB

references/performance.md

View on GitHub
# Performance — measure, then fix the real bottleneck

Never optimize from a hunch. Profile, find the component that actually re-renders or the chunk that's actually heavy, fix that.

## 1. Profile first

- **React DevTools Profiler**: record an interaction, read the flamegraph. "Why did this render?" (Profiler settings) names the prop/state/context that triggered each render.
- Bundle size: `npx vite-bundle-visualizer` or `rollup-plugin-visualizer` to see what's actually shipped.
- Field metrics: LCP < 2.5s, INP < 200ms, CLS < 0.1. Generic CWV measurement detached from React → `../performance/SKILL.md`.

## 2. `key` correctness (the silent state bug)

Index keys are fine for static lists. The moment a list can **reorder, insert, or delete**, an index key makes React reuse the wrong DOM/state — inputs keep old values, the wrong row animates, checkboxes stick to the wrong item.

```tsx
// Bad: index key on a mutable list → wrong row state after delete/reorder
{users.map((u, i) => <Row key={i} user={u} />)}
// Good: stable identity
{users.map((u) => <Row key={u.id} user={u} />)}
```

## 3. Virtualize long lists

Past ~50–100 rows the DOM node count, not React, is the cost. Render only the visible window.

```tsx
import { useVirtualizer } from "@tanstack/react-virtual";

const v = useVirtualizer({
  count: rows.length,
  getScrollElement: () => parentRef.current,
  estimateSize: () => 48,
  overscan: 8,
});
// render only v.getVirtualItems(), positioned by item.start
```

## 4. Code-split

```tsx
const Chart = lazy(() => import("./Chart")); // separate chunk, loaded on demand
<Suspense fallback={<Spinner />}><Chart data={data} /></Suspense>
```

Vite emits a separate chunk for every dynamic `import()`. Split at route boundaries first, then heavy leaf components (charts, editors, maps).

## 5. React Compiler vs manual memo

When the **React Compiler** is enabled (Vite plugin / `babel-plugin-react-compiler`), it auto-memoizes components and values — **delete** manual `useMemo`/`useCallback`/`React.memo`; they're dead weight and noise.

```ts
// vite.config.ts
export default defineConfig({
  plugins: [react({ babel: { plugins: ["babel-plugin-react-compiler"] } })],
});
```

If the compiler is **not** on, memoize only what the Profiler proved expensive — not everything.

## 6. Narrow store selectors → re-render map

A component re-renders when a value it *subscribes to* changes. With Zustand, subscribe to the smallest slice:

```ts
// Bad: re-renders on any store change
const { count } = useCart();
// Good: re-renders only when the count changes
const count = useCart((s) => s.items.length);
```

Same principle for context: a high-write context re-renders every consumer, so high-frequency values belong in a store with selectors, not context.

## 7. Suspense for perceived speed

Wrap independent data regions in their own `<Suspense>` so each reveals as its query resolves instead of blocking the whole screen on the slowest fetch. Pair `useSuspenseQuery` (see `data-and-state.md`) with per-region boundaries.
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 197kUpdated Claude CodeCodexVerifiedInstall