Skip to content
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

Duplicated tags with ssr #556

Closed
0x366 opened this issue Jan 15, 2023 · 2 comments
Closed

Duplicated tags with ssr #556

0x366 opened this issue Jan 15, 2023 · 2 comments
Labels
blocked by upstream bug Something isn't working

Comments

@0x366
Copy link

0x366 commented Jan 15, 2023

Describe the bug
I have a website with ssr. On each +page.svelte I have a . On dev it's working fine. If I build and run on prod - I have duplicated tags

This is is how every +page.svelte looks like:

import {LL, locale} from "./../i18n/i18n-svelte"


<<<< body>>>>


<MetaTags
	title="{$LL.pageTitle.main()}"
	description="{$LL.pageDescription.main()}"
	languageAlternates="{getHeadLinks($page.url.pathname, $locale).alternate}"
	canonical="{`https://mywebsite.com/${$locale}${removeLocaleFromPath(
		$page.url.pathname,
		$locale
	)}`}"
/>

** FUNCTIONS**


let LOCALES = ["de", "en"]; // IMPORANT ADD NEW LANG
export const getHeadLinks = (url: string, locale: string) => {
	url = removeLocaleFromPath(url, locale);
	let alternate = [
		{ hrefLang: "x-default", href: `https://mywebsite.com/${url}` },
		{ hrefLang: "de", href: `https://mywebsite.com/de${url}` },
		{ hrefLang: "en", href: `https://mywebsite.com/en${url}` }
	];
	return { alternate: alternate };
};

export const removeLocaleFromPath = (path: string, locale: string) => {
	for (let i = 0; i < LOCALES.length; i++) {
		path = path.replace(`/${LOCALES[i]}/`, "/");
	}
	for (let i = 0; i < LOCALES.length; i++) {
		if (path === `/${LOCALES[i]}`) {
			path = "";
		}
	}
	return path;
};

If I run the build with js turned off - there is only one instance of meta tag. Tho if I turn it on - the second one appears. When I goto anotherpage one instance of metatag changes its urls, and the other doesn't. So seems like the metatags injected 2 times - on server side and on client side. How do I turn it off ?

@0x366 0x366 added the bug Something isn't working label Jan 15, 2023
@oekazuma
Copy link
Owner

oekazuma commented Jan 16, 2023

This may not be a bug in svelte-meta-tags.
I don't know the details, but I think it's a bug in Svelte or SvelteKit, so I suggest you create a bug there.

@0x366
Copy link
Author

0x366 commented Jan 19, 2023

solved by sveltejs/svelte#4533 (comment)

@0x366 0x366 closed this as completed Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked by upstream bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants