P
💻DeveloppementAdvancedAll AIs

Prompt to Master SSR and Hydration with Next.js

A complete prompt to diagnose, implement and optimize Server-Side Rendering and hydration in a Next.js application, with common error handling.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert Next.js spécialisé en Server-Side Rendering et hydratation. Mon projet utilise [VERSION_NEXTJS] avec le [APP_ROUTER|PAGES_ROUTER]. Voici mon contexte :

  • Page concernée : [DESCRIPTION_PAGE]
  • Problème ou objectif : [PROBLEME_OU_OBJECTIF]
  • Stack technique : [STACK_TECHNIQUE]

Analyse ma situation et fournis-moi :

  1. Diagnostic SSR/Hydratation : Identifie les erreurs potentielles d'hydratation (mismatch client/serveur), les composants qui ne devraient pas être rendus côté serveur, et les accès incorrects à des API navigateur (window, document, localStorage).

  2. Architecture de rendu optimale : Propose la stratégie de rendu adaptée pour chaque composant de ma page (Server Component, Client Component, SSR, SSG, ISR) en justifiant chaque choix. Indique clairement où placer les directives 'use client' et 'use server'.

  3. Code corrigé/optimisé : Réécris le code concerné avec les bonnes pratiques :

    • Séparation claire des Server et Client Components
    • Gestion correcte du hydration mismatch (useEffect, dynamic imports avec ssr: false, Suspense boundaries)
    • Streaming SSR avec loading.tsx si pertinent
    • Gestion du cache et revalidation (revalidatePath, revalidateTag)
  4. Data fetching : Recommande le pattern de récupération de données adapté (fetch dans Server Components, Route Handlers, Server Actions) avec gestion d'erreurs et loading states.

  5. Performance : Mesure l'impact sur les Core Web Vitals (LCP, FID, CLS) et propose des optimisations concrètes (lazy loading, prefetch, parallel data fetching).

  6. Tests : Fournis un exemple de test vérifiant que le SSR produit le HTML attendu et que l'hydratation se déroule sans erreur.

Formate ta réponse avec du code TypeScript commenté et des explications claires pour chaque décision.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt is designed to get a comprehensive analysis of your Next.js rendering architecture. By specifying your Next.js version and router type, the AI adapts its recommendations to available APIs (App Router with Server Components or Pages Router with getServerSideProps/getStaticProps). The diagnostic section is particularly useful for resolving hydration errors, one of the most common SSR issues. The AI identifies frequent causes: accessing window server-side, conditional rendering based on client state, or using SSR-incompatible libraries. It then proposes concrete solutions like dynamic() with ssr: false or useEffect patterns. To get the most from this prompt, precisely describe your problem or goal: is it a hydration bug to fix, a migration to the App Router, or a performance optimization? The richer the context, the more relevant and directly applicable the recommendations will be to your code.

Use Cases

Debug a hydration mismatch error between server and client renderingMigrate a page from Pages Router to App Router with Server ComponentsOptimize initial load time (LCP) of a dynamic page with SSR and streamingChoose between SSR, SSG and ISR for each route of an e-commerce site

Expected Output

A structured analysis with SSR/hydration problem diagnosis, recommended component architecture (Server vs Client), corrected and commented TypeScript code, data fetching strategy, performance recommendations and test examples.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour des erreurs d’hydratation, ajoutez une variable `mounted` dans un `useEffect` et ne rendez le contenu client qu’après montage. Pour isoler un composant non-SSR, privilégiez `next/dynamic` avec `ssr:false` plutôt que de désactiver le SSR globalement. Pensez à tester aussi avec `next build` en production.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Automate Your Git Commits with AI

This prompt analyzes a Git diff and automatically generates structured commit messages following project conventions, with atomic splitting if needed.

717
💻DeveloppementAdvancedAll AIs

Create Async Workers and Jobs with AI

A complete prompt to design and implement async workers and jobs with queuing, retry, monitoring and deployment.

676
💻DeveloppementIntermediateAll AIs

REST API for ML Model

Exposing a model via an API

385
💻DeveloppementAdvancedAll AIs

Progressive Rollout Strategy

Progressive deployment of a new model

526