fix: destroy effect on error (#12376)

fixes #12360

---------

Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
pull/12385/head
Rich Harris 6 months ago committed by GitHub
parent 145d67a489
commit 47a073e0db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: destroy effects that error on creation

@ -109,6 +109,9 @@ function create_effect(type, fn, sync, push = true) {
set_is_flushing_effect(true);
update_effect(effect);
effect.f |= EFFECT_RAN;
} catch (e) {
destroy_effect(effect);
throw e;
} finally {
set_is_flushing_effect(previously_flushing_effect);
}

@ -104,7 +104,10 @@ export function runtime_suite(runes: boolean) {
if (config.skip_mode?.includes('hydrate')) return true;
}
if (variant === 'dom' && config.skip_mode?.includes('client')) {
if (
variant === 'dom' &&
(config.skip_mode?.includes('client') || (config.mode && !config.mode.includes('client')))
) {
return 'no-test';
}

@ -0,0 +1,13 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: '<p><p>invalid</p></p>',
mode: ['hydrate'],
recover: true,
test({ assert, target, logs }) {
target.click();
flushSync();
assert.deepEqual(logs, ['body', 'document', 'window']);
}
});

@ -0,0 +1,5 @@
<svelte:window onclick={() => console.log('window')} />
<svelte:document onclick={() => console.log('document')} />
<svelte:body onclick={() => console.log('body')} />
<p>{@html '<p>invalid</p>'}</p>

@ -0,0 +1,9 @@
<script>
import Inner from './Inner.svelte';
</script>
<svelte:window onclick={() => console.log('window')} />
<svelte:document onclick={() => console.log('document')} />
<svelte:body onclick={() => console.log('body')} />
<Inner />

@ -0,0 +1,11 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
mode: ['client'],
test({ assert, target, logs }) {
target.click();
flushSync();
assert.deepEqual(logs, []);
}
});

@ -0,0 +1,14 @@
<script>
import { mount, onMount } from 'svelte';
import Outer from './Outer.svelte';
let el;
onMount(() => {
try {
mount(Outer, { target: el });
} catch {}
});
</script>
<div bind:this={el}></div>
Loading…
Cancel
Save