agentleFS
dafaalzdafaalz/agent-skills/skills/react/SKILL.md

react

Skill2 starsChanged 51 days agoMITView on GitHub

Use when auditing and optimizing React/Next.js application performance, component waterfalls, bundle sizes, Server Actions, or re-render dependencies. Don't use for CSS design (use frontend-design), UX usability critiques (use ui-ux-review), UI prototyping (use prototype), CSS/spring animations (use ui-motion), or multi-task execution plans (use agent-planning).

48 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use app-renderer-systems, refactoring-analysis and 9 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • pedronauckSkill

    app-renderer-systems

    Create, extend, or debug frontend domain modules organized under systems/. Covers adapters, Query hooks, local state, and public exports; excludes generic components and backend implementation.

    Also in 3 projects that use this

  • pedronauckSkill

    refactoring-analysis

    Audit code quality and architectural health or plan refactoring using Fowler code smells and techniques; write prioritized findings to docs/_refacs/. Excludes formatting, performance, and security audits.

    Also in 3 projects that use this

  • andyridsSkill

    express

    Run the ICM express-change pipeline - a small change no spec has to move for, with the plan record left intact

    Also in 4 projects that use this

  • tondevrelSkill

    pytorch

    Leading deep learning framework. Provides Tensors and Dynamic Computational Graphs with strong GPU acceleration. Widely used for research, neural networks, and differentiable programming.

    Also in 3 projects that use this

  • azlekovSkill

    tailwindcss

    This skill should be used when the user asks to "style with Tailwind", "add CSS", "configure theme", "use @theme", "add custom colors", "implement dark mode", "use container queries", "add responsive design", "use OKLCH colors", or discusses styling, theming, or visual design. Always use the latest Tailwind CSS version and modern patterns.

    Also in 5 projects that use this

  • jander99Skill

    typescript-advanced

    Design, implement, refactor, and debug advanced TypeScript patterns including generics, utility types, mapped types, conditional types, type guards, discriminated unions, and strict mode configuration. Use when writing type-safe code, fixing type errors, or improving type inference.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

10 rules. 0 are common, 3 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 38 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow these five steps in sequence.

    line 28
  2. Very specific:

    Check React version, Next.js version, and compiler configuration across package.json and Next.js config:

    line 34
  3. Very specific:

    Run TypeScript compiler diagnostics with Next.js route typegen:

    line 38
  4. Very specific:

    Read the specific rule file in references/rules/<prefix>-<name>.md for concrete code implementations, anti-patterns, and mechanical fixes.

    line 60
  5. Very specific:

    Place Server Actions in dedicated files with 'use server' at the top (never inside 'use client' files).

    line 68
  6. Very specific:

    When compiler: true, do not add manual useMemo, useCallback, or React.memo.

    line 69
  7. Very specific:

    Use .reduce() instead of Math.max(...array) for numeric aggregations over dynamic datasets to prevent call stack size limits.

    line 71
  8. Distinctive:

    Run build commands, test suites, and type checks to verify that the bottleneck is eliminated:

    line 77
  9. Distinctive:

    Never modify component visual aesthetics, design tokens, or typography in the name of performance.

    line 88
  10. Very specific:

    Ensure 'use client' is explicitly declared at the top of client component files.

    line 91

“Common” is measured: kept by at least 6 in 10 of the 38 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

React

Performance optimization and architectural patterns for React and Next.js applications. Profile and optimize React and Next.js applications by eliminating network waterfalls, managing bundle size, and reducing unnecessary re-renders.

<HARD-GATE> Write-Target Boundary. In Audit mode, do not modify any source file outside `.agents/state/react/`. In Optimize mode, modify only component files, dynamic import boundaries, Server Action files, and RSC or client boundary declarations. Never modify backend API route contracts, database schemas, business validation, or accessibility attributes. Emit audit reports to `.agents/state/react/audit-report.md` before changing code. </HARD-GATE>

Modes

Select an execution mode before Step 1:

  • Audit mode (default). Profile bundles, waterfalls, and re-renders, and report findings without editing source code.
  • Optimize mode. Restructure Server and Client boundaries, stream Suspense trees, split chunks, upgrade action hooks, and apply compiler-safe optimizations.

Reference quick routing

Optimization domainReference moduleScope
Render & network optimizationreferences/render-optimization.mdReact 19 mutations, Core Web Vitals, & waterfalls

Workflow

Follow these five steps in sequence.

Step 1. Toolchain probe and bottleneck identification

Probe the project runtime, compiler configuration, and performance symptoms before modifying code:

  1. Check React version, Next.js version, and compiler configuration across package.json and Next.js config:
    node -e "const fs=require('fs'),p=JSON.parse(fs.readFileSync('package.json','utf8')),d={...p.dependencies,...p.devDependencies},c=['next.config.ts','next.config.mjs','next.config.js'].find(f=>fs.existsSync(f));console.log({react:d.react,next:d.next,compiler:Boolean(d['babel-plugin-react-compiler']||(c&&/reactCompiler\s*:\s*true/.test(fs.readFileSync(c,'utf8'))))})"
  2. Run TypeScript compiler diagnostics with Next.js route typegen:
    npx next typegen && npx tsc --noEmit
  3. Profile component rendering or network waterfalls to isolate the exact bottleneck.

Completion criterion. .agents/state/react/baseline.json exists on disk with fields react_version, next_version, compiler, tsc_errors (0), perf_metric_name, perf_metric_baseline, perf_metric_threshold, and perf_metric_source. perf_metric_source is one of lighthouse-json, web-vitals-lib, next-bundle-analyzer, or manual-profiler. Attach the raw measurement artifact path to perf_metric_source_path. A baseline without a source artifact is rejected.

Step 2. Rule selection and priority triage

Filter rules by the React version detected in Step 1:

  • React 19 or later. All categories apply, including server- and modern action hooks.
  • React 18. Skip useActionState and useOptimistic upgrades. Use useTransition for pending states. Retain forwardRef rather than passing ref as standard prop. Skip compiler optimizations when compiler: false.
  • React 17 or earlier. Skip all Server Component and Server Action rules. Confine optimizations to bundle-, client-, and rerender- categories.

Record category selection in .agents/state/react/rule-selection.json. Enforce joint security and serialization invariants: every RSC or Server Action change must verify server authorization and Client boundary DTO safety.

Completion criterion. .agents/state/react/rule-selection.json exists on disk with fields react_version and applied_categories matching the project runtime.

Step 3. Reference consultation

Read the specific rule file in references/rules/<prefix>-<name>.md for concrete code implementations, anti-patterns, and mechanical fixes.

Completion criterion. The rule file is inspected and the canonical fix pattern is established before mutating source files.

Step 4. Surgical implementation

Apply minimal code changes to eliminate the bottleneck:

  • Upgrade legacy useState/useEffect mutation flows to React 19 useActionState, useOptimistic, and uncontrolled FormData when on React 19. Before replacing a controlled form, verify that input state survives network failure per ui-ux-review INV-7. If uncontrolled migration would drop draft persistence, retain the controlled form and use useActionState solely for submit-state tracking.
  • Place Server Actions in dedicated files with 'use server' at the top (never inside 'use client' files). Validate session credentials and tenant access inside the action. Return serializable discriminated unions (ActionState { ok: boolean, error: string | null }) instead of throwing raw errors that Next.js censors in production.
  • When compiler: true, do not add manual useMemo, useCallback, or React.memo. Use immutable derivations (.toSorted()) and accept ref as a standard React 19 prop.
  • For high-frequency interactive controls like range sliders, separate local thumb position state from transitioned data filtering to preserve responsive input tracking.
  • Use .reduce() instead of Math.max(...array) for numeric aggregations over dynamic datasets to prevent call stack size limits.

Completion criterion: Targeted components implement the rule pattern with zero orphan imports, verified security boundaries, and clean compiler derivation paths.

Step 5. Verification pass

Run build commands, test suites, and type checks to verify that the bottleneck is eliminated:

npx next typegen && npx tsc --noEmit && npm test

Completion criterion: Clean build exit code, passing test assertions, and verified elimination of the target performance defect.

Boundary isolation

Confine optimization strictly to component rendering patterns, bundle splitting, and data fetching:

  • Preserve backend API route contracts, database schemas, and business validation logic.
  • Never modify component visual aesthetics, design tokens, or typography in the name of performance.
  • Preserve existing accessibility attributes and semantic markup; never remove aria attributes or keyboard handlers to simplify rendering.
  • Preserve public exported signatures, but narrow internal 'use client' props to minimal serializable DTOs. Block raw database model leakage across the Client boundary using experimental_taintObjectReference.
  • Ensure 'use client' is explicitly declared at the top of client component files.
  • Type Next.js 15 params and searchParams as Promises (Promise<{ slug: string }>) and await them concurrently with cookies().
  • Guard concurrent RSC reads with Promise.allSettled and an AbortController timeout signal to prevent whole-page crashes and detached orphaned queries.

Rule categories by priority

PriorityCategoryImpactPrefixFocus
1Eliminating WaterfallsCRITICALasync-Parallelize requests, defer await, use streaming
2Server Actions and SecurityCRITICALserver-Server Actions auth, RSC caching, minimize client serialization
3Bundle Size OptimizationHIGHbundle-Tree-shaking, dynamic imports, avoid barrel files
4Client-Side Data FetchingMEDIUM-HIGHclient-SWR deduplication, passive listeners, compact client storage
5Re-render OptimizationMEDIUMrerender-Primitive dependencies, state colocation, deferred values
6Rendering PerformanceMEDIUMrendering-Content visibility, ternary conditionals, SVG animation wrappers
7JavaScript PerformanceLOW-MEDIUMjs-Map and Set lookups, early exits, loop hoisting
8Advanced PatternsLOWadvanced-Stable callback refs, single initialization, event handler refs

Detailed rule specifications, code examples, and bad versus good patterns are stored individually in references/rules/<prefix>-<name>.md.

Quick audit checklist

Review this table before completing React optimization tasks:

CheckPassing condition
Next.js 15 dynamic APIsparams, searchParams, and cookies() awaited properly as Promises
WaterfallsData dependencies run concurrently via Promise.allSettled with AbortController timeout
Suspense streamingHeavy or slow queries deferred and streamed via <Suspense> boundaries
Boundary serializationInternal 'use client' props narrowed to safe DTOs; raw ORM records tainted
Server ActionsActions declared in 'use server' files, verify session auth, and return serializable union results
Modern actionsForms use useActionState, useOptimistic, and uncontrolled inputs with rollback
Compiler compatibilityZero redundant useMemo/useCallback when compiler active; immutable derivations used
Native propsComponents accept ref as standard prop without legacy forwardRef
Input responsivenessHigh-frequency sliders decouple immediate thumb state from heavy transitioned filtering
Array aggregationAggregations use .reduce() instead of spreading unbounded arrays
Bundle sizeHeavy client modules split dynamically with tree-shaking preserved
AccessibilitySemantic elements, ARIA attributes, and focus order preserved intact
VerificationAutomated tests pass and TypeScript emits zero diagnostic errors

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.