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

gatsby-plugin-canonical-urls: root page canonical url contains trailing slash when trailingSlash === never #38377

Closed
2 tasks done
techfg opened this issue Jul 27, 2023 · 1 comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@techfg
Copy link

techfg commented Jul 27, 2023

Preliminary Checks

Description

When trailingSlash is set to never, gatsby-plugin-canonical-urls generates a canonical url for the default page that ends in a trailling slash (all other pages are correct).

image

image

The issue seems to stem from https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-canonical-urls/src/gatsby-ssr.js#L10 where it always adds pathname to the parsed url.

Reproduction Link

https://codesandbox.io/p/sandbox/canonical-urls-contains-trailingslash-l7f9sf

Steps to Reproduce

  1. Set trailingSlash to never in gatsby-config.js
  2. Build site (gatsby develop)
  3. Inspect HTML head in default page (`/')

Note

If using Codesandbox repro, you may need to open the sandbox URL in a separate tab to open dev tools

Expected Result

The default page canonical url should not contain a trailing slash

Actual Result

The default page canonical url does contain a trailing slash

Environment

System:
    OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (2) x64 AMD EPYC
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.16.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.5.1 - /usr/local/bin/npm
  npmPackages:
    gatsby: ^5.11.0 => 5.11.0
    gatsby-plugin-canonical-urls: ^5.11.0 => 5.11.0

Config Flags

N/A

@techfg techfg added the type: bug An issue or pull request relating to a bug in Gatsby label Jul 27, 2023
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 27, 2023
@techfg techfg changed the title gatsby-plugin-canonical-urls: root page canonical url contains trailing slash when trailingSlash === never gatsby-plugin-canonical-urls: root page canonical url contains trailing slash when trailingSlash === never Jul 27, 2023
@techfg
Copy link
Author

techfg commented Jul 27, 2023

Apologies, just found the closed issue #37536 which references #34205 (reply in thread) where this was discussed. The release notes from 4.7 indicate that any path with a / when never is configured will 301 redirect which is the behavior I experience. Thinking this through some more and validating behavior, confirmed that 301 is returned when path ends in / EXCEPT for the default page where only window.location.href is "adjusted" to remove the slash which makes sense since root paths can't be redirected.

The main concern was making sure everything is consistent across core gatsby & the plugins when trailingSlash is never which it does appear to be. I should have looked more closely before opening this issue, apologies again.

Closing this out.

@techfg techfg closed this as completed Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant