The Wayback Machine - https://web.archive.org/web/20201201113814/https://github.com/gatsbyjs/gatsby/issues/27298
Skip to content
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

Simple gatsby-plugin-canonical-urls Protocol Bug #27298

Open
mikleing opened this issue Oct 5, 2020 · 14 comments · May be fixed by #27585
Open

Simple gatsby-plugin-canonical-urls Protocol Bug #27298

mikleing opened this issue Oct 5, 2020 · 14 comments · May be fixed by #27585

Comments

@mikleing
Copy link

@mikleing mikleing commented Oct 5, 2020

Description

The gatsby-plugin-canonical-urls plugin adds a rel=canonical tag to the head of each HTML page.

Here is an example of code added to the head of the html document:

<link rel="canonical" href="https://www.abc.com" data-baseprotocol="https:" data-basehost="www.abc.com">

The potential problem is with the protocol. It states the protocol is "https:". But shouldn't it be "https" without the colon?

How to Reproduce

  1. Start with the Gatsby Starter Default.
  2. Install the gatsby-plugin-canonical-urls plugin.
  3. Run "gatsby develop"
  4. Open "localhost:8000" in Google Chrome.
  5. Open the developer tools (click F12).
  6. Select "Elements"
  7. Expand the "head" section.
  8. Look for the rel=canonical tag.
  9. Find the property data-baseprotocol. It should be equal to "https" not "https:"

Solution

Open the gatsby-srr.js file. And modify line 29 to remove the colon. Here is what line 29 should look like:

data-baseprotocol={parsed.protocol.slice(0, -1)}

@rutujak24
Copy link

@rutujak24 rutujak24 commented Oct 6, 2020

Please assign me this issue

@LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Oct 6, 2020

Hi!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

@rutujak24
Copy link

@rutujak24 rutujak24 commented Oct 6, 2020

@LekoArts Sir, Can I work on this issue and solve it?

@LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Oct 6, 2020

@rutujak24 This issue lacks a clear issue/error description so there isn't anything actionable here. Please have a look at the issues tagged with hacktoberfest.

@mikleing
Copy link
Author

@mikleing mikleing commented Oct 6, 2020

@rutujak24 I have updated my original message to include information on how to reproduce the error. I didn't create a reproduction since the error is found by simply using a starter project and installing the plugin. There is no special code needed to reproduce the error. I do also include the steps to fix the error. It's a very simple error.

@pvdz
Copy link
Contributor

@pvdz pvdz commented Oct 7, 2020

Can you cite a reference stating the protocol should be without a colon? I can't find a reference and everything I find on the canonical tag also has a colon.

@pvdz
Copy link
Contributor

@pvdz pvdz commented Oct 7, 2020

Honestly I'm of half a mind to just drop data-basehost and data-baseprotocol. I cannot find any reference that refers to these attributes or how they ought to be filled. These attributes were added two years ago but the PR (#4116) does not explain why. I don't think the original issue (#4110) does either. Perhaps @danhounshell can chime in here?

@mikleing
Copy link
Author

@mikleing mikleing commented Oct 7, 2020

Before posting the issue, I spend a fair amount of time looking for any specification for data-basehost and data-baseprotocol. I couldn't find any standard or even a reference of anyone who uses those values. Google's documentation does not comment on data-basehost or data-baseprotocol. I also began to wonder if they were really needed.

So I don't have a reference that says the protocol should not have the colon. But I've never seen a reference to the protocol that includes the colon. Plus, I could see how this could have been an oversight by the original programmer. The field parsed.protocol seems to give you exactly what you want. But I've seen people add the .slice(0, -1) function when referencing the protocol from the url package.

@rutujak24
Copy link

@rutujak24 rutujak24 commented Oct 8, 2020

Yes I do agree with @mikleing
I had a similar approach to this issue.

@pvdz
Copy link
Contributor

@pvdz pvdz commented Oct 9, 2020

Considering it's been like this for two years, I would suggest to either keep it as is or drop it entirely. If nothing is actually using this, they're just dead bytes. And arguably, the protocol of the canonical url should be leading anyways so it feels like a redundant field regardless.

@pvdz
Copy link
Contributor

@pvdz pvdz commented Oct 9, 2020

Ok, @pieh pointed me towards https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-canonical-urls/src/gatsby-browser.js#L6-L21 and that this is probably the reason for these attributes existing in the first place. Nothing else. So removing the colon would break that so we're not going to do that.

So I'd propose to drop these attributes and get this information straight from the canonical url in browser.js instead.

@mikleing
Copy link
Author

@mikleing mikleing commented Oct 9, 2020

@pvdz That sounds like a good plan.

@tmttn
Copy link
Contributor

@tmttn tmttn commented Oct 21, 2020

So I'd propose to drop these attributes and get this information straight from the canonical url in browser.js instead.

My PR is pretty much exactly this. :-)

@LekoArts LekoArts removed the Hacktoberfest label Nov 2, 2020
@github-actions
Copy link

@github-actions github-actions bot commented Nov 22, 2020

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? label Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.