Comments (10)
Yes, makes total sense to have a fallback as part of the template @rdsedmundo 👍
However, I'm not sure react-head
should manage that. Conceptually my mental model is when you import { Title } from 'react-head'
then you're telling react-head to manage that Title tag -- I'm not sure it makes sense for react-head to manage all title tags.
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>
from react-head.
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, react-head
won't override it and it always stays on the top and "won the battle" compared to the tag that react-head
inserts.
I'll change the title and description appropriately.
from react-head.
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 title
to be part of the template vs having react-head completely manage it?
from react-head.
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 <title>
tag on the HTML I can see the title being picked up. Relying only on react-head
Slack won't get anything, as JS won't execute. And by the way, we don't have strong SEO requirements that would justify adding server-side rendering, the use case is really just this quick link sharing on a platform here and there.
from react-head.
Yes, makes total sense to have a fallback as part of the template @rdsedmundo 👍
However, I'm not sure
react-head
should manage that. Conceptually my mental model is when youimport { Title } from 'react-head'
then you're telling react-head to manage that Title tag -- I'm not sure it makes sense for react-head to manage all title tags.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 hope in some future it will be corrected and I can return to this compenente.
- Thank you anyway.
from react-head.
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.
from react-head.
Personally, my mental model says that existing tags should not be modified by react-head. The real solution here is SSR.
Although the title
tag might seem special in this case, how would react-head handle other singleton type tags (i.e. <meta name="viewport" ...>
). Would it clobber those too?
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 title
tag in your template (or interpolated through some other means), then inject another title
tag via react-head. The resulting HTML will have two title tags (bad for a number of reasons). However, inspecting the page after JS has executed and react-head has removed the original title tag will make it appear as though there's no problem.
from react-head.
Personally, my mental model says that existing tags should not be modified by react-head. The real solution here is SSR.
Although the
title
tag might seem special in this case, how would react-head handle other singleton type tags (i.e.<meta name="viewport" ...>
). Would it clobber those too?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
title
tag in your template (or interpolated through some other means), then inject anothertitle
tag via react-head. The resulting HTML will have two title tags (bad for a number of reasons). However, inspecting the page after JS has executed and react-head has removed the original title tag will make it appear as though there's no problem.
It is correct thought in SSR.
My approach is for the CSR.
from react-head.
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.
from react-head.
Wrote up a quick RFC: #97
from react-head.
Related Issues (20)
- Link canonical cascade HOT 1
- Expose HeadTag? HOT 2
- Question: Does it work without ssr for SEO, on fb and twitter ? HOT 1
- Children prop type missing in HeadProvider HOT 7
- Is this library still maintained? HOT 1
- Suggestion: use renderToStaticMarkup instead of renderToString HOT 4
- Some tags not collected HOT 4
- Invariant failed in HeadTags HOT 9
- Development server not working HOT 2
- does not support ie9? HOT 2
- Proposal: headTagsToElement(headTags) HOT 1
- Element.remove() not supported in IE HOT 3
- Document usage with SSR streaming HOT 3
- TypeScript support HOT 3
- react-head supports meta update on lazy load HOT 3
- itemProp support on <Meta /> HOT 1
- canonical link is repeated HOT 1
- Entities in computed attribute values? Suggested approach? HOT 5
- RFC: Managing tags without extra markup HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-head.