nfl / react-helmet

A document head manager for React
MIT License
17.34k stars 660 forks source link

Server Side Rendering #379

Open m-a-r-c-e-l-i-n-o opened 6 years ago

m-a-r-c-e-l-i-n-o commented 6 years ago

Maybe I've been doing server side rendering with Helmet the wrong way and if that is the case, please correct me. It's my understanding that the only way to get the values from Helmet during server side rendering is to call the "Helmet.renderStatic()" method from the "Helmet" global after the components are rendered.

There are two major issues with this approach:

  1. It will not work if the app is using two different versions of Helmet, since it relies on the same global instance being used everywhere.
  2. The data of one request could bleed into other requests if the server setup involves multiple renders with an asynchronous step in between (which is my case).

Is there any reason we can't use the "provider" approach for server side rendering? I can probably submit a PR if you guys are okay with the approach. Here's an example of how that looks: (https://material-ui.com/guides/server-rendering/#server-rendering). This approach is also seen in other libraries that have a server side rendering component (e.g. Redux).

kylepotts commented 6 years ago

Not sure if you are aware but https://github.com/staylor/react-helmet-async exists which I think addresses some of your issues.

tmbtech commented 5 years ago

Seems like this is an ongoing theme. I might have missed it but is there a public repo I can fork?

I would like to investigate further and it would same me some time if it was easily repo'd.

I'm also open to a PR. Let's talk about the implementation details first? Maybe I can open a public slack or gitter.

kylepotts commented 5 years ago

@tmbtech FWIW We've moved over to using react-helmet-async. Maybe reach out to them and talk about moving the changes from the fork over here.

egemon commented 5 years ago

https://github.com/nfl/react-helmet#server-usage