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

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

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

<p>This prompt is designed to get a comprehensive analysis of your Next.js rendering architecture. By specifying your <strong>Next.js version</strong> and <strong>router type</strong>, the AI adapts its recommendations to available APIs (App Router with Server Components or Pages Router with getServerSideProps/getStaticProps).</p><p>The diagnostic section is particularly useful for resolving <strong>hydration errors</strong>, one of the most common SSR issues. The AI identifies frequent causes: accessing <code>window</code> server-side, conditional rendering based on client state, or using SSR-incompatible libraries. It then proposes concrete solutions like <code>dynamic()</code> with <code>ssr: false</code> or <code>useEffect</code> patterns.</p><p>To get the most from this prompt, precisely describe your <strong>problem or goal</strong>: 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.</p>

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

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Stable Diffusion Prompt for Generating Python Code

Stable Diffusion, known for its powerful image generation, can also be used to create realistic visuals of Python code. Whether you need illustrations of code snippets for your presentations, blog posts, or educational materials, Stable Diffusion lets you generate stylized screenshots of code editors displaying Python. Unlike language models like ChatGPT or Claude that produce executable code, Stable Diffusion excels at creating photorealistic images depicting code on a screen, in an IDE, or in a terminal. This approach is especially useful for content creators, UX designers building development interface mockups, or trainers looking for impactful visuals without revealing their actual source code. By mastering the right prompts, you'll achieve convincing renderings of Python development screens with a professional aesthetic, consistent syntax colors, and careful framing. Here are the most effective prompts to make that happen.

0137
💻DeveloppementAdvancedAll AIs

Terraform Multi-Environment Architecture

Managing multiple environments with Terraform

0144
💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

0155
💻DeveloppementIntermediateAll AIs

Multi-Level Testing Pipeline

Structuring tests in the pipeline

0156