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.

dangerouslySetInnerHTML not working on <title> tag

See original GitHub issue

I have a page title with coded HTML entities that I would like to render as: “New Post”

It’s delivered to React as: &#8220;New Post&#8221;

For rendering the title on the page I use this code and it works as expected:

<ArticleTitle><span dangerouslySetInnerHTML={{__html: post.title}} /></ArticleTitle>

Returns:

“New Post”


However, when I try to do the same thing for the <title> tag I get an [object Object] returned:

<Helmet>
  <title dangerouslySetInnerHTML={{__html: post.title}} />
</Helmet>

Returns:

<title dangerouslysetinnerhtml="[object Object]" data-react-helmet="dangerouslySetInnerHTML">“New Post” · RAM</title>

There’s an original title that is set per page by the server, however as you browse around I’m using React to update it on the client-side. If I remove the server-side <title> tag, no <title> tag is rendered at all by the front end.

Is this issue related to react-helmet or something else going on?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:10
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
seantjohnson-devcommented, Dec 19, 2017

This is happening for me as well. Is this supported or not? If not, is there a way to get the unescaped text without ‘dangerouslySetInnerHTML’?

0reactions
fredrivettcommented, Oct 1, 2022

he hasn’t been updated in over 4 years (Sept 2018), so I’d be wary of adopting that for security reasons

Read more comments on GitHub >

github_iconTop Results From Across the Web

React dangerouslySetInnerHTML not working when using ...
It seems like this issue only occurs when you give it an escaped html. A solution implemented by @sergiotapia involves creating a helper ......
Read more >
Using dangerouslySetInnerHTML in a React application
dangerouslySetInnerHTML is a property that you can use on HTML elements in a React application to programmatically set their content. Instead of ...
Read more >
DangerouslySetInnerHTML in React JS Explained
dangerouslySetInnerHTML is an attribute under DOM elements in React. According to the official documentation, dangerouslySetInnerHTML is React's replacement ...
Read more >
When to use dangerouslySetInnerHTML in React? - Refine Dev
Because React does not allow direct interaction with the DOM, your content ... React recognizes the HTML tags and correctly renders them.
Read more >
DOM Elements - React
There are a number of attributes that work differently between React and HTML: ... style attribute as the primary means of styling elements...
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