agentleFS
PanPanFRPanPanFR/oh-my-kilo/skills/vercel-react/SKILL.md

vercel-react

Skill12 starsChanged 3 months agoMITView on GitHub

React/Next.js performance optimization + composition patterns from Vercel Engineering. Covers 70+ rules: eliminating waterfalls, bundle optimization, server performance, re-render optimization, rendering performance, JS performance, advanced patterns, plus compound components, state management, React 19 APIs. Use for writing, reviewing, refactoring React/Next.js code.

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Key pattern: Start promises before awaiting, use Promise.all() or better-all for parallelism.

    line 35

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “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

Vercel React Best Practices + Composition Patterns

Unified skill combining performance rules (70+) with composition architecture patterns.

When to Apply

  • Writing new React components or Next.js pages
  • Implementing data fetching (client/server)
  • Reviewing code for performance issues
  • Refactoring existing React/Next.js code
  • Optimizing bundle size or load times
  • Designing component APIs (avoid boolean prop proliferation)
  • Building reusable component libraries

PART 1: PERFORMANCE RULES (Priority Order)

1. Eliminating Waterfalls (CRITICAL)

RuleDescription
async-cheap-condition-before-awaitCheck cheap sync conditions before awaiting flags
async-defer-awaitMove await into branches where actually used
async-parallelUse Promise.all() for independent operations
async-dependenciesUse better-all for partial dependencies
async-api-routesStart promises early, await late in API routes
async-suspense-boundariesUse Suspense to stream content

Key pattern: Start promises before awaiting, use Promise.all() or better-all for parallelism.

2. Bundle Size Optimization (CRITICAL)

RuleDescription
bundle-barrel-importsImport directly, avoid barrel files (lucide-react, MUI, etc.)
bundle-analyzable-pathsPrefer statically analyzable import paths
bundle-dynamic-importsUse next/dynamic for heavy components
bundle-defer-third-partyLoad analytics/logging after hydration
bundle-conditionalLoad modules only when feature activated
bundle-preloadPreload on hover/focus for perceived speed

Quick wins:

// ❌ Barrel import - loads 1500+ modules
import { Check, X } from 'lucide-react'

// ✅ Direct import (Next.js 13.5+ transforms automatically)
// ✅ Non-Next.js: import Check from 'lucide-react/dist/esm/icons/check'

3. Server-Side Performance (HIGH)

RuleDescription
server-auth-actionsAuthenticate inside Server Actions (not just middleware)
server-cache-reactUse React.cache() for per-request deduplication
server-cache-lruUse LRU cache for cross-request caching
server-dedup-propsAvoid duplicate serialization in RSC props
server-hoist-static-ioHoist static I/O (fonts, logos) to module level
server-no-shared-module-stateNo mutable module-level request state
server-serializationMinimize data passed to client components
server-parallel-fetchingRestructure components to parallelize fetches
server-parallel-nested-fetchingChain nested fetches per item in Promise.all
server-after-nonblockingUse after() for non-blocking operations

4. Client-Side Data Fetching (MEDIUM-HIGH)

RuleDescription
client-swr-dedupUse SWR for automatic request deduplication
client-event-listenersDeduplicate global event listeners
client-passive-event-listenersUse passive: true for scroll/touch
client-localstorage-schemaVersion and minimize localStorage data

5. Re-render Optimization (MEDIUM)

RuleDescription
rerender-defer-readsDon't subscribe to state only used in callbacks
rerender-memoExtract expensive work into memoized components
rerender-memo-with-default-valueHoist default non-primitive props to constants
rerender-dependenciesUse primitive dependencies in effects
rerender-derived-stateSubscribe to derived booleans, not raw values
rerender-derived-state-no-effectDerive state during render, not effects
rerender-functional-setstateUse functional setState for stable callbacks
rerender-lazy-state-initPass function to useState for expensive values
rerender-simple-expression-in-memoAvoid memo for simple primitives
rerender-split-combined-hooksSplit hooks with independent dependencies
rerender-move-effect-to-eventPut interaction logic in event handlers
rerender-transitionsUse startTransition for non-urgent updates
rerender-use-deferred-valueDefer expensive renders to keep input responsive
rerender-use-ref-transient-valuesUse refs for transient frequent values
rerender-no-inline-componentsDon't define components inside components

6. Rendering Performance (MEDIUM)

RuleDescription
rendering-animate-svg-wrapperAnimate div wrapper, not SVG element
rendering-content-visibilityUse content-visibility for long lists
rendering-hoist-jsxExtract static JSX outside components
rendering-svg-precisionReduce SVG coordinate precision
rendering-hydration-no-flickerUse inline script for client-only data
rendering-hydration-suppress-warningSuppress expected mismatches
rendering-activityUse Activity component for show/hide
rendering-conditional-renderUse ternary, not && for conditionals
rendering-usetransition-loadingPrefer useTransition for loading state
rendering-resource-hintsUse React DOM resource hints for preloading
rendering-script-defer-asyncUse defer/async on script tags

7. JavaScript Performance (LOW-MEDIUM)

RuleDescription
js-batch-dom-cssGroup CSS changes via classes or cssText
js-index-mapsBuild Map for repeated lookups
js-cache-property-accessCache object properties in loops
js-cache-function-resultsCache function results in module-level Map
js-cache-storageCache localStorage/sessionStorage reads
js-combine-iterationsCombine multiple filter/map into one loop
js-length-check-firstCheck array length before expensive comparison
js-early-exitReturn early from functions
js-hoist-regexpHoist RegExp creation outside loops
js-min-max-loopUse loop for min/max instead of sort
js-set-map-lookupsUse Set/Map for O(1) lookups
js-tosorted-immutableUse toSorted() for immutability
js-flatmap-filterUse flatMap to map and filter in one pass
js-request-idle-callbackDefer non-critical work to browser idle time

8. Advanced Patterns (LOW)

RuleDescription
advanced-effect-event-depsDon't put useEffectEvent results in effect deps
advanced-event-handler-refsStore event handlers in refs
advanced-init-onceInitialize app once per app load
advanced-use-latestuseLatest for stable callback refs

PART 2: COMPOSITION PATTERNS

1. Component Architecture (HIGH)

Avoid Boolean Prop Proliferation

// ❌ Boolean props create exponential complexity
function Composer({ isThread, isDMThread, isEditing, isForwarding }) { }

// ✅ Explicit variants with composition
function ThreadComposer({ channelId }) { }
function EditComposer() { }
function ForwardMessageComposer() { }

Use Compound Components

// Shared context, not props
const ComposerContext = createContext<ComposerContextValue | null>(null)

function ComposerProvider({ children, state, actions, meta }) {
  return <ComposerContext value={{ state, actions, meta }}>{children}</ComposerContext>
}

// UI components compose what they need
<Composer.Provider state={state} actions={actions} meta={meta}>
  <Composer.Frame>
    <Composer.Header />
    <Composer.Input />
    <Composer.Footer>
      <Composer.Formatting />
      <Composer.Submit />
    </Composer.Footer>
  </Composer.Frame>
</Composer.Provider>

2. State Management (MEDIUM)

Decouple State from UI

// Provider handles state implementation
function ChannelProvider({ channelId, children }) {
  const { state, update, submit } = useGlobalChannel(channelId)
  return (
    <Composer.Provider state={state} actions={{ update, submit }}>
      {children}
    </Composer.Provider>
  )
}

// UI only knows context interface
function ChannelComposer() {
  return <Composer.Frame>...</Composer.Frame>
}

Generic Context Interface (Dependency Injection)

interface ComposerState { input: string; attachments: Attachment[] }
interface ComposerActions { update: (s) => void; submit: () => void }
interface ComposerMeta { inputRef: React.RefObject<TextInput> }
interface ComposerContextValue { state: ComposerState; actions: ComposerActions; meta: ComposerMeta }

const ComposerContext = createContext<ComposerContextValue | null>(null)

Lift State to Provider

function ForwardMessageProvider({ children }) {
  const [state, setState] = useState(initialState)
  return (
    <Composer.Provider state={state} actions={{ update: setState, submit: forwardMessage }}>
      {children}
    </Composer.Provider>
  )
}

// Custom components OUTSIDE composer can access state
function ForwardButton() {
  const { actions: { submit } } = use(ComposerContext)
  return <Button onPress={submit}>Forward</Button>
}

3. Implementation Patterns (MEDIUM)

Create Explicit Variants

function ThreadComposer({ channelId }) {
  return (
    <ThreadProvider channelId={channelId}>
      <Composer.Frame>
        <Composer.Input />
        <AlsoSendToChannelField channelId={channelId} />
        <Composer.Footer>...</Composer.Footer>
      </Composer.Frame>
    </ThreadProvider>
  )
}

Prefer Children Over Render Props

// ✅ Children - flexible, readable
<Composer.Frame>
  <CustomHeader />
  <Composer.Input />
  <Composer.Footer>
    <Composer.Formatting />
    <Composer.Submit />
  </Composer.Footer>
</Composer.Frame>

// ❌ Render props - awkward, inflexible
<Composer renderHeader={() => <CustomHeader />} renderFooter={...} />

4. React 19 APIs (MEDIUM)

// ❌ forwardRef not needed in React 19
const ComposerInput = forwardRef((props, ref) => <TextInput ref={ref} {...props} />)

// ✅ ref as regular prop
function ComposerInput({ ref, ...props }) {
  return <TextInput ref={ref} {...props} />
}

// ❌ useContext
const value = useContext(MyContext)

// ✅ use() - can be called conditionally
const value = use(MyContext)

QUICK REFERENCE: TOP 10 IMPACT RULES

  1. async-parallel - Promise.all() for independent ops (2-10×)
  2. bundle-barrel-imports - Direct imports (15-70% faster dev, 40% faster cold starts)
  3. server-parallel-fetching - Component composition for parallel data (CRITICAL)
  4. server-parallel-nested-fetching - Chain per-item in Promise.all (CRITICAL)
  5. rerender-no-inline-components - Prevents remount, lost state (HIGH)
  6. rerender-derived-state-no-effect - Derive during render, not effects (MEDIUM)
  7. architecture-avoid-boolean-props - Composition over conditionals (HIGH)
  8. state-lift-state - Provider enables external access (HIGH)
  9. rendering-conditional-render - Ternary over && prevents bugs (MEDIUM)
  10. client-swr-dedup - Automatic deduplication (MEDIUM-HIGH)

HOW TO USE

For detailed explanations and code examples, reference individual rule files:

rules/async-parallel.md
rules/bundle-barrel-imports.md
rules/architecture-avoid-boolean-props.md
rules/state-context-interface.md

Full compiled document: AGENTS.md

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.