Skip to content
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

NextJs useGSAP Hydration Failed #608

Closed
epenflow opened this issue Dec 25, 2024 · 2 comments
Closed

NextJs useGSAP Hydration Failed #608

epenflow opened this issue Dec 25, 2024 · 2 comments

Comments

@epenflow
Copy link

I'm encountering hydration errors when using useGSAP on my NextJs Pages. Whenever i try to use useGSAP on a page, I get a hydration error

{0CDF9F3C-B020-48EE-87CD-A213F1933E5E}

"use client";
import { useGSAP } from "@/config/gsap";
import React from "react";
import "./base.css";

const Page = () => {
	const containerRef = React.useRef<HTMLElement | null>(null);

	useGSAP(() => {}, { scope: containerRef });

	return (
		<main ref={containerRef}>
			<section className="section h-svh w-full border border-red-500 relative">
				<div className="w-1/2 h-1/2 bg-red-500 right-0 absolute trigger" />
			</section>
			<section className="h-svh w-full border border-red-500 relative">
				<div data-step className="w-1/2 h-1/2 " />
			</section>
			<section className="h-svh w-full border border-red-500 relative">
				<div data-step className="w-40 h-40" />
			</section>
		</main>
	);
};

export default Page;
@jackdoyle
Copy link
Member

I believe this has been answered here:
https://gsap.com/community/forums/topic/43281-hydration-error-in-nextjs-15/

@epenflow
Copy link
Author

epenflow commented Jan 2, 2025

The issue likely doesn't stem from ScrollTrigger itself. Instead, it appears related to typeof window !== "undefined" check. This check is commonly used to differentiate between server side and client side. However, during react hydration process, this conditional check can result in mismatched. To address this, add suppressHydrationWarning to the body tag to suppress hydration warnings.

https://react.dev/reference/react-dom/client/hydrateRoot

@epenflow epenflow closed this as completed Jan 2, 2025
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

No branches or pull requests

2 participants