Skip to content
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

[Docs]: Did not expect server HTML to contain a <script> in <html> #1077

Closed
chanan opened this issue Dec 16, 2021 · 32 comments · Fixed by #2682
Closed

[Docs]: Did not expect server HTML to contain a <script> in <html> #1077

chanan opened this issue Dec 16, 2021 · 32 comments · Fixed by #2682
Labels

Comments

@chanan
Copy link

chanan commented Dec 16, 2021

What version of Remix are you using?

1.0.6

What version of Node are you using? Minimum supported version is 14.

16

Steps to Reproduce

  1. Run npx create-remix@latest
  2. Run yarn to install packages
  3. run yarn dev to start the server
  4. Observe the browser dev tools console

Expected Behavior

No errors should be shown in the console

Actual Behavior

The following error is shown in the browser dev console:

react-dom.development.js:67 
        
       Warning: Did not expect server HTML to contain a <script> in <html>.
    at head
    at html
    at Document (http://localhost:3000/build/root-KCVDQOQR.js:65:21)
    at App
    at RemixCatchBoundary (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:1518:10)
    at RemixErrorBoundary (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:1457:5)
    at RemixRoute (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:2947:3)
    at Routes (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:2930:7)
    at Router2 (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:457:21)
    at RemixCatchBoundary (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:1518:10)
    at RemixErrorBoundary (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:1457:5)
    at RemixEntry (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:2827:12)
    at RemixBrowser (http://localhost:3000/build/_shared/chunk-RDYF4RHT.js:3509:42)
@chanan chanan added the bug Something isn't working label Dec 16, 2021
@girishk21
Copy link

girishk21 commented Dec 16, 2021

hey @chanan, this is a hydration warning from React. This is most probably because of your browser extensions injecting scripts into the HTML Document before React could hydrate the server rendered document. Check out in incognito, the warning should disappear

@iwfan
Copy link

iwfan commented Jan 7, 2022

Hi @chanan, You can also add suppressHydrationWarning in the root.tsx to suppress this warning.

export default function App() {
  return (
-    <html lang='en'>
+    <html lang='en' suppressHydrationWarning={true}>
      <head>
  ...

@kentcdodds
Copy link
Member

I'd strongly recommend against suppressing all warnings like this. It could silence actual problems. If it were me, I would disable this extension until this issue has been resolved on the extension author's side.

@joanofdart
Copy link

Hey all, removed react-dev-tools but I still get the warning 😢 and I don't want to supress them all as suggested by @kentcdodds

@kentcdodds
Copy link
Member

@joanofdart, I don't think react devtools causes this warning. Are you sure it's not another extension that's causing it? It could also be a third party library that's modifying the DOM before React hydrates the app.

@joanofdart
Copy link

@kentcdodds ill disable them all and check which one is causing this 😄 thanks for the quick response tho!

@slowselfip
Copy link

In my case it was Apollo Client Devtools v4.0.0. Disabling it made the error message disappear, enabling it made it re-appear.

@edzis
Copy link
Contributor

edzis commented Jan 26, 2022

For me it was "Google Analytics Opt-out Add-on (by Google)" - https://chrome.google.com/webstore/detail/google-analytics-opt-out/fllaojicojecljbmefodhfapmkghcbnh?hl=en

@vojty
Copy link

vojty commented Feb 2, 2022

For me, it's ThreeJS Developer Tools extension for Chrome https://chrome.google.com/webstore/detail/threejs-developer-tools/ebpnegggocnnhleeicgljbedjkganaek

@Elijah-trillionz
Copy link

In my case, it's the video.js library and I need it

@machour machour added docs and removed bug Something isn't working labels Mar 17, 2022
@machour machour changed the title [Bug]: Did not expect server HTML to contain a <script> in <html> [Docs]: Did not expect server HTML to contain a <script> in <html> Mar 17, 2022
@kush-daga
Copy link

I also receive this warning if I try to add a third-party script in the Remix app using <script> tag in the body. Is there a better way to go about this, loading third-party scripts? Maybe I missed it in the docs.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2022

🤖 Hello there,

We just published version v1.3.5 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@corgipower
Copy link

I'm getting this as well, on remix 1.4.1.
For me, it's coming from a disable autoplay extension, but I don't get this warning in apps built with other frameworks.

@eric-burel
Copy link
Contributor

Hi, why is this issue closed? I understand that the issue is probably not on Remix yet it's expected to have extensions injecting scripts in apps, I am not sure why we get this warning. Could it be at least more explicit (for instance having a bit more info about the script to quickly tell which one is responsibile)?

@kentcdodds
Copy link
Member

The warning you see is coming from React, not Remix. So there's literally nothing Remix can do for you here. You'll want to open an issue on React if you want to improve the error message.

@arnaudambro
Copy link
Contributor

Hello !
In my case, I'm not seeing it with Chrome and Firefox, but with Safari I do, where I installed the extension Google Analytics Opt-out Browser add-on. If I disable that extension, no more warning.

guidefari added a commit to guidefari/remixgoose that referenced this issue Jul 17, 2022
@alexmacarthur
Copy link

Disabling the Apollo Client Devtools extension fixed the issue for me. 👍

@jjhiggz
Copy link

jjhiggz commented Sep 4, 2022

Disabling the Apollo Client Devtools extension fixed the issue for me. 👍

SAME

@MrSiby
Copy link

MrSiby commented Sep 30, 2022

Hello ! In my case, I'm not seeing it with Chrome and Firefox, but with Safari I do, where I installed the extension Google Analytics Opt-out Browser add-on. If I disable that extension, no more warning.

This plugin was also the cause of the issue for me.

@VeelongGit
Copy link

Just reporting seeing this issue with Adobe Acrobat: PDF edit, convert, sign tools Chrome extension

@heydavee
Copy link

For me it was a coupon extension. Never would have thought about it.
To my german friends: Try to disable the Shoop extension.

@m-alva
Copy link

m-alva commented Apr 26, 2023

I have the same problem with newrelic.getBrowserTimingHeader, Newrelic browser agent

@amodanov
Copy link

I am experiencing an issue where the __staticRouterHydrationData is not present in the final server-rendered version of my application, despite being generated during the server-side rendering process.

<div id="react-app">
    <div class="page">.......</div>
    <script nonce="........">
        window.__staticRouterHydrationData = JSON.parse("{\"loaderData\":{\"0\":null,\"0-0\":null},\"actionData\":null,\"errors\":null}");
    </script>
</div>

This script tag, specifically for __staticRouterHydrationData, is available when generated on the server. However, it mysteriously disappears in the final version.

Has anyone else encountered a similar problem, or perhaps could provide insight on why this might be happening?

@gavriguy
Copy link
Contributor

In my case, it's the video.js library and I need it

Hi @Elijah-trillionz did you manage to run videojs on remix without getting those errors?

@kiliman
Copy link
Collaborator

kiliman commented Jun 19, 2023

@gavriguy when trying to import a package that doesn't support SSR, the typical solution is to re-export the component from a *.client.tsx file. Then wrap in <ClientOnly> from remix-utils.

// components/video.js.client.tsx
import videojs 'video.js'

export const VideoJS = (props) => {
  // from https://videojs.com/guides/react/
  // ...
}
export default VideoJS
// routes/video.tsx
import VideoJS from '~/components/video.js.client'
import { ClientOnly } from 'remix-utils'

export default Component() {
  return (
    <ClientOnly>
      {() => <VideoJS />
    </ClientOnly>
  )
}

@gavriguy
Copy link
Contributor

Hi @kiliman thanks for your answer. That's exactly what I did but I still get errors:

image

@kiliman
Copy link
Collaborator

kiliman commented Jun 19, 2023

@gavriguy
Copy link
Contributor

Thanks it is working :) but there are still errors in the console log:

image

@kiliman
Copy link
Collaborator

kiliman commented Jun 19, 2023

Hydration issues occur when code outside of your app modifies the DOM. This is typically caused by browser extensions. There are workarounds like https://github.com/kiliman/remix-hydration-fix. The next version of React will minimize these hydration errors. You can verify by installing react@canary.

@gavriguy
Copy link
Contributor

Thanks for you help much appreciated.

I gave your solution a try and it works without any errors. Cheers :)

@amodanov
Copy link

amodanov commented Jun 19, 2023

I am experiencing an issue where the __staticRouterHydrationData is not present in the final server-rendered version of my application, despite being generated during the server-side rendering process.

<div id="react-app">
    <div class="page">.......</div>
    <script nonce="........">
        window.__staticRouterHydrationData = JSON.parse("{\"loaderData\":{\"0\":null,\"0-0\":null},\"actionData\":null,\"errors\":null}");
    </script>
</div>

This script tag, specifically for __staticRouterHydrationData, is available when generated on the server. However, it mysteriously disappears in the final version.

Has anyone else encountered a similar problem, or perhaps could provide insight on why this might be happening?

It seems that I have resolved my issue by using suppressHydrationWarning, but I'm unsure whether this is a good solution or simply a workaround.

Is this behavior expected and should it work correctly in React version 17?

<React.Fragment>
    <Provider store={store}>
        <RouterProvider router={router} fallbackElement={null} />
    </Provider>

    <SuppressScriptHydrationWarning />
</React.Fragment>
export const SuppressScriptHydrationWarning = () => {
    const [isClient, setIsClient] = useState(false);

    useEffect(() => {
        setIsClient(true);
    }, []);

    return isClient ? null : <script suppressHydrationWarning={ true } />;
};

@Mihai-github
Copy link

Hey, I have a html template that I have to move to Remix.js witch includes many js files, from libraries like bootstrap to custom js, but when I put them into the public folder and try to include them into the root.tsx file I see in the server console errors regarding route not found plus on the client hydration issues and also the ui for a second has a flicker but the js is not working...

Is this something that is not supported or I don't know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.