-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
hydration error when there is a chrome extension that modifies DOM #4822
Comments
This is a known gotcha, however, I agree it would be helpful if Remix could do something to prevent this from happening. For me the error only occurs in development. Has anyone found a workaround other than incognito or uninstalling the extensions? |
We talked about this with @mjackson The root of the problem is that remix hydrates the whole document, instead of a div on the body. Not sure if the team is willing to reconsider this choice, and the consequences it would have on handling things like meta & so on. Maybe a good topic for today's live roadmap stream. |
Thank you all for the answers. |
@jin2255 Are you experiencing this error when running in production? I only experience it in development. |
This happens in both production and development. |
thank you, @machour |
@jin2255 someone needs to post a proposal for change and a discussion needs to happen, in order to get this on the team radar: |
for me its only happening in production :'( |
I am not getting any error in Firefox and incognito of chrome. Do anyone getting any error in production??? |
I face the same issue with https://chrome.google.com/webstore/detail/autoscroll/occjjkgifpmdgodlplnacmkejpdionan/related extension on development and production. |
I was able to resolve my issue by invoking |
mhmm, so it seems there is not exact solution yet Really I loved remix |
Well @jin2255 I just needed to downgrade react version ( from 18.x.x to 17.x.x ) and every it is fine by now in our production environment. |
@jin2255 Ryan and Michael discussed this in the Roadmap live stream last week. So basically my understanding is:
|
|
When using CSS-in-JS, the styles fail to render, so as you can imagine it feels like the entire site breaks. In summary, it's a React 18 problem and it can be seen at FAILShydrateRoot(document, <RemixBrowser />) WORKShydrate(<RemixBrowser />, document)
// Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead.
// Until you switch to the new API, your app will behave as if it's running React 17 Reproductionhttps://stackblitz.com/edit/node-czrvzk?file=app/entry.client.tsx I used styled-components and I have a large project using styletron that also has this same issue and workaround. |
This is not just a Chrome Extension problem. If you share your website on social media, it opens in an in-app browser. Meta, at least, injects fancy stuff in the DOM (weird, right?), which leads to the same issue. This one is more concerning to me, as the brand's reputation is at stake (they are linking the customers to an apparently broken site), and affects 100% of the users. |
For the time being, I think it's better to avoid R18. |
Still with react@17 additional injected elements (such as the ...unless they're placed as the last child of an element, which is not controllable in every case... |
|
thank you, all |
Not sure we can do this in the guise of |
Is it safe to do this for a Remix project on PROD? 🤔 |
Per the React team, yes. Next.js (at least the app router) only uses canaries so any production Next.js app using the App Router is using a canary. It's really up to you and your team though if you feel comfortable shipping a canary release to production. |
I'm facing the same problem as described. When having Grammarly on, the favicon jumps in production and development, and a bunch of hydration errors appear in the console. It's been over a year and is quite critical. We are talking about people developing entire websites and then seeing it all broken because HTML is injected dynamically, which is a common occurrence. Is there a hack other than using the React canary version? |
Nah I don't think so ... https://twitter.com/BrooksLybrand/status/1763678388806394127?t=pxowwBKSwYI-VP4yADlDvw&s=19 |
my workaround to prevent any DOM modifications until after hydration happens
client entry
|
I just wanted to smoothly deploy to the production environment, I didn't expect so many pitfalls. If I had known it would be like this, I wouldn't have used this tool. This is my temporary solution, I just comment out this line, and the world becomes quiet.
|
@MaeThird, update to the React canary version to resolve the hydration issues. This is a React issue because Remix hydrates the entire document instead of a single div. Also make sure you pin the version and add to |
@kiliman works now! Thank you. |
I'm facing this issue with react 18.3.1 |
v18.3 used to be the canary version that fixed this. It's now React 19. So install the latest RC |
This definitely helped, but Grammarly was still acting up and messing up the entire page. Until a stable version of React 19 is out, I found this workaround.
Thanks @OnurGvnc for |
For anyone else still struggling with this, the only thing that worked for me with both browser extensions and browsers that inject into the DOM
Is using the canary version mentioned here:
Just set the React version in "dependencies": {
"react": "18.3.0-canary-a870b2d54-20240314",
"react-dom": "18.3.0-canary-a870b2d54-20240314",
} and add this to avoid issues with dependencies: "dependencies": {
"react": "18.3.0-canary-a870b2d54-20240314",
"react-dom": "18.3.0-canary-a870b2d54-20240314",
},
"overrides": {
"react": "18.3.0-canary-a870b2d54-20240314",
"react-dom": "18.3.0-canary-a870b2d54-20240314"
}, The permanent solution to this is to upgrade to React 19 once it becomes stable. You can keep this canary version until your dependencies start supporting React 19. |
…ation (#32637) Closes #32632. A side effect of Remix's hydration implementation is that it throws away the entire DOM. This is broadly discussed in remix-run/remix#4822 - there might be a fix in coming React versions, but who knows. Besides breaking browser extensions, this also deletes our toolbar! This PR fixes it by periodically checking in on `x-pw-glass`, and remounting it if it was unmounted. Hacky but effective!
…ix-ui/react-slot to align with https://react.dev/blog/2024/04/25/react-19-upgrade-guide#deprecated-element-ref Script injections (by browser extensions or test runners like Cypress or TestCafe) cause hydration errors. React19 improves that situation (remix-run/remix#4822).
What version of Remix are you using?
latest
Steps to Reproduce
I installed an extension that modifies DOM such as Grammar Checker into my browser and tried to develop a web app with Remix.
I get the following errors and the styles of the app were messed up.
Hydration failed because the initial UI does not match what was rendered on the server.
There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
Expected Behavior
I have errors when I install any extension that modifies DOM into my browser
Actual Behavior
The favicon and styles are messed up
The important thing is that this error has already been mentioned many times and there is no exact solution
What's even more interesting is that the https://remix.run site doesn't have this error occur even if it was developed with Remix
The text was updated successfully, but these errors were encountered: