react icon indicating copy to clipboard operation
react copied to clipboard

Bug: Hydration error due to <button>

Open JAGADEESHWARAN20 opened this issue 2 years ago • 5 comments

React version:

is there any way to fix this issue

Unhandled Runtime Error Error: Hydration failed because the initial UI does not match what was rendered on the server. See more info here: https://nextjs.org/docs/messages/react-hydration-error

In HTML,

                          <button>
                          ^^^^^^^^
                            <_c>
                              <button>
                              ^^^^^^^^

Link to code example:

https://github.com/JAGADEESHWARAN20/Shopwithdashboard/blob/main/app/(dashboard)/%5BstoreId%5D/(routes)/settings/components/SettingsForm.tsx

JAGADEESHWARAN20 avatar Mar 12 '24 12:03 JAGADEESHWARAN20

i tried So many time to find this issue , but I don't get it ....

screenshot:

image

how to remove this also

image

JAGADEESHWARAN20 avatar Mar 12 '24 12:03 JAGADEESHWARAN20

Hey @JAGADEESHWARAN20 👋

I'm not an expert on Next.js, but it looks like this error is caused by nesting two interactive <button>s. That is, you have a button within another button.

Hope this helps!

pwbriggs avatar Mar 13 '24 00:03 pwbriggs

@JAGADEESHWARAN20 How did you run this project? using yarn test?

muskan2622 avatar Mar 13 '24 11:03 muskan2622

Using npm run dev

JAGADEESHWARAN20 avatar Mar 14 '24 01:03 JAGADEESHWARAN20

The error is present because you have nested two buttons because the generated html code will render two buttons side by side whereas during hydration the buttons are nested.

dmx1254 avatar Mar 15 '24 14:03 dmx1254

Yeah nesting buttons is invalid HTML.

rickhanlonii avatar Mar 24 '24 01:03 rickhanlonii