Helmet behaves strangely when rendering is asynchronous
See original GitHub issueI was seeing some odd behavior with meta tags in the head of the static pages in my project. I created a new basic template, added a <Head><title> This is About </title></Head> to the About container, and <Head><title> This is Home </title></Head> to the Home container, and ran yarn build.
The About-title ended up in the index.html file and the Home-title was nowhere to be seen.
I looked into it a bit, and I think the async renderToString is the culprit. It works as intended if I just remove the await keyword.
It looks like Helmet doesn’t work all that well if the rendering is asynchronous. I dare not create a PR making it synchronous, because I’m sure it has some other use case I’m not aware of.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Is the rewind approach safe? #216 - nfl/react-helmet - GitHub
EmilTholin mentioned this issue on Nov 3, 2017. Helmet behaves strangely when rendering is asynchronous react-static/react-static#117.
Read more >In ReactJS, why does `setState` behave differently when ...
Yes, there's a bit of magic here. React calls render synchronously after your event handler. This is necessary to avoid flickers. Share.
Read more >Server-render renderToNodeStream with react-helmet-async
The problem with helmet and renderToNodeStream is that even with helmet-async, you still need to render the complete React tree first, to get ......
Read more >What is the purpose of useEffect without a dependency array?
Code in useEffect runs asynchronously AFTER the render is already committed to the DOM. In practice, I suppose in most circumstances there's ...
Read more >How to use the react-helmet.Helmet.canUseDOM function in ...
To help you get started, we've selected a few react-helmet.Helmet.canUseDOM examples ... before(() => { // Tell helmet to run as if it's...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Why is it necessary to change
renderToHtmlto be synchronous? If people want it to be synchronous, just don’t have it return aPromise.The ability to have it be
asyncis quite important. For example, I’m planning in integrationmathjax-node-pageso that my equations get converted to<svg>elements during site compilation. The conversion is synchronous, so makingrenderToHtmlwill break everything. I can imagine plenty of other scenarios as well.If
getRoutescan beasync, why can’trenderToHtml?Yes, we should most definitely change the
renderToHtmlmethod to be synchronous. This will be a breaking change mostly because of syntax. So we’ll save it for the next breaking change batch.