mirror of https://github.com/sveltejs/svelte
fix: attach effects-inside-deriveds to the parent of the derived (#13309)
* WIP * fix types * ensure effects with deriveds are added to the tree * test * changeset * oopspull/13311/head
parent
c4d8d405c9
commit
1d1e4aeeb1
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: attach effects-inside-deriveds to the parent of the derived
|
@ -0,0 +1,16 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: '<button>clicks: 0</button>',
|
||||
|
||||
test({ assert, target }) {
|
||||
const button = target.querySelector('button');
|
||||
|
||||
flushSync(() => button?.click());
|
||||
assert.htmlEqual(target.innerHTML, '<button>clicks: 1</button>');
|
||||
|
||||
flushSync(() => button?.click());
|
||||
assert.htmlEqual(target.innerHTML, '<button>clicks: 2</button>');
|
||||
}
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
let count = $state(0);
|
||||
|
||||
const { value } = $derived.by(() => {
|
||||
let value = $state(0);
|
||||
|
||||
$effect(() => {
|
||||
value = count;
|
||||
});
|
||||
|
||||
return {
|
||||
get value() {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<button onclick={() => (count += 1)}>clicks: {value}</button>
|
Loading…
Reference in new issue