← Back to Skills Marketplace
wpank

React Performance

by wpank · GitHub ↗ · v1.0.0
cross-platform ✓ Security Clean
1616
Downloads
1
Stars
9
Active Installs
1
Versions
Install in OpenClaw
/install react-performance
Description
React and Next.js performance optimization patterns. Use when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance. Triggers on tasks involving components, data fetching, bundle optimization, re-render reduction, or server component architecture.
README (SKILL.md)

React Performance Patterns

Performance optimization guide for React and Next.js applications. Patterns across 7 categories, prioritized by impact. Detailed examples in references/.

When to Apply

  • Writing new React components or Next.js pages
  • Implementing data fetching (client or server-side)
  • Reviewing or refactoring for performance
  • Optimizing bundle size or load times

Categories by Priority

# Category Impact
1 Async / Waterfalls CRITICAL
2 Bundle Size CRITICAL
3 Server Components HIGH
4 Re-renders MEDIUM
5 Rendering MEDIUM
6 Client-Side Data MEDIUM
7 JS Performance LOW-MEDIUM

Installation

OpenClaw / Moltbot / Clawbot

npx clawhub@latest install react-performance

1. Async — Eliminating Waterfalls (CRITICAL)

Parallelize independent operations

Sequential awaits are the single biggest performance mistake in React apps.

// BAD — sequential, 3 round trips
const user = await fetchUser()
const posts = await fetchPosts()
const comments = await fetchComments()

// GOOD — parallel, 1 round trip
const [user, posts, comments] = await Promise.all([
  fetchUser(), fetchPosts(), fetchComments(),
])

Defer await until needed

Move await into branches where the value is actually used.

// BAD — blocks both branches
async function handle(userId: string, skip: boolean) {
  const data = await fetchUserData(userId)
  if (skip) return { skipped: true }    // Still waited
  return process(data)
}

// GOOD — only blocks when needed
async function handle(userId: string, skip: boolean) {
  if (skip) return { skipped: true }    // Returns immediately
  return process(await fetchUserData(userId))
}

Strategic Suspense boundaries

Show layout immediately while data-dependent sections load independently.

// BAD — entire page blocked
async function Page() {
  const data = await fetchData()
  return \x3Cdiv>\x3CSidebar />\x3CHeader />\x3CDataDisplay data={data} />\x3CFooter />\x3C/div>
}

// GOOD — layout renders immediately, data streams in
function Page() {
  return (
    \x3Cdiv>
      \x3CSidebar />\x3CHeader />
      \x3CSuspense fallback={\x3CSkeleton />}>\x3CDataDisplay />\x3C/Suspense>
      \x3CFooter />
    \x3C/div>
  )
}
async function DataDisplay() {
  const data = await fetchData()
  return \x3Cdiv>{data.content}\x3C/div>
}

Share a promise across components with use() to avoid duplicate fetches.


2. Bundle Size (CRITICAL)

Avoid barrel file imports

Barrel files load thousands of unused modules. Direct imports save 200-800ms.

// BAD — loads 1,583 modules
import { Check, X, Menu } from 'lucide-react'

// GOOD — loads only 3 modules
import Check from 'lucide-react/dist/esm/icons/check'
import X from 'lucide-react/dist/esm/icons/x'
import Menu from 'lucide-react/dist/esm/icons/menu'

Next.js 13.5+: use experimental.optimizePackageImports in config. Commonly affected: lucide-react, @mui/material, react-icons, @radix-ui, lodash, date-fns.

Dynamic imports for heavy components

import dynamic from 'next/dynamic'
const MonacoEditor = dynamic(
  () => import('./monaco-editor').then((m) => m.MonacoEditor),
  { ssr: false }
)

Defer non-critical third-party libraries

Analytics, logging, error tracking — load after hydration with dynamic() and { ssr: false }.

Preload on user intent

const preload = () => { void import('./monaco-editor') }
\x3Cbutton onMouseEnter={preload} onFocus={preload} onClick={onClick}>Open Editor\x3C/button>

3. Server Components (HIGH)

Minimize serialization at RSC boundaries

Only pass fields the client actually uses across the server/client boundary.

// BAD — serializes all 50 user fields
return \x3CProfile user={user} />

// GOOD — serializes 1 field
return \x3CProfile name={user.name} />

Parallel data fetching with composition

RSC execute sequentially within a tree. Restructure to parallelize.

// BAD — Sidebar waits for header fetch
export default async function Page() {
  const header = await fetchHeader()
  return \x3Cdiv>\x3Cdiv>{header}\x3C/div>\x3CSidebar />\x3C/div>
}

// GOOD — sibling async components fetch simultaneously
async function Header() { return \x3Cdiv>{await fetchHeader()}\x3C/div> }
async function Sidebar() { return \x3Cnav>{(await fetchSidebarItems()).map(renderItem)}\x3C/nav> }
export default function Page() { return \x3Cdiv>\x3CHeader />\x3CSidebar />\x3C/div> }

React.cache() for per-request deduplication

import { cache } from 'react'
export const getCurrentUser = cache(async () => {
  const session = await auth()
  if (!session?.user?.id) return null
  return await db.user.findUnique({ where: { id: session.user.id } })
})

Use primitive args (not inline objects) — React.cache() uses Object.is. Next.js auto-deduplicates fetch, but React.cache() is needed for DB queries, auth checks, and computations.

after() for non-blocking operations

import { after } from 'next/server'
export async function POST(request: Request) {
  await updateDatabase(request)
  after(async () => { logUserAction({ userAgent: request.headers.get('user-agent') }) })
  return Response.json({ status: 'success' })
}

4. Re-render Optimization (MEDIUM)

Derive state during render — not in effects

// BAD — redundant state + effect
const [fullName, setFullName] = useState('')
useEffect(() => { setFullName(first + ' ' + last) }, [first, last])

// GOOD — derive inline
const fullName = first + ' ' + last

Functional setState for stable callbacks

// BAD — recreated on every items change
const addItem = useCallback((item: Item) => {
  setItems([...items, item])
}, [items])

// GOOD — stable, always latest state
const addItem = useCallback((item: Item) => {
  setItems((curr) => [...curr, item])
}, [])

Defer state reads to usage point

Don't subscribe to dynamic state if you only read it in callbacks.

// BAD — re-renders on every searchParams change
const searchParams = useSearchParams()
const handleShare = () => shareChat(chatId, { ref: searchParams.get('ref') })

// GOOD — reads on demand
const handleShare = () => {
  const ref = new URLSearchParams(window.location.search).get('ref')
  shareChat(chatId, { ref })
}

Lazy state initialization

// BAD — JSON.parse runs every render
const [settings] = useState(JSON.parse(localStorage.getItem('s') || '{}'))

// GOOD — runs only once
const [settings] = useState(() => JSON.parse(localStorage.getItem('s') || '{}'))

Subscribe to derived booleans

// BAD — re-renders on every pixel
const width = useWindowWidth(); const isMobile = width \x3C 768

// GOOD — re-renders only when boolean flips
const isMobile = useMediaQuery('(max-width: 767px)')

Transitions for non-urgent updates

// BAD — blocks UI on scroll
const handler = () => setScrollY(window.scrollY)

// GOOD — non-blocking
const handler = () => startTransition(() => setScrollY(window.scrollY))

Extract expensive work into memoized components

const UserAvatar = memo(function UserAvatar({ user }: { user: User }) {
  const id = useMemo(() => computeAvatarId(user), [user])
  return \x3CAvatar id={id} />
})
function Profile({ user, loading }: Props) {
  if (loading) return \x3CSkeleton />
  return \x3Cdiv>\x3CUserAvatar user={user} />\x3C/div>
}

Note: React Compiler makes manual memo()/useMemo() unnecessary.


5. Rendering Performance (MEDIUM)

CSS content-visibility for long lists

For 1000 items, browser skips ~990 off-screen (10x faster initial render).

.list-item { content-visibility: auto; contain-intrinsic-size: 0 80px; }

Hoist static JSX outside components

Avoids re-creation, especially for large SVG nodes. React Compiler does this automatically.

const skeleton = \x3Cdiv className="skeleton" />
function Container() { return \x3Cdiv>{loading && skeleton}\x3C/div> }

6. Client-Side Data (MEDIUM)

SWR for deduplication and caching

// BAD — each instance fetches independently
useEffect(() => { fetch('/api/users').then(r => r.json()).then(setUsers) }, [])

// GOOD — multiple instances share one request
const { data: users } = useSWR('/api/users', fetcher)

7. JS Performance (LOW-MEDIUM)

Set/Map for O(1) lookups

// BAD — O(n)
items.filter(i => allowed.includes(i.id))
// GOOD — O(1)
const allowedSet = new Set(allowed)
items.filter(i => allowedSet.has(i.id))

Combine array iterations

// BAD — 3 passes
const a = users.filter(u => u.isAdmin)
const t = users.filter(u => u.isTester)
// GOOD — 1 pass
const a: User[] = [], t: User[] = []
for (const u of users) { if (u.isAdmin) a.push(u); if (u.isTester) t.push(u) }

Also: early returns, cache property access in loops, hoist RegExp outside loops, prefer for...of for hot paths.


Quick Decision Guide

  1. Slow page load? → Bundle size (2), then async waterfalls (1)
  2. Sluggish interactions? → Re-renders (4), then JS perf (7)
  3. Server page slow? → RSC serialization & parallel fetching (3)
  4. Client data stale/slow? → SWR (6)
  5. Long lists janky? → content-visibility (5)
Usage Guidance
This skill is an instruction-only guide for React/Next.js performance and appears internally consistent. Before installing or running any suggested installer commands, verify the publisher/source (homepage is missing and owner ID is opaque). If you plan to add it to an agent, inspect the skill files locally first — there are no required secrets or binaries, and no code will be executed by the platform automatically. Avoid running unfamiliar npx commands or URLs without reviewing them; if you need autonomous agent use, remember the agent could invoke the skill during eligible tasks, but this skill itself doesn't request elevated privileges or access to credentials.
Capability Analysis
Type: OpenClaw Skill Name: react-performance Version: 1.0.0 The skill bundle provides documentation and code examples for React and Next.js performance optimization. All content, including SKILL.md, README.md, and reference files, is purely educational and descriptive. There is no evidence of malicious intent, such as data exfiltration, unauthorized command execution, persistence mechanisms, or prompt injection attempts against the AI agent. The installation instructions are standard for OpenClaw skills or involve direct `npx add` from a GitHub URL, which, while a potential supply chain vector if the source were compromised, does not constitute malicious behavior *within* the analyzed skill bundle itself.
Capability Assessment
Purpose & Capability
Name/description match the included SKILL.md and reference files: all content is performance guidance for React/Next.js and the examples, patterns, and recommendations align with that purpose.
Instruction Scope
SKILL.md contains only code examples, patterns, and usage guidance. It does not instruct the agent to read system files, access environment variables, transmit data to external endpoints, or run arbitrary shell commands beyond a suggestion for installing via clawhub/npm tooling.
Install Mechanism
There is no formal install spec and no code files to execute (lowest-risk). The README and SKILL.md mention installation commands (npx clawhub@latest install and an npx add GitHub URL). These are suggestions only — there is no bundled installer — but the GitHub 'tree' URL and the npx add usage are somewhat unusual; verify any installer command before running it locally.
Credentials
The skill declares no required environment variables, binaries, or config paths. Nothing in the instructions references credentials or external secrets.
Persistence & Privilege
always is false and the skill has no install-time side effects described. It does not request permanent presence or system-wide configuration changes.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install react-performance
  3. After installation, invoke the skill by name or use /react-performance
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release – performance optimization patterns for React and Next.js: - Prioritized optimization patterns across critical areas: async/waterfalls, bundle size, server components, re-render reduction, and more - Clear examples for eliminating waterfalls, optimizing imports, and reducing bundle size - Guidance on parallel data fetching, minimizing client/server serialization, and using Suspense effectively - Concrete recommendations for state, memoization, transitions, and event handling - Includes installation instructions and describes real-world triggers for usage
Metadata
Slug react-performance
Version 1.0.0
License
All-time Installs 10
Active Installs 9
Total Versions 1
Frequently Asked Questions

What is React Performance?

React and Next.js performance optimization patterns. Use when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance. Triggers on tasks involving components, data fetching, bundle optimization, re-render reduction, or server component architecture. It is an AI Agent Skill for Claude Code / OpenClaw, with 1616 downloads so far.

How do I install React Performance?

Run "/install react-performance" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is React Performance free?

Yes, React Performance is completely free (open-source). You can download, install and use it at no cost.

Which platforms does React Performance support?

React Performance is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created React Performance?

It is built and maintained by wpank (@wpank); the current version is v1.0.0.

💬 Comments