Skip to content

Conversation

@colinmurphy
Copy link
Member

fixes #325

@colinmurphy colinmurphy marked this pull request as ready for review April 22, 2025 09:50
@colinmurphy colinmurphy requested review from ahuseyn, Copilot and moonmeister and removed request for Copilot April 22, 2025 09:50
Copy link
Contributor

Copilot AI left a 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.

@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-chore-fix-canonicals-remove-queries https://hb…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-chore-fix-canonicals-remove-queries https://hb…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-chore-fix-canonicals-remove-queries https://hb…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@colinmurphy
Copy link
Member Author

Tested - https://hb460lxzg149kqezezu23hfu1.js.wpenginepowered.com/blog/welcome-to-the-new-faustjs-org/?test=true

Screenshot 2025-04-22 at 13 23 30

@ahuseyn
Copy link
Member

ahuseyn commented Apr 22, 2025

Nice @colinmurphy, I've tested too!

Copy link
Member

@moonmeister moonmeister left a 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 = "";
Copy link
Member

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.

Copy link
Member Author

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 ❤️

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, this scenario cleans things:

image

Copy link
Member

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.

Copy link
Member Author

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 )

@moonmeister moonmeister self-requested a review April 23, 2025 21:05
Copy link
Member

@moonmeister moonmeister left a 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

@moonmeister
Copy link
Member

moonmeister commented Apr 29, 2025

Not the correct fix. @alexwpengine working on new PR

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.

fix: Bad Canonical Links

4 participants