ethanniser/hydration-test/hydration-safe-inputs
Claude Code and agent skill by ethanniser/hydration-test
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Fix React hydration issues where user input typed before hydration gets wiped/cleared when React takes over. Use when (1) users report input fields clearing on page load, (2) working with SSR/SSG React apps (Next.js, Remix, Astro) that have controlled inputs, (3) auditing forms for hydration safety, or (4) building new forms in statically rendered React apps.
Install
npx vskill@latest install ethanniser/hydration-test/hydration-safe-inputsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Hydration-Safe Inputs
The Problem
In SSR/SSG React apps, there's a window between when HTML renders and when React hydrates. If a user types into an input during this window, React's hydration will wipe their input because React initializes state to the default value (usually empty string).
The Fix
Initialize state by reading the DOM element's current value instead of a hardcoded default:
Key Requirements
- Element needs an `id` - The initializer must find the element
- Use lazy initializer -
useState(() => ...)notuseState(...) - Guard for SSR - Check
typeof window !== "undefined" - Type check the element - Use
instanceof HTMLInputElement(orHTMLTextAreaElement,HTMLSelectElement)
Patterns by Input Type
Text Input
Checkbox
Select
Textarea
Identifying Vulnerable Components
Search for these patterns that indicate potential hydration wipe issues:
- Controlled inputs with hardcoded initial state:
``tsx // VULNERABLE const [value, setValue] = useState(""); return <input value={value} onChange={...} />; ``
- Form components in SSR/SSG pages - Any
"use client"component with controlled inputs in Next.js App Router, or any component inpages/directory
- Components without hydration-safe initialization - Missing the
typeof windowguard pattern
Refactoring Checklist
When fixing an existing component:
- Add unique
idto the input element - Replace
useState(defaultValue)withuseState(() => { ... }) - Add window check and DOM query in initializer
- Add appropriate
instanceoftype guard - Keep original default as SSR fallback
Custom Hook (Optional)
For apps with many inputs, extract to a reusable hook:
Testing
To verify the fix works:
- Add artificial hydration delay (slow network or blocking script)
- Type into the input before hydration completes
- Confirm input value persists after hydration
Example delay script for testing:
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hydration-safe-inputs/SKILL.md
Popularity
- Repository stars
- 18
- Repository forks
- 5
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 25 Mar 2026, 8 months ago.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ethanniser/hydration-test/hydration-safe-inputs)