Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/components/seo.jsx
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 = "";
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 )

canonicalUrl = urlObject.toString();
}

return (
<Head>
Expand Down