sickn33/agentic-awesome-skills / plugins/aasb-web-app/skills/react-best-practices
react-best-practices
VerifiedComprehensive performance optimization guide for React and Next.js applications, adapted from Vercel’s published guidance. Use when writing new React components or Next.js pages, implementing data fetching (client or server-side), or reviewing code for performance issues.
rules/rendering-hydration-no-flicker.md
View on GitHub---
title: Prevent Hydration Mismatch Without Flickering
impact: MEDIUM
impactDescription: avoids visual flicker and hydration errors
tags: rendering, ssr, hydration, localStorage, flicker
---
## Render Consistent Theme State
Render the same authorized theme on server and first client render. When a validated non-sensitive theme cookie is available, select it on the server. Otherwise start with the same default on both sides, read storage in an Effect with try/catch, allow only known theme values and accept a possible theme flash.
A framework-supported pre-hydration theme script can reduce flicker, but requires CSP nonce/hash handling and intentional hydration configuration. Mutating an arbitrary div before hydration does not by itself prevent a hydration mismatch. Never interpolate untrusted storage into executable code, enable unsafe-inline globally, or derive authentication from client storage.
**Example (deterministic initial render):**
```tsx
'use client'
import { useEffect, useState } from 'react'
export function ThemeWrapper({ children }: { children: React.ReactNode }) {
const [theme, setTheme] = useState('light')
useEffect(() => {
try {
const value = localStorage.getItem('theme')
if (value === 'light' || value === 'dark') setTheme(value)
} catch { /* denied storage: retain the default */ }
}, [])
return <div className={theme}>{children}</div>
}
```
**Limitation:** This fallback can flash the default theme. Test hydration, CSP, preference changes and accessibility in the actual framework.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |