feat: implement DynamicProviders to disable SSR for global context providers in root layout
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import nextDynamic from 'next/dynamic'; // <-- 1. On importe l'outil dynamique
|
||||
import { DynamicProviders } from '../components/DynamicProviders';
|
||||
import Navbar from '../components/Navbar';
|
||||
import Footer from '../components/Footer';
|
||||
import { getSiteSettings } from '../lib/settings';
|
||||
@@ -7,8 +7,7 @@ import { Metadata } from 'next';
|
||||
import { Inter, Playfair_Display } from 'next/font/google';
|
||||
import './globals.css';
|
||||
|
||||
// 2. LA MAGIE EST ICI : On force Next.js a ignorer les Providers pendant le build serveur
|
||||
const Providers = nextDynamic(() => import('../components/Providers').then((mod) => mod.Providers), { ssr: false });
|
||||
// 2. LA MAGIE EST ICI : On utilise un wrapper Client pour le no-SSR
|
||||
|
||||
|
||||
const inter = Inter({
|
||||
@@ -57,13 +56,13 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
||||
return (
|
||||
<html lang="fr" className={`${inter.variable} ${playfair.variable}`} style={devBrandOverride} suppressHydrationWarning>
|
||||
<body className="bg-gray-50 text-gray-900 antialiased min-h-screen flex flex-col font-sans" suppressHydrationWarning>
|
||||
<Providers>
|
||||
<DynamicProviders>
|
||||
<Navbar settings={settings} />
|
||||
<main className="flex-grow">
|
||||
{children}
|
||||
</main>
|
||||
<Footer settings={settings} />
|
||||
</Providers>
|
||||
</DynamicProviders>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
14
components/DynamicProviders.tsx
Normal file
14
components/DynamicProviders.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import dynamic from 'next/dynamic';
|
||||
|
||||
// On importe les Providers reellement en mode Client-Only (pas de SSR)
|
||||
const Providers = dynamic(
|
||||
() => import('./Providers').then((mod) => mod.Providers),
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
export function DynamicProviders({ children }: { children: React.ReactNode }) {
|
||||
return <Providers>{children}</Providers>;
|
||||
}
|
||||
Reference in New Issue
Block a user