Skip to content

fix: hydration issue #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Theodore-Kelechukwu-Onyejiaku

What does it do?

There is a hydration error on the Next.js frontend. The <html> and <body> tags are already defined in the root layout at ./next/app/layout.tsx, so they must not be included again in the locale-specific layout at ./next/app/[locale]/layout.tsx.

// Path: ./next/app/layout.tsx

export default function RootLayout({
  children,
  params,
}: {
  children: React.ReactNode;
  params: { lang: Locale };
}) {
  return (
    <html lang={params.lang} suppressHydrationWarning>
      <body suppressHydrationWarning>
        <SlugProvider>
          {children}
        </SlugProvider>
      </body>
    </html>
  );
}

Why is it needed?

After setting up Launchpad, a hydration error is thrown on the frontend:

hydration error
hydration error details

Including multiple or tags in nested layouts will cause errors in Next.js (App Router), as these tags are meant to be defined once globally.

❌ What to Remove
Avoid wrapping the locale layout in another <html> or <body>:

// Path: ./next/app/[locale]/layout.tsx

return (
  <html lang={locale}>
    <ViewTransitions>
      <CartProvider>
        <body className="...">
          <Navbar ... />
          {children}
          <Footer ... />
        </body>
      </CartProvider>
    </ViewTransitions>
  </html>
);

✅ Updated Locale Layout
Instead, use a <div> or <main> container:

// Path: ./next/app/[locale]/layout.tsx

return (
  <ViewTransitions>
    <CartProvider>
      <div
        className={cn(
          inter.className,
          "bg-charcoal antialiased h-full w-full"
        )}
      >
        <Navbar data={pageData.navbar} locale={locale} />
        {children}
        <Footer data={pageData.footer} locale={locale} />
      </div>
    </CartProvider>
  </ViewTransitions>
);

How to test it?

Simply make sure the whole Strapi application doesn't crash and the connected Next.js application is fully working.

Some additional things to check:

  • Strapi project uuid is "LAUNCHPAD". strapi/packages.json.
  • If you updated content, make sure to create a new export in the strapi/data folder and update the strapi/packages.json seed command if necessary.
  • Strapi version is the latest possible.

Related issue(s)/PR(s)

Let us know if this is related to any issue/pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant