Skip to content

Commit 5d3aa2b

Browse files
trueadmRich-Harris
andauthored
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>
1 parent b27ca42 commit 5d3aa2b

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: invalidate parent effects when child effects update parent dependencies

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

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

465473
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
let value = $state(0);
3+
4+
$effect.pre(() => {
5+
console.log("Outer");
6+
value;
7+
8+
$effect.pre(() => {
9+
console.log("Inner");
10+
value = 10;
11+
});
12+
});
13+
</script>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy