fix: ensure unowned deriveds correctly update (#12747)

pull/12752/head
Dominic Gannaway 2 months ago committed by GitHub
parent 98ae05b569
commit bd9a2d2077
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure unowned deriveds correctly update

@ -162,9 +162,9 @@ export function check_dirtiness(reaction) {
if ((flags & MAYBE_DIRTY) !== 0) {
var dependencies = reaction.deps;
var is_unowned = (flags & UNOWNED) !== 0;
if (dependencies !== null) {
var is_unowned = (flags & UNOWNED) !== 0;
var i;
if ((flags & DISCONNECTED) !== 0) {
@ -198,7 +198,10 @@ export function check_dirtiness(reaction) {
}
}
set_signal_status(reaction, CLEAN);
// Unowned signals should never be marked as clean.
if (!is_unowned) {
set_signal_status(reaction, CLEAN);
}
}
return false;

@ -676,4 +676,21 @@ describe('signals', () => {
assert.equal(d.deps?.length, 1);
};
});
test('unowned deriveds correctly update', () => {
return () => {
const arr1 = proxy<{ a: number }[]>([]);
const arr2 = proxy([]);
const combined = derived(() => [...arr1, ...arr2]);
const derived_length = derived(() => $.get(combined).length);
assert.deepEqual($.get(combined), []);
assert.equal($.get(derived_length), 0);
arr1.push({ a: 1 });
assert.deepEqual($.get(combined), [{ a: 1 }]);
assert.equal($.get(derived_length), 1);
};
});
});

Loading…
Cancel
Save