-
Notifications
You must be signed in to change notification settings - Fork 3
chore: Fixed an issue with canonical URLs containing query strings #328
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| import Head from "next/head"; | ||
|
|
||
| export default function SEO({ title, description, imageUrl, url }) { | ||
| const canonicalUrl = url | ||
| ? // eslint-disable-next-line no-restricted-globals, n/prefer-global/process, n/prefer-global/url | ||
| new URL(url, process.env.NEXT_PUBLIC_SITE_URL) | ||
| : undefined; | ||
| let canonicalUrl = false; | ||
|
|
||
| if (url) { | ||
| // eslint-disable-next-line no-restricted-globals, n/prefer-global/process, n/prefer-global/url | ||
| const urlObject = new URL(url, process.env.NEXT_PUBLIC_SITE_URL); | ||
| // Remove any query string as search is writable so we remove any potential query string | ||
| urlObject.search = ""; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the search string issues but I could imagine others potentially. I'm wondering if this is the correct fix or if the issue is the URL we are passing in is from the router and not from WP.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @moonmeister Ah I see your point. Let me fix this. Thanks for spotting this ❤️
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @moonmeister Sorry I might be missing something here. But if you have a look at the blog post slug template we have
and that uri is used for the SEO component So it looks to me we are using the WP URL and sorry if I am totally missing something.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colinmurphy Interesting. Well, the bad URL is getting in there somehow. Maybe we need to dig deeper.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just updated the original ticket with a video. TL;DR: This only affects doc pages as supported by my testing and the analytics page I linked to there.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @moonmeister 🚀 @alexwpengine is going to have a look. (Thanks @alexwpengine ) |
||
| canonicalUrl = urlObject.toString(); | ||
| } | ||
|
|
||
| return ( | ||
| <Head> | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.