mirror of https://github.com/sveltejs/svelte
fix: don't depend on deriveds created inside the current reaction (#15564)
* WIP * WIP * add test * update test * changeset * oops * lintpull/15551/head
parent
1d10a65b78
commit
d2e79326c7
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't depend on deriveds created inside the current reaction
|
@ -0,0 +1,20 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
test({ assert, target, logs }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
flushSync(() => button?.click());
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<p>1/2</p
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(logs, [0, 0]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,26 @@
|
|||||||
|
<script>
|
||||||
|
class Foo {
|
||||||
|
value = $state(0);
|
||||||
|
double = $derived(this.value * 2);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
console.log(this.value, this.double);
|
||||||
|
}
|
||||||
|
|
||||||
|
increment() {
|
||||||
|
this.value++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let foo = $state();
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
foo = new Foo();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => foo.increment()}>increment</button>
|
||||||
|
|
||||||
|
{#if foo}
|
||||||
|
<p>{foo.value}/{foo.double}</p>
|
||||||
|
{/if}
|
Loading…
Reference in new issue