Skip to content

Commit 5ace53d

Browse files
committed
fix: set deriveds as CLEAN if they are assigned to
1 parent 3080c13 commit 5ace53d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.changeset/nervous-kids-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: set deriveds as `CLEAN` if they are assigned to

packages/svelte/src/internal/client/reactivity/sources.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export function internal_set(source, value) {
171171
}
172172
}
173173

174+
if ((source.f & DERIVED) !== 0) {
175+
set_signal_status(/** @type {Derived} */ (source), CLEAN);
176+
}
177+
174178
mark_reactions(source, DIRTY);
175179

176180
// It's possible that the current reaction might not have up-to-date dependencies

packages/svelte/tests/signals/test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,21 @@ describe('signals', () => {
10801080
};
10811081
});
10821082

1083+
test.only("deriveds set after they are DIRTY doesn't get updated on get", () => {
1084+
return () => {
1085+
const a = state(0);
1086+
const b = derived(() => $.get(a));
1087+
1088+
set(b, 1);
1089+
assert.equal($.get(b), 1);
1090+
1091+
set(a, 2);
1092+
set(b, 3);
1093+
1094+
assert.equal($.get(b), 3);
1095+
};
1096+
});
1097+
10831098
test('deriveds containing effects work correctly when used with untrack', () => {
10841099
return () => {
10851100
let a = render_effect(() => {});

0 commit comments

Comments
 (0)