question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Helmet behaves strangely when rendering is asynchronous

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
xogenycommented, Nov 13, 2017

Why is it necessary to change renderToHtml to be synchronous? If people want it to be synchronous, just don’t have it return a Promise.

The ability to have it be async is quite important. For example, I’m planning in integration mathjax-node-page so that my equations get converted to <svg> elements during site compilation. The conversion is synchronous, so making renderToHtml will break everything. I can imagine plenty of other scenarios as well.

If getRoutes can be async, why can’t renderToHtml?

1reaction
tannerlinsleycommented, Nov 13, 2017

Yes, we should most definitely change the renderToHtml method to be synchronous. This will be a breaking change mostly because of syntax. So we’ll save it for the next breaking change batch.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found