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
gatsby-plugin-react-helmet orders the components too late in <head> #22206
Comments
Do you have any "sources" about facebook skipping trying to extract I'm not sure but ordering of this stuff shouldn't matter as long as it's there. |
In https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element I don't see any notion about ordering. Only ordering restrictions relate to charset meta - https://html.spec.whatwg.org/multipage/semantics.html#charset :
|
So if facebook don't pick up those tags if they are later on in - it seems like it's facebook that doesn't follow spec? |
No I don't have sources, this is a few years ago, I had the problem in entirely different stack. I watched the FB bot crawling and downloading only n-amount of bytes from the top, and if the og tags was not there it didn't parse them. I also have Content-Security-Policy, and it's odd if it comes after the style files. |
I gave the workaround in my main post already. If this is not actionable at the moment I will close this. |
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
|
Thank you @ttstauss your fix worked perfectly. |
If this issue exists, then I will reopen this. I think that Gatsby should handle the good ordering by default, and these hacks are just adding noise to us all trying to maintain configurations which should be in Gatsby itself. |
What's the directory of gatsby-ssr.js? |
@jun-gh, |
I tried adding this on my root directory, but still Helmet tags are still under several style tags. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
I don't have means to add labels. I wish one could just give reaction to that bot to not close it. Short of that, I have to comment. |
We are happy to review a PR changing the behavior of |
I closed this, since that's what the bot would have done, if this is not actionable. I would have thought that if the default gives a broken behavior as commented by others, it would be a bug. But others bug is someone's feature as the saying goes. Edit: How can you read mr. @ttstauss and @Dres90 comments as anything else than a bug? The default behavior leads to OG meta tags not being identified correctly, isn't that a bug? |
For the record I also had to implement this fix and I think ordering of head elements should be a feature. I want that level of control right out of the plugin |
Thank you @ttstauss . Your fix worked for me. |
|
@jun-gh I am also facing the same problem meta tags are still below the style tags, did you got a workaroud ? |
Also facing this issue |
No luck. I'm trying the prerender.io . I'll update if it works.
Martin I. Abanes
miabanes@gmail.com
…On Wed, Jul 8, 2020 at 8:30 AM Evan Rose ***@***.***> wrote:
Also facing this issue
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22206 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHI2Y5ZTZAEQXR4D5II7OTDR2O43DANCNFSM4LGNKWOQ>
.
|
Also, not entirely sure how @KyleAMathews Any thoughts? |
Gatsby renders the surrounding html separately from the body hence the two
apis.
…On Thu, Nov 18, 2021, 7:08 PM Grayson Hicks ***@***.***> wrote:
Also, not entirely sure how onPreRenderHTML and onRenderBody work
together and if this sorting can just be done in one, or should be done the
same in both.
@KyleAMathews <https://github.com/KyleAMathews> Any thoughts?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22206 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAARLB4DGSGDOUONAJVJ2EDUMW5SHANCNFSM4LGNKWOQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Okay, so should they both use the same ordering mechanism or does it matter? |
It looks like the tags present in html.js are already in the correct sequence ( |
The body is literally just for the html body so there's no meta, etc tags there. |
Does anyone have a repo that I can use to reproduce this? Even if you've implemented one of the workarounds above, I am trying to test a fix in the framework itself. Let me know, thanks! |
My issue is that https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-image interferes with this solution #22206 (comment) as it also uses |
@m99coder I believe the solution I am working on will always take place within the framework, after react-helmet. |
I think I was able to reproduce it here: https://github.com/graysonhicks/head-tags-test Steps
Expected ResultAll meta tags at the top of the head Actual ResultSome meta tags stuck at the bottom/in the middle I arbitrarily added as many cc: @KyleAMathews |
@graysonhicks That’s exactly what also happens in my case. If you wanna have a look at a “live” site: https://woodist.de. Can’t share the source, though. |
The problem is critical and no solution worked for my site. |
@leandroboari I have an approved PR here #34030 . Just need to get it merged and released 👍 |
This update solved the order of the tag in general pages. Dynamically generated pages with createPages still have the problem though |
@alejandrozeppelinlabs Hm, I think the file this changed is called the same regardless of whether a page is creating with File System API, pages folder, or createPages. Is that correct @KyleAMathews ? |
Yeah this fixes applies to all pages regardless of how it's created. |
mmm don't know what might be happening. This is the site as soon as you enter to any page inside https://zeppelinlabs.io/news/ the meta tags are mixed up. Thought it could be createPages because the difference between the news pages and the other ones is that. But I understand that it has to be something different might be happening |
@alejandrozeppelinlabs They look messed up after hydration, but I believe they are correct on the initial server response when is what a crawler will see:
Note I removed a lot of HTML and CSS that wasn't relevant to make the response somewhat smaller. Most importantly, |
The above fix doesn't work with created pages. https://developers.facebook.com/tools/debug/ Confirms this, it does seem to have fixed it on general pages |
Struggling on why headComponents.sort has no effect ( or not being run)? The gatsby-ssr.js is under src directory.
|
@stefan1968 I have dozens of dynamically created pages and all of them now have the correct order of @oscmimax2 I also had this snippet in my |
@m99coder I need to use the snippet because the system was implemented in 3.3. I am still figuring out why the gatsby-ssr.js 's onPreRenderHTML() doesn't come into effect. Also, is the effect not for development mode? |
The fix was backported to v3, but you need the latest for v3. This doesn't affect development mode, because the meta tags don't matter in development. |
@graysonhicks gatsby@3.14.6 is running here. I can still see tons of style and script above my meta tags. Is there anywhere I can check to make sure "meta tag upfloating" comes into effect? (using gatsby-plugin-react-helmet@4.14.0) Thanks. |
@oscmimax2 Are you looking at the original network request or just the DOM in the browser? |
@graysonhicks It was the DOM (= "Elements" view in chrome ) . Thanks :) |
Not sure how I can help, but I'm experiencing an issue as well with the Apple Smart Banner capability: https://developer.apple.com/documentation/webkit/promoting_apps_with_smart_app_banners My custom meta tag is appearing after "link" (which imports styles). Would love to get my meta tag ahead of that to see if Apple somehow reads my meta tag and displays the proper banner. And while we're at it, maybe it belongs before the "title" tag too... |
I'm locking this issue as resolved as the issue was fixed. If you have further questions, please open a GitHub discussion: https://github.com/gatsbyjs/gatsby/discussions/categories/help |
Description
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 theog
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
The text was updated successfully, but these errors were encountered: