fix: ensure transient writes to tracked parent effects works as expected (#15506)

* ix: ensure transient writes to tracked parent effects works as expected

* lint

* format test

* tweak changeset

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/15510/head
Dominic Gannaway 6 months ago committed by GitHub
parent b27ca425c7
commit 5d3aa2bda4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: invalidate parent effects when child effects update parent dependencies

@ -460,6 +460,14 @@ export function update_reaction(reaction) {
// the same version
if (previous_reaction !== null) {
read_version++;
if (untracked_writes !== null) {
if (previous_untracked_writes === null) {
previous_untracked_writes = untracked_writes;
} else {
previous_untracked_writes.push(.../** @type {Source[]} */ (untracked_writes));
}
}
}
return result;

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
test({ assert, target, logs }) {
assert.deepEqual(logs, ['Outer', 'Inner', 'Outer', 'Inner']);
}
});

@ -0,0 +1,13 @@
<script>
let value = $state(0);
$effect.pre(() => {
console.log("Outer");
value;
$effect.pre(() => {
console.log("Inner");
value = 10;
});
});
</script>
Loading…
Cancel
Save