mirror of https://github.com/sveltejs/svelte
fix: don't run teardown effects when deriveds are unfreezed (#18227)
The logic was flawed - a teardown effect only has a teardown function but not `fn` property, but unfreeze thought that everything with a `teardown` needs to be unfreezed Helps with #18221 (though likely doesn't fix it completely, at least not the more general `batch.#roots`problems)pull/18239/head
parent
1e899cba35
commit
dc1f037fa6
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't run teardown effects when deriveds are unfreezed
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: { dev: true }, // for testing that teardown effect in eager $.get(loaded) doesn't lead to a crash (because it means REACTION_RAN is set, which means unfreeze_derived runs)
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [count, shift] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>0</button><button>shift</button><p>0</p>`);
|
||||||
|
|
||||||
|
count.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>1</button><button>shift</button><p>0 (...)</p>`);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>1</button><button>shift</button><p>1</p>`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
let resolvers = [];
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
const { promise, resolve } = Promise.withResolvers();
|
||||||
|
resolvers.push(() => resolve(value));
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count += 1}>{$state.eager(count)}</button>
|
||||||
|
<button onclick={() => resolvers.shift()?.()}>shift</button>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
{@const loaded = $state.eager(count) === count}
|
||||||
|
<p>{await push(count)} {loaded ? '' : '(...)'}</p>
|
||||||
|
|
||||||
|
{#snippet pending()}{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
Loading…
Reference in new issue