-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Title component doesn't override default <title> tag provided via HTML template #83
Comments
Nevermind, I realized what is going on in fact. The nesting is working. The problem is that, if I provide a default tag on my HTML template, I'll change the title and description appropriately. |
I guess what is the desired behavior here? I'm not sure react-head should mess with existing markup on the page. Curious what your use case is for the |
It's simply because this one can act as a default one and if I share the webpage on Slack, for example. If I do that and have the |
Yes, makes total sense to have a fallback as part of the template @rdsedmundo 👍 However, I'm not sure To solve your use case though I guess it would be relatively easy to add a small snippet to remove the title tag that the template adds and then the rest would be left up to react-head: <head>
<title id="template-title">Template Title</title>
</head>
<script>
const templateTitle = document.getElementById("template-title");
if (templateTitle) templateTitle.parentNode.removeChild(templateTitle);
</script> |
Thank you, I stopped using react-head precisely for not having this feature, it is very, the proposed solution is simply horrible, nothing clean.
|
I’m curious how others feel about this. If there’s enough interest in having react-head clobber existing tags on the page that it otherwise does not manage, we can look into adding support. |
Personally, my mental model says that existing tags should not be modified by react-head. The real solution here is SSR. Although the I image troubleshooting unexpectedly changing tag values to be more difficult than seeing duplicate tags and realizing one is being injected by react-head, and the other hardcoded in the template. Also, expecting react-head to clobber the other title tags could lead to problems if you are using SSR. Suppose you had a hard-coded |
It is correct thought in SSR. |
If anyone's interested in working on this, I think a PR to show how this might work would be helpful. Ideally there should be a way to opt-in (or opt-out) of clobbering. |
Wrote up a quick RFC: #97 |
I'm using client-side rendering and
react-head
is not able to replace a default tag that I provided on my HTML template. It only adds a new<title>
tag at the end of the head, and due to the browser behavior, only the first one is actually used.react-helmet
as a reference supported this fine.template.html
index.js
The expected behavior for me is that
Test2
is going to replace and be the title of the page, but what happens is thatTest
remains as the title, as its tag is positioned first.The text was updated successfully, but these errors were encountered: