-
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue with canonical URLs by ensuring that query strings are removed from the URL before rendering the canonical tag.
- Replaces the ternary operator initialization with an if block to remove query strings.
- Ensures the canonical URL is generated without any query parameters.
Co-authored-by: Copilot <[email protected]>
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
|
Nice @colinmurphy, I've tested too! |
moonmeister
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment, I'm wondering if this is the correct fix
| // 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 = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
const { title, date, author, uri, excerpt, editorBlocks } = post;
and that uri is used for the SEO component
<Seo
title={title}
url={uri}
description={excerpt.replaceAll(/<\/?\S+>/gm, "")}
/>
So it looks to me we are using the WP URL and sorry if I am totally missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @moonmeister 🚀
@alexwpengine is going to have a look. (Thanks @alexwpengine )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix for doc pages not in SEO component as discussed in previously
|
Not the correct fix. @alexwpengine working on new PR |


fixes #325