Files
clawmates/skills/frontend/react-19-server-components.md
T
Omar SobhandClaude Opus 4.7 7b23f61632
ci / gates (push) Successful in 4s
ci / frontend (push) Successful in 25s
ci / rust (push) Failing after 3m41s
ci / e2e (push) Skipped
ci / publish (push) Skipped
slice 3.5c: seed 15 built-in skills across the 6 stacks
Hand-authored skill catalog anchored to real 2026-07 versions:
  - Rust 1.97.1 (stable), edition 2024
  - React 19.2.7, Server Components + Actions
  - TailwindCSS 4.3.3 (CSS-first config, Oxide engine)
  - three.js r185 (WebGPURenderer stable, BatchedMesh matured)
  - React Native 0.86 / Expo SDK 54+ (New Architecture default)
  - cargo-nextest 0.9.140, gitleaks 8.20+, cargo-audit 0.21+
  - Postgres 17 (18 in beta, don't rely on)
  - CUDA Blackwell, Metal Apple7+, ROCm CDNA3

Ships 15 skills across the categories:
  foundation/  workspace-repo-commit-protocol
               small-focused-commits
               tdd-red-green-refactor
               code-review-checklist
               int-xx-marker-protocol
               decompose-int-items
  rust/        write-rust-current-edition
               rust-error-handling
               cargo-test-driven-development
               rust-async-tokio-idioms
  backend/     postgres-migrations-forward-only
               postgres-index-selection
               api-pagination-day-1
  frontend/    react-19-server-components
               tailwind-v4-idioms
               component-4-state-model
  mobile/      expo-managed-vs-bare
               rn-flashlist-perf
  gpu/         gpu-coalescing-and-occupancy
               roofline-model
  threejs/     threejs-perf-and-teardown
  security/    cargo-audit-workflow
               secret-scanning-gitleaks

skills_loader.rs walks skills/**/*.md, parses YAML frontmatter
(name, description, when_to_use, tags), upserts via
skills_catalog::upsert_builtin. Idempotent per boot — bumps version
+ appends skill_versions row ONLY when body changes. Deterministic
sha256-derived ids so builtins are stable across boots.

Dockerfile copies skills/ to /etc/clawmates/skills. Server boot
task spawns loader alongside team_template_loader.

Follow-ups (Slice 3.5c continuation, future PRs):
  - 20-30 more skills (duckdb, shadcn composition, a11y, WebGPU
    migration, metal frame capture, rocprof, deep gitea forge
    integration, semgrep rulepacks)
  - Bind skills to team template roles (add [role.skills] refs to
    templates/teams/*.toml + wire template_role_skills population
    in team_template_loader)

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-07-19 13:55:44 -07:00

3.3 KiB

name, description, when_to_use, tags
name description when_to_use tags
react-19-server-components React 19.2 patterns — RSC by default, `use()` hook, Actions + useActionState, `use client` boundaries. You're writing React components in a Next.js 15+ app on React 19. Rust_sdlc + frontend teams pin this.
frontend
react
versioned

React 19 patterns (as of 19.2.7)

Server Components by default

  • Every new component is a Server Component unless it needs interactivity. use client opts in.
  • Why: no JS ships to the browser for pure-display components, data fetching happens at the source, secrets stay server-side.
  • When to use client:
    • Hooks (useState, useEffect, useReducer, custom hooks that use them).
    • Event handlers (onClick, onChange).
    • Browser-only APIs (window, document, IntersectionObserver).
    • Third-party libs that call useLayoutEffect internally.

Pattern: keep the parent server, extract the interactive leaf as client:

// list.tsx (server component)
export async function List() {
  const items = await db.items.findMany();
  return (
    <div>
      {items.map((i) => <Row key={i.id} item={i} />)}
      <RefreshButton />          {/* client leaf */}
    </div>
  );
}

// refresh-button.tsx
"use client";
export function RefreshButton() {
  return <button onClick={() => router.refresh()}>Refresh</button>;
}

The use() hook

Read a promise or context inside a component (server OR client):

import { use } from "react";
export function User({ userPromise }: { userPromise: Promise<User> }) {
  const user = use(userPromise);          // suspends until resolved
  return <div>{user.name}</div>;
}
  • Wrap in <Suspense fallback={...}> at the boundary you want to loading-state.
  • Works with context: const theme = use(ThemeContext) — can be called conditionally, unlike useContext.

Actions + useActionState

Server actions handle mutations without an API route:

"use client";
import { useActionState } from "react";

async function submit(prev: State, formData: FormData) {
  "use server";
  await db.thing.create({ data: formData });
  return { ok: true };
}

export function Form() {
  const [state, action, pending] = useActionState(submit, { ok: false });
  return (
    <form action={action}>
      <input name="title" />
      <button disabled={pending}>Save</button>
      {state.ok && <p>Saved!</p>}
    </form>
  );
}

useOptimistic

For instant UI feedback on mutations:

const [optimistic, addOptimistic] = useOptimistic(items, (state, next) => [...state, next]);

What changed vs React 18

  • forwardRef is optional — regular components accept ref as a prop (19.0+).
  • use client boundary is enforced — you can't useState in a Server Component. Fails at build.
  • Removed: React.createRef in functional components (was already deprecated), string refs.

Common bugs

  • Passing a function from a Server Component to a Client Component prop — fails serialization. Solution: define the function inside the client component or pass a Server Action.
  • useState in an async Server Component — build error. Extract the interactive part to a "use client" leaf.
  • document accessed in the top level of a client component file — SSR runs the top level, blows up. Guard with if (typeof window !== "undefined") or move into an effect.