svelte
svelte copied to clipboard
svelte:head does not remove title tag
Describe the bug
A title tag added using <svelte:head>
, cannot be removed? like you can with any other tag i have tested (meta, script).
Reproduction
<svelte:head>
{#if toggleBool}
<!-- stays put even if toggleBool is false -->
<title>Title injected!!!</title>
<!-- gets removed as expected -->
<meta name="description" content="I am ALIVE" />
<!-- gets removed as expected -->
<script>
console.log('I am alive!');
</script>
{/if}
</svelte:head>
Relevant repl: https://svelte.dev/repl/2ecf81b43d0d4b2eaa02d80adf803929?version=3.48.0
Logs
No response
System Info
Windows 10, Firefox & Edge, svelte repl 3.48.0
Severity
annoyance
I think thats on purpose, because when you would remove the title, without setting a new one the page would have no title at all. So the only way to change the title is to set a new one. You could of cause keep track of the previeous titles and set it to the last one. This could be a possible solution
This actually blocks fallback titles, maybe we can (at least) remove the title when one is present in a parent, like:
<!-- src/routes/+layout.svelte -->
<svelte:head>
<title>Fallback</title>
</svelte:head>
<!-- src/routes/+page.svelte -->
<svelte:head>
<title>Home</title>
</svelte:head>
<a href="/404">Go to 404 page</a>
Give the above example a direct call to "/404" will result in the title "Fallback" while a call using CSR will result in the old title "Home" still being displayed instead of the fallback one.