mirror of https://github.com/sveltejs/svelte
fix: clean up svelte:head anchors on unmount (#18697)
include client-created <svelte:head> anchors in the head effect’s DOM range remove anchors through the existing HEAD_EFFECT teardown add client and hydration regression coverage for repeated mount/unmount cycles Fixes #18695 --------- Co-authored-by: svelte-triage-bot <team@svelte.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>pull/18508/merge
parent
15720b16a5
commit
4b61851ec8
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: remove `<svelte:head>` anchors on unmount
|
||||
@ -0,0 +1,3 @@
|
||||
<svelte:head>
|
||||
<meta name="test" content="value" />
|
||||
</svelte:head>
|
||||
@ -0,0 +1,19 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { ok, test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'hydrate'],
|
||||
|
||||
test({ assert, target, window }) {
|
||||
const initial = window.document.head.childNodes.length;
|
||||
const button = target.querySelector('button');
|
||||
ok(button);
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
flushSync(() => button.click());
|
||||
flushSync(() => button.click());
|
||||
}
|
||||
|
||||
assert.equal(window.document.head.childNodes.length, initial);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
import Head from './Head.svelte';
|
||||
|
||||
let show = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (show = !show)}>toggle</button>
|
||||
|
||||
{#if show}
|
||||
<Head />
|
||||
{/if}
|
||||
Loading…
Reference in new issue