mirror of https://github.com/sveltejs/svelte
fix: prevent derives without dependencies from ever re-running (#17445)
* fix: prevent derives without dependencies from ever re-running * tweak Co-authored-by: David Roizenman <hmnd@users.noreply.github.com>pull/17456/head
parent
f8bdadc1bf
commit
286b40c452
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: prevent derives without dependencies from ever re-running
|
||||
@ -0,0 +1,22 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
skip_no_async: true,
|
||||
async test({ assert, target }) {
|
||||
const [fork] = target.querySelectorAll('button');
|
||||
|
||||
fork.click();
|
||||
await tick();
|
||||
|
||||
const [, increment] = target.querySelectorAll('button');
|
||||
const p = target.querySelector('p');
|
||||
|
||||
assert.equal(p?.textContent, '0');
|
||||
|
||||
increment.click();
|
||||
await tick();
|
||||
|
||||
assert.equal(p?.textContent, '1');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
import { fork } from 'svelte';
|
||||
|
||||
class Counter {
|
||||
count = $state(0);
|
||||
}
|
||||
|
||||
let condition = $state(false);
|
||||
let counter = $derived(new Counter());
|
||||
</script>
|
||||
|
||||
<button onclick={() => {
|
||||
fork(() => {
|
||||
condition = true;
|
||||
}).commit();
|
||||
}}>fork</button>
|
||||
|
||||
{#if condition}
|
||||
<button onclick={() => {
|
||||
counter.count++;
|
||||
}}>click</button>
|
||||
<p>{counter.count}</p>
|
||||
{/if}
|
||||
Loading…
Reference in new issue