Skip to content

Commit 1b89622

Browse files
committed
ix: ensure transient writes to tracked parent effects works as expected
1 parent e2bbc56 commit 1b89622

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

.changeset/brown-rockets-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure transient writes to tracked parent effects works as expected

packages/svelte/src/internal/client/runtime.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ export function update_reaction(reaction) {
460460
// the same version
461461
if (previous_reaction !== null) {
462462
read_version++;
463+
if (untracked_writes !== null) {
464+
if (previous_untracked_writes === null) {
465+
previous_untracked_writes = untracked_writes;
466+
} else {
467+
previous_untracked_writes.push(.../** @type {Source[]} */ (untracked_writes));
468+
}
469+
}
463470
}
464471

465472
return result;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
test({ assert, target, logs }) {
5+
assert.deepEqual(logs, ["Outer", 'Inner', "Outer", 'Inner']);
6+
}
7+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
3+
let value = $state(0);
4+
5+
$effect.pre(() => {
6+
console.log("Outer");
7+
value;
8+
9+
$effect.pre(() => {
10+
console.log("Inner");
11+
value = 10;
12+
});
13+
});
14+
</script>

0 commit comments

Comments
 (0)