QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.19k stars 52 forks source link

[Question][Maybe due to the middleware] Forced `canonical` on OpenGraph? #404

Open gustaveWPM opened 1 month ago

gustaveWPM commented 1 month ago

Hello, I don't know if it is really related to Next International, because I've given a quick look in its source code and found 0 occurrence of canonical.

Unfortunately, I have a super weird issue with OpenGraph. Let's say I have a page which exists in English https://dashboard-rtm.vercel.app/en/blog/patch-notes/dashboard/post-11, but not in any other language, and not in the default language too.

image

If I go to the Facebook Sharing Debugger, and then force a scrape of my page, then, I see that the canonical is forced to https://dashboard-rtm.vercel.app/blog/patch-notes/dashboard/post-11.

This is super weird, because I've set the canonical within the generateMetadata function, using App Router, respecting all the Next.js standards and using the latest version of Next, which is currently v14.2.3. Also, I'm using urlMappingStrategy: 'rewriteDefault'.

So... I don't know what's going on. Everything seems to be set perfectly fine in my <head> tag.

There is no https://dashboard-rtm.vercel.app/blog/patch-notes/dashboard/post-11 canonical.

https://dashboard-rtm.vercel.app/en/blog/patch-notes/dashboard/post-11

Weird too, if I go to the Pagespeed Insights and put https://dashboard-rtm.vercel.app/blog/patch-notes/dashboard/post-11, then it will redirect properly, detecting a connection from USA.

image

I have no clue. :( Is this likely to be coming from Next International, even if I don't think so?


EDIT: setting an explicit og:url does not change anything


EDIT 2: hmmm... image

I've never set a canonical on a page which has two translations like this. Weird.

Also, I do not understand the 307 HTTP Redirect. It looks like the real issue is this redirect, which may be the root cause of all of this, leading Facebook's debug tool to infer the canonical based on the content after this redirection.

URL: https://dashboard-rtm.vercel.app/en/blog/patch-notes/dashboard/post-06

Maybe the middleware should NOT redirect when a request comes from services such as Pagespeed Insights or OpenGraph? (Using something like this: https://github.com/omrilotan/isbot)


Also, I'm looking forward to test the v2. I just would like to have an opinion about all of this: is it due to Next International or not, if so, why, how, and can we hope this to be fixed or shall we workaround it on the app side?

gustaveWPM commented 1 month ago

Hmm... Yes, after some other tests, it seems that the middleware always redirect the OpenGraph crawler to the default locale. I'll keep that in mind while waiting for the v2.