svelte:head not removing/updating components
Describe the bug
TL;DR
Seperate
The problem
Before we simply placed the title in a
Now, the SEO itself works fine for a page visit, until we navigate. The previous
I'm not sure if this is intended behavior. If it is, it should be clearly stated in the documentation for either SvelteKit or Svelte. Or even worse, if we're blocked by how the internals work, we should give a clear, and preferably simple, alternative. I'm currently considering a context with SEO info in the root layout, but I haven't experimented with that yet😅
Otherwise, thanks for the amazing framework, I've really enjoyed working with it. This is just a minor problem, I've experienced across a couple of different projects now, so I decided to make an issue.
Have a nice day😄
Reproduction
lib/Seo.svelte
<script>
export let title;
export let metaDescription;
</script>
<title>{title}</title>
<meta name="description" content={metaDescription} />
<meta property="og:description" content={metaDescription} />
routes/+page.svelte
<script>
import Seo from '$lib/Seo.svelte'
</script>
<svelte:head>
<Seo title="Main page" metaDescription="Description for main page" />
</svelte:head>
<h1>Main page</h1>
<a href="/sub">Go to subpage</a>
routes/sub/+page.svelte
<script>
import Seo from '$lib/Seo.svelte';
</script>
<svelte:head>
<Seo title="Subpage title" metaDescription="This is a description for the subpage"></Seo>
</svelte:head>
<h1>Subpage</h1>
<a href="/">Go to main page</a>
Reproducible repo: https://github.com/Nerglej/sveltekit_head_bug
I also create a SvelteLab REPL if that's okay: https://www.sveltelab.dev/87889fasa3uab9m
To view the problem in the REPL, use your browser debugger (usually F12), and inspect the iframe where the content is rendered. Under the tag you can find the
where each navigation just appends new titles and metatagsLogs
No response
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.2.2
@sveltejs/kit: ^2.0.0 => 2.5.16
@sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.1
svelte: ^4.0.5 => 4.2.18
vite: ^5.0.0 => 5.3.1
Severity
serious, but I can work around it
Additional Information
I ran the System Info command in the SvelteKit REPL mentioned above, so you should roughly get the same results. I have the same problem on three machines, both Windows and Linux, so I don't suspect the system is the problem but either SvelteKit or Svelte.