hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

React Hydration Error upon loading hello world starter

Open sun33t opened this issue 2 years ago • 12 comments

What is the location of your example repository?

No location - just spun up the hello world template and ran the dev script

What version of Hydrogen are you using?

v2023.1.2

What version of Remix are you using?

v1.12.0

Steps to Reproduce

  1. npm create @shopify/hydrogen@latest
  2. choose hello world
  3. choose typescript
  4. choose install dir
  5. install with npm - yes
  6. cd into install dir and execute npm run dev

Expected Behavior

Following the execution of npm run dev, its expected to view the site at localhost:3000 and to not see any react errors within the browser console.

Actual Behavior

Following the execution of npm run dev, when I expect the index page at localhost:3000 within chrome (with react-dev-tools installed) A number of console errors are present related to react hydration errors.

Screenshot 2023-02-14 at 06 19 06

Not sure if this is an obvious fix, but I figured it's worth raising as I've not modified any of the code within the hello world started other than to run npm update @shopify/hydrogen - I thought I'd try updating first in case there was a fix included but the error is present in the current version as well as the previous version.

sun33t avatar Feb 14 '23 06:02 sun33t

Could this issue be linked to https://github.com/remix-run/remix/issues/5416 and as such not a @shopify/hydrogen framework issue but linked to my browser extension configuration or remix? Apologies if so.

sun33t avatar Feb 14 '23 06:02 sun33t

@sun33t You can try loading your app within a private browsing window, or a different browser that doesn't have any extensions installed, in order to test whether that's the problem :)

davidhousedev avatar Feb 14 '23 10:02 davidhousedev

Thanks @davidhousedev, I did exactly that and experienced the following:

Normal Chrome window with apollo client dev tools - hydration errors Incognito Chrome (no extensions) - no errors Normal Chrome window without apollo client dev tools - no hydration errors

I repeated the same steps above for Firefox and received the same results so I think it's definitely happening because of Apollo Client devtools.

sun33t avatar Feb 15 '23 05:02 sun33t

This related to Remix and React. More info: https://github.com/remix-run/remix/discussions/4902

lordofthecactus avatar Feb 16 '23 14:02 lordofthecactus

Since the @shopify packages seem to be having issues from recent commits I went back to just npm create @shopify/hydrogen npm install npm run dev leaving off the @latest I also had a hydrogen 2 project from the first day of release I had work in that I had did a pull and npm install and hit all the package vulnerabilities and errors after npm run dev. So I deleted my node_modules and replaced the package.json and package.lock with the code from repo where I did npm create @shopify/hydrogen and then re-ran npm install and npm dev on it and it was back up and working.

karlhass15 avatar Feb 17 '23 18:02 karlhass15

Here is a temporary fix that is getting us past this problem on our Hydrogen 2 builds that use Styled Components (applied here to the H2 hello-world template.

Based on @kiliman's initial fix, wrapped into remix-island by @Xiphe and https://github.com/remix-run/remix/discussions/5244#discussioncomment-4890083 by @clgeoio

More information:

  • https://github.com/remix-run/remix/issues/5569
  • https://github.com/remix-run/remix/discussions/5244
  • Remix Roadmap Discussion
  • https://github.com/facebook/react/issues/24430

duncan-fairley avatar Feb 25 '23 20:02 duncan-fairley

@duncan-fairley is this really solving the issue for you? I am still experiencing it, but with your solution the error becomes:

Warning: Expected server HTML to contain a matching <body> in <div>.
    at body

Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.

 Warning: validateDOMNesting(...): <body> cannot appear as a child of <div>.
    at body

tomh4 avatar Oct 26 '23 14:10 tomh4

Is there anything I can do about this?

tomh4 avatar Nov 19 '23 19:11 tomh4

As this is really a fundamental React problem, there isn't that much to do at the moment. Though you can try if the React 1.8.3-canary release helps.

blittle avatar Nov 21 '23 16:11 blittle

@blittle I tried 18.3 but it did not help, with the hydration error, but updating the react dom as well to canary at least got the flashing away. the hydration errors still exist in the logs

tomh4 avatar Dec 02 '23 08:12 tomh4

I am experiencing this issue, it prevents my modals and drawers from rendering with issues "only in production". I am using chakra UI for the drawers and modals. are there any fixes for this? @sun33t

image

eldevflo avatar Mar 26 '24 12:03 eldevflo

I havent found any...

tomh4 avatar Mar 26 '24 12:03 tomh4

This is not an issue we can solve. It is something we need from React. Please test hydration issues an an incognito window to make sure extensions are no the culprit.

blittle avatar Jul 18 '24 20:07 blittle