Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Nextjs Ssr Hydration Fixer

    1

    Diagnose and fix Next.js SSR hydration mismatches, window/localStorage checks, and non-deterministic UI errors.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Nextjs Ssr Hydration Fixer

    Nextjs Ssr Hydration Fixer

    Example session with this skill installed

    I am getting 'Hydration failed because the initial UI does not match' error in my Next.js navbar because I am checking for a 'theme' in localStorage. Help me fix this.

    • Read your context and instructions
    • Compiled the nextjs ssr hydration
    • Generated the UI component

    I have analyzed the hydration mismatch in your navbar. The error occurs because the server attempts to render the theme-specific UI, but `localStorage` is only available on the client. I have refactored the component using a two-pass rendering pattern with a `useIsMounted` hook to ensure the client-only state is only rendered after hydration. ## Fixed Navbar Component ```tsx 'use client'; import { useState, useEffect } from 'react'; export default function Navbar() { const [isMounted, setIsMounted] = useState(false); const [theme, setTheme] = useState('light'); // Step 1: Handle hydration by waiting for mount useEffect(() => { setIsMounted(true); const savedTheme = localStorage.getItem('theme'); if (savedTheme) { setTheme(savedTheme); } }, []); // Step 2: Render a placeholder or null during SSR to avoid mismatch if (!isMounted) { return <nav className="h-16 bg-gray-100" />; // Matching height skeleton } return ( <nav className={`h-16 ${theme === 'dark' ? 'bg-black text-white' : 'bg-white text-black'}`}> <div className="max-w-7xl mx-auto px-4"> <span>Current Theme: {theme}</span> <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}> Toggle </button> </div> </nav> ); } ``` **Next steps** 1. Replace your existing `Navbar.tsx` with this refactored code. 2. If you have multiple components needing this fix, consider moving the `isMounted` logic into a shared `hooks/useIsMounted.ts` file. 3. Check for any `<p>` tags in the parent component that might be wrapping this navbar to prevent nesting errors.

    Navbar.tsx

    TSX · React component

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Next.js hydration mismatches cause broken layouts, console noise, and failed SEO audits. This skill provides a systematic approach to identifying and fixing SSR errors where server-rendered HTML fails to sync with the client-side DOM. ## What it does - **Root cause analysis** scans code for non-deterministic values like `window`, `localStorage`, or random IDs that break SSR. - **Two-pass rendering** implements `useIsMounted` hooks or client-side mounting logic to ensure consistent hydration. - **Dynamic component injection** configures `next/dynamic` with `ssr: false` for problematic third-party libraries. - **HTML structure validation** detects and repairs invalid nesting such as interactive elements inside anchors or paragraphs wrapping blocks. - **State synchronization** ensures dates and localized strings match across the server-client boundary. ## How it works 1. **Analyze** the provided React component or error log to pinpoint the hydration trigger. 2. **Apply** the appropriate fix pattern, such as a custom mounting hook or dynamic import. 3. **Refactor** the component structure to eliminate HTML nesting antipatterns. 4. **Generate** clean, production-ready code for either App Router or Pages Router architectures. ## Frameworks & tools Built specifically for Next.js (App and Pages Router) and React. Handles standard Web APIs like `window`, `localStorage`, and `Intl` date formatting. ## Why this beats prompting it yourself Generic prompts often lead to "quick fixes" like suppressing warnings, which hide bugs rather than solving them. This skill uses a deterministic workflow to implement the two-pass rendering pattern correctly, preventing layout shifts and flickering. ## Use cases - **Browser API access** fixing errors caused by using `window` or `document` during initial render. - **Non-deterministic data** resolving mismatches from random IDs or server-side dates. - **Third-party widgets** wrapping client-only libraries that do not support SSR. - **Legacy nesting** cleaning up invalid HTML tags that trigger DOM nesting warnings. ## Known limitations Does not perform global project-wide static analysis. You must provide the specific component or file causing the hydration error.

    Requires the specific file or component code causing the error. Limited to Next.js and React environments.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 3 days ago

    Requires

    File System Read/Write (strictly scoped to current project workspace `./`).
    Zero global installation or elevated privileges required.

    Permissions

    Read Files

    Target Use Cases: - Fix Next.js hydration mismatch error in React component. - Resolve 'Text content did not match server-rendered HTML' in Next.js. - Diagnose client-side hydration failure with localStorage.

    Listed3 days ago

    What's inside

    Frequently Asked Questions

    This skill identifies and resolves 'Hydration Mismatch' errors where the server-rendered HTML doesn't match the client-side DOM, preventing layout shifts and broken interactivity.

    It is compatible with both the modern App Router and the classic Pages Router, supporting TypeScript and standard JavaScript implementations.

    No complex installation is required; simply provide the skill with your problematic component code or the specific error log from your console to begin the refactoring process.

    The skill provides production-ready code patterns, such as implementing 'useIsMounted' hooks or configuring 'next/dynamic' imports with SSR disabled for third-party libraries.

    While it can analyze large files, it works best when you provide the specific component or module triggering the hydration warning for a more targeted and accurate fix.

    Yes, the skill is updated regularly to align with the latest Next.js and React releases, ensuring that the generated fixes follow current best practices for performance and SEO.

    New in Frontend & Web Apps