nfl / react-helmet

A document head manager for React
MIT License
17.37k stars 661 forks source link

Is it possible to specify that some tags ONLY render with SSR #337

Open rohan-buechner opened 6 years ago

rohan-buechner commented 6 years ago

I have an isomorphic application that makes use of GTM + Helmet for my analytics needs. I've been though the other issues logged on here, and found one other that is somewhat similar, but not exactly the same.

The issue is regarding that if I move the server renderer hooks to, say, from the head to the body. EG, let's look at no-script:

<head>
</head>
<body>
      ${helmet.noscript.toString()}
</body>

ultimately once the react server-side code has loaded, the no-script tag is duplicated:

<head>
     <noscript>Clientside</noscript>
</head>
<body>
     <noscript>Serverside</noscript>
</body>

My question is thus: For things like GTM, I think this could be super useful, is there any way in the API that someone can specify that an element within helmet ONLY renders using the SSR/Client renderer?

tb commented 6 years ago

How about something like:

      <Head>
        {typeof window === 'undefined' && helmet.noscript.toString()}
      </Head>