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

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

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

  • 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

Kubernetes Cloud Cost Optimization

Reduce Kubernetes costs

0289
💻DeveloppementBeginnerAll AIs

Post-Deployment Smoke Tests

Automatically validate a deployment

0372
💻DeveloppementIntermediateChatGPT

Prompt ChatGPT to Create E2E Tests

End-to-end (E2E) tests are essential to ensure an application works as a whole, but writing them is often time-consuming and repetitive. ChatGPT can significantly speed up this process by generating complete test scenarios covering critical user paths, edge cases, and necessary assertions. Whether you use Cypress, Playwright, Selenium, or any other framework, AI can produce structured and maintainable tests from a simple functional description. The challenge is to provide a sufficiently precise prompt to obtain realistic tests that follow best practices (stable selectors, async handling, test isolation) and integrate directly into your CI/CD pipeline. In this guide, you'll find an optimized main prompt along with variants adapted to your expertise level, to turn your functional specifications into robust E2E test suites in seconds.

0304
💻DeveloppementIntermediateAll AIs

Transform JSON data with business logic

Transform data between different API formats

0298