-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Duplicate <link rel="canonical"/> #32944
Comments
Given your reproduction, I could not reproduce this. Make sure you don't have a typo in |
Hi, @balazsorban44 I just found the will fuplicate If I use with preact (https://github.com/preactjs/next-plugin-preact) I create a repo with duplicate result I set
The is duplicate. but If I set
The is not duplicate |
It seems to be an issue with |
@balazsorban44 if (h.key && typeof h.key !== 'number' && h.key.indexOf('$') > 0) {
hasKey = true;
const key = h.key.slice(h.key.indexOf('$') + 1);
if (keys.has(key)) {
isUnique = false;
} else {
keys.add(key);
}
} |
That's from #9315 and it's necessary because React "escapes" keys by prepending const SEPARATOR = '.'; // line 22
...
function escape(key: string) {
...
return '$' + escapedString; // line 41
}
function getElementKey(element: any, index: number) {
...
return escape('' + element.key); // line 71
...
}
function mapIntoArray() {
...
const childKey =
nameSoFar === '' ? SEPARATOR + getElementKey(child, 0) : nameSoFar; // line 116
...
} In Preact,
I see you've created preactjs/next-plugin-preact#51, but I'm not sure if that's the right repository. Perhaps preact/compat is where such adjustments need to be made, since that's the Preact->React compat layer. Anyway, for now I've manually put |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
12.0.4
What version of Node.js are you using?
v16.10.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
Hi, Core Team
I develop a website with next.js and I have to do about SEO, so I study from a guideline https://nextjs.org/docs/api-reference/next/head.
I put a default meta tag in custom _app.tsx with <title/> or meta tag and some page that have to specific <title/> or meta I use key property to avoid the duplication it work fine, but when I put a link tag for canonical. Output show a html content with duplicate canonical.
Example html output
So I go to the shared/lib/head.js https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/head.tsx#L67, I found a unique logic by
If I set the key with $ in the key for an example.
The canonical from pages/example.tsx is output as one and only canonical for that page.
I'm not sure why you have to check h.key.indexOf('$') > 0, I think most of developer follow the guide from https://nextjs.org/docs/api-reference/next/head, If the logic was right, May be the document need to be updated or this is a new bug.
Please answer ASAP because I want to fix this as fast as possible, I have to keep working for an seo on website.
Thanks in advance.
Expected Behavior
Expected the with key props not duplicate for an example .
To Reproduce
Create a with key property and put it in Head from next/head The will duplicate in head tag.
Example html output
The text was updated successfully, but these errors were encountered: