nextjs-hydration-prevention

nextjs-hydration-prevention is a cursor rule for Cursor from rm2thaddeus/Pixel_Detective. It costs 0 tokens per session (697 once invoked), scanned C, original, MIT.

Rules for preventing Next.js hydration errors by keeping server-rendered and browser-rendered output consistent. Hydration is the process where browser-side code takes over HTML first rendered by the server.

In plain words
What is it for?
Use it when handling themes, color-mode setup, browser-only components, or any Next.js code that renders both on the server and in the browser.
Why use it?
It reduces mismatches that can cause warnings, broken layouts, or different content after a page loads.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when handling themes, color-mode setup, browser-only components, or any Next.js code that renders both on the server and in the browser.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/rm2thaddeus/Pixel_Detective

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for nextjs-hydration-prevention

README.md
[![agentmods](https://agentmods.dev/badge/rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention/github.svg)](https://agentmods.dev/rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention)
Your own site
<a href="https://agentmods.dev/rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention"><img src="https://agentmods.dev/badge/rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for nextjs-hydration-prevention

Your own site · 80×15
<a href="https://agentmods.dev/rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention"><img src="https://agentmods.dev/badge/rules/rm2thaddeus/pixel_detective/nextjs-hydration-prevention.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 697 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00697
Opus 5.5 $0.00000 $0.00279
Sonnet 5.5 $0.00000 $0.00139
Haiku 4.5 $0.00000 $0.00070

Measured 1mo ago against content hash 5018b8d3a755, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade C, and why

nextjs-hydration-prevention scanned grade C with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

1. **Clear caches**: `rm -rf .next && npm run dev`
frontend/.cursor/rules/nextjs-hydration-prevention.mdc · 107 lines

How it starts

The opening of the file, as written. The whole thing — 107 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Next.js Hydration Error Prevention Rules

🚨 CRITICAL: Server/Client Rendering Consistency

MANDATORY PATTERNS - ALWAYS USE:

1. Theme Provider Setup (Chakra UI)
// ✅ CORRECT: Two-stage rendering to prevent mismatches
const [mounted, setMounted] = useState(false);

useEffect(() => {
  setMounted(true);
}, []);

// During SSR - minimal theme
if (!mounted) {
  return <ChakraProvider theme={ssrTheme}>{children}</ChakraProvider>;
}

// After hydration - full theme
return <ChakraProvider theme={clientTheme}>{children}</ChakraProvider>;
2. ColorModeScript Placement
// ✅ ALWAYS in layout.tsx <head>
export default function RootLayout({ children }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <head>
        <ColorModeScript initialColorMode="light" />
      </head>
      <body><Provider>{children}</Provider></body>
    </html>
  );
}
3. Client-Only Components
// ✅ Use mounted state for browser-specific logic
const [mounted, setMounted] = useState(false);

useEffect(() => {
  setMounted(true);
}, []);

if (!mounted) {
  return <PlaceholderComponent />; // Server-safe fallback
}

return <BrowserSpecificComponent />; // Full functionality

FORBIDDEN PATTERNS - NEVER USE:

❌ Direct Browser API Access in Render
// ❌ NEVER: Causes hydration mismatch
function BadComponent() {
  return <div>Width: {window.innerWidth}</div>;
}

// ❌ NEVER: Different values on server/client
function BadComponent() {
  return <div>{Math.random()}</div>;
}

// ❌ NEVER: Time-dependent rendering
function BadComponent() {
  return <div>{new Date().toLocaleTimeString()}</div>;
}

DEBUGGING CHECKLIST:

Before any commit involving themes, client-only features, or dynamic content:

  • Test in production build: npm run build && npm start
  • Console clean: No hydration error messages
  • Theme consistency: Both light/dark modes work without flash
  • suppressHydrationWarning: Only on <html> tag, nowhere else
  • ColorModeScript: Always in <head>, matches theme config

Read the full file on GitHub · 107 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 107 lines · 0 tokens per session scan C 5018b8d3a755

Subscribe to this mod's changes

nextjs-hydration-prevention is a cursor rule published in the GitHub repository rm2thaddeus/Pixel_Detective (21 stars, last pushed 8mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 697 tokens. A static security scan graded it C with 1 finding (recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.