Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set deriveds as CLEAN if they are assigned to #15592

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nervous-kids-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: set deriveds as `CLEAN` if they are assigned to
4 changes: 4 additions & 0 deletions packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export function internal_set(source, value) {
}
}

if ((source.f & DERIVED) !== 0) {
set_signal_status(/** @type {Derived} */ (source), CLEAN);
}

mark_reactions(source, DIRTY);

// It's possible that the current reaction might not have up-to-date dependencies
Expand Down
15 changes: 15 additions & 0 deletions packages/svelte/tests/signals/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,21 @@ describe('signals', () => {
};
});

test("deriveds set after they are DIRTY doesn't get updated on get", () => {
return () => {
const a = state(0);
const b = derived(() => $.get(a));

set(b, 1);
assert.equal($.get(b), 1);

set(a, 2);
set(b, 3);

assert.equal($.get(b), 3);
};
});

test('deriveds containing effects work correctly when used with untrack', () => {
return () => {
let a = render_effect(() => {});
Expand Down