mirror of https://github.com/sveltejs/svelte
fix: ensure eager effects don't break reactions chain (#17138)
Execution of eager effects didn't set `is_updating_effect`, which meant the logic in `get` would wrongfully prevent dependencies being added to `reactions` of sources/deriveds. Fixes #17133pull/17168/head
parent
a7a6d898d5
commit
99e670f632
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure eager effects don't break reactions chain
|
||||
@ -0,0 +1,35 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { normalise_inspect_logs } from '../../../helpers';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
async test({ assert, target, logs }) {
|
||||
const [b] = target.querySelectorAll('button');
|
||||
|
||||
b.click();
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, `<button>first unseen: 1</button>`);
|
||||
|
||||
b.click();
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, `<button>first unseen: 2</button>`);
|
||||
|
||||
b.click();
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, `<button>first unseen:</button>`);
|
||||
|
||||
assert.deepEqual(normalise_inspect_logs(logs), [
|
||||
[0, 1, 2],
|
||||
[1, 2],
|
||||
'at SvelteSet.add',
|
||||
[2],
|
||||
'at SvelteSet.add',
|
||||
[],
|
||||
'at SvelteSet.add'
|
||||
]);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
import {SvelteSet} from "svelte/reactivity";
|
||||
const ids = [0,1,2];
|
||||
const seenIds = new SvelteSet();
|
||||
|
||||
const unseenIds = $derived(ids.filter((id) => !seenIds.has(id)));
|
||||
|
||||
const currentId = $derived(unseenIds.at(0));
|
||||
$inspect(unseenIds)
|
||||
</script>
|
||||
|
||||
<button onclick={() => seenIds.add(currentId)}>
|
||||
first unseen: {currentId}
|
||||
</button>
|
||||
Loading…
Reference in new issue