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

Fix the <Seo /> component to render canonical URLs without trailing slashes #1622

Merged
merged 1 commit into from Jan 9, 2024

Conversation

blittle
Copy link
Contributor

@blittle blittle commented Jan 8, 2024

WHY are these changes introduced?

Fixes #1619. Thank you @joshuafredrickson!

WHAT is this pull request doing?

We change the Seo component so that it always strips the trailing slash. Are there scenarios where this is not desirable?

HOW to test your changes?

Load the demo store, and view the source code of http://localhost:3000/collections/freestyle/ and verify that the trailing slash is not included in the canonical URL tag.

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@@ -411,15 +411,16 @@ export function generateSeoTags<
}

const urlWithoutParams = content.split('?')[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that our Seo implementation strips off all query parameters. Technically I don't think this is always the right thing to do. Would merchants ever want product variants to be indexed separately? The challenge to properly do this is we would need to know which query params relate to product options, and which are irrelevant and should be stripped 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least from reading the SEO recommendations, it is not recommended to have query params, especially when the content is similar. For example,

search pages /search should be the main crawl-able page while other variants should have canonical url to the same search url

  • /search?query=blue - canonical url should be /search

Same should be with product variants - main url /products/best-product-ever. Its variants /products/best-product-ever?color=blue should have the same canonical urls because

  • Majority of the page content is the same
  • When grouped as the same canonical url, the product search ranking won't be fragmented by the variants

@blittle blittle merged commit 36d6fa2 into main Jan 9, 2024
10 checks passed
@blittle blittle deleted the bl-fix-seo-canonical-tags branch January 9, 2024 14:34
This was referenced Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canonical URLs are generated with a trailing slash and without
2 participants