skip to Main Content

I’ve encountered the hydration error in nextjs and on debugging I found that when I use the div tag instead of the main tag then it causes this issue.

The error that I get

enter image description here
Below is the code that caused the error

import React from "react";
import Image from "next/image";

type Props = {};

const LearnTesting = (props: Props) => {
  return (
    <div>
      <h1>Learn Testing</h1>
    </div>
  );
};

export default LearnTesting;

Below is the code that runs flawlessly

import React from "react";
import Image from "next/image";

type Props = {};

const LearnTesting = (props: Props) => {
  return (
    <main>
      <h1>Learn Testing</h1>
    </main>
  );
};

export default LearnTesting;

You can see the only difference is the usage of the div tag instead of the main tag causing the hydration error.

While going through the documentation I don’t see an explanation related to the usage of semantic tags or anything related. It only mentions incorrect nesting of tags. Maybe I’m missing something?

2

Answers


  1. What css is getting applied, is there anything on the div thats not on the main and vice-versa?

    Login or Signup to reply.
  2. Hey you tried Hard Reload or cleaning Cache

    1. On Chrome, Press right click on reload button → Select Empty Cache and Hard Reload
    2. Just go the browser, Chrome → three bars button on top right corner (hamburger menu) → more tools → Developer tools → Applocation tab → storage → clear site data
    3. There can be a chance your <LearnTesting /> Component is rendering inside h1 Like:
    <h1>
      <LearningTesting />
    </h1>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search