Next.js Discord

Discord Forum

Generic Hydration Error: No Specific Message

Answered
Glitch guy posted this in #help-forum
Open in Discord
Avatar
i have used all techniques mentioned from gpt and all still getting hydration error on text build bunx next dev --turbo, don't know what exactly the problem is

"use client";

import axios from "axios";
import { useEffect, useState } from "react";

export default function MagicLogin() {
  const [error, setError] = useState(false);
  const [userId, setUserId] = useState<string | null>(null);
  const [secret, setSecret] = useState<string | null>(null);

  useEffect(() => {
    if(typeof window !== "undefined") {
      const searchParams = new URLSearchParams(window.location.search);
      setUserId(searchParams.get("userId") as string);
      setSecret(searchParams.get("secret") as string);
      try {
        if(userId && secret){
          axios.post("/api/session", { userId, secret });
        }
      } catch (err) {
        setError(true);
      }
    }
  });

  if (error) {
    return (
      <div className="h-svh w-full flex justify-center items-center flex-col">
        <p className="text-center text-red-500">
          Something went wrong, try again later
        </p>
      </div>
    );
  } else {
    return (
      <div className="h-svh w-full flex justify-center items-center flex-col">
        <div className="m-auto my-2 rounded-full h-10 w-10 border-t-4 border-white/50 animate-spin"></div>
        <p className="text-xl text-center">Redirecting ...</p>
      </div>
    );
  }
}


also tried dynamic component

"use client";

import dynamic from "next/dynamic";

export default function MagicLogin() {
  const MagicComponent = dynamic(() => import("./MagicLogin"), {
    ssr: false,
  })

  return(
    <>
      <MagicComponent />
    </>
  )
}
Answered by Asian black bear
Then it is that cz-shortcut-listen prop causing the error. Disable Colorzilla or open the page in incognito mode.
View full answer

16 Replies

Avatar
Asian black bear
You need to share the error message and its diff which typically shows what has caused the hydration error.
And btw, your effect has no dependency array which is a huge bug.
Avatar
the error has nothing specific just a generic message
A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:

- A server/client branch `if (typeof window !== 'undefined')`.
- Variable input such as `Date.now()` or `Math.random()` which changes each time it's called.
- Date formatting in a user's locale which doesn't match the server.
- External changing data without sending a snapshot of it along with the HTML.
- Invalid HTML tag nesting.
Avatar
@Asian black bear And btw, your effect has no dependency array which is a huge bug.
Avatar
when i add brackets (to run only once) it doesn't make a api call
Avatar
@Glitch guy the error has nothing specific just a generic message
Avatar
Asian black bear
Is there no diff like in this example?
Image
Avatar
@Asian black bear Is there no diff like in this example?
Avatar
this is exactly how it shows
Avatar
Asian black bear
You are contradicting yourself now. I am asking about the thing at the bottom.
You first said there is nothing specific and now you say there is something.
That diff at the bottom, if it's displayed, helps you pinpoint the issue.
Avatar
Image
Avatar
Asian black bear
Then it is that cz-shortcut-listen prop causing the error. Disable Colorzilla or open the page in incognito mode.
Answer
Avatar
that solved it
thankyou!!
@Asian black bear how did you know that was the error? (colorzilla)??
Avatar
Asian black bear
You can see from my screenshot as well from your console output that the diff points out that attribute wasn't SSR-ed while it is there on the client. Googling that will reveal it's Colorzilla's attribute that gets injected and messes up React. Also dozens of other people in here have asked about the exact same issue. There is pretty much a post every day or two about that plugin in particular.