gatsby-plugin-react-helmet orders the components too late in <head>
See original GitHub issueDescription
When I use gatsby-plugin-react-helmet
I notice that the <Helmet />
components come way too late in the head tag. I have noticed that on occasion for instance Facebook does not always parse the og
tags if they come too late in the head.
Steps to reproduce
Just use <Helmet />
, and notice in the static output files there is a lot of CSS related stuff etc. above the helmet tag in the <head>
.
Expected result
Helmet tags should be prioritised when doing the <head />
tag.
Workaround
Currently there is easy workaround, but I consider that gatsby’s default is broken. We should not need workaround for this.
gatsby-ssr.js
var React = require("react");
// Hack, to reorder the helmet components as first in <head> tag
exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
/**
* @type {any[]} headComponents
*/
const headComponents = getHeadComponents();
headComponents.sort((a, b) => {
if (a.props && a.props["data-react-helmet"]) {
return 0;
}
return 1;
});
replaceHeadComponents(headComponents);
};
Issue Analytics
- State:
- Created 4 years ago
- Reactions:26
- Comments:122 (15 by maintainers)
Top Results From Across the Web
gatsby-plugin-react-helmet
React Helmet is a component which lets you control your document head using their React component. With this plugin, attributes you add in...
Read more >How to render Helmet Meta Tags before Styles in Gatsby
It seems that the gatsby-plugin-react-helmet renders the meta tags too late in the head section. To test this assumption I briefly checked it ......
Read more >How to add meta tags with gatsby which first need to be fetched
This means that the Helmet component will be populated later than the crawler requests it. I'm not sure about your specs but you...
Read more >29 Installing React Helmet #Gatsby #React #PWA ... - YouTube
29 Installing React Helmet #tuto #tutorialReact Helmet is a component which lets you control your document head using their React component.
Read more >The Ultimate Guide to Gatsby & SEO - SALT.agency®
You can then create an SEO component that uses Gatsby's React Helmet plugin to retrieve the metadata from gatsby-config.js for inclusion in ...
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
I ran into the same issue. I tried checking the meta/og tags via several tools (e.g. Open Graph Check, Meta Tags, and Social Share Preview) and none of them were able to pick them up.
Once I mad a tweak similar to @Ciantic’s I was able to retrieve them successfully.
I beleive this was mainly caused by a rather large style tag being placed before the meta tags.
My solution requried a bit more to get it working. I had to implement the following in my
gatsby-ssr.js
(you may be able to get away with just using the onRenderbody api, but I used the onPreRenderHTML api as well to move them completely to the top):We are happy to review a PR changing the behavior of
gatsby-plugin-react-helmet
however we won’t work on this and thus the bot asking for activity is correct. We don’t consider this being broken but a feature request.