fix: better handling of derived signals that have no dependencies (#10558)

* fix: better handling of derived signals that have no dependencies

* fix: better handling of derived signals that have no dependencies
pull/10561/head
Dominic Gannaway 10 months ago committed by GitHub
parent aef245364c
commit 5698fb789c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: better handling of derived signals that have no dependencies

@ -824,7 +824,8 @@ function update_derived(signal, force_schedule) {
destroy_references(signal);
const value = execute_signal_fn(signal);
updating_derived = previous_updating_derived;
const status = current_skip_consumer || (signal.f & UNOWNED) !== 0 ? DIRTY : CLEAN;
const status =
(current_skip_consumer || (signal.f & UNOWNED) !== 0) && signal.d !== null ? DIRTY : CLEAN;
set_signal_status(signal, status);
const equals = /** @type {import('./types.js').EqualsFunctions} */ (signal.e);
if (!equals(value, signal.v)) {

@ -263,6 +263,27 @@ describe('signals', () => {
};
});
let no_deps = $.derived(() => {
return [];
});
test('two effects with an unowned derived that has no depedencies', () => {
const log: Array<Array<any>> = [];
$.render_effect(() => {
log.push($.get(no_deps));
});
$.render_effect(() => {
log.push($.get(no_deps));
});
return () => {
$.flushSync();
assert.deepEqual(log, [[], []]);
};
});
test('schedules rerun when writing to signal before reading it', (runes) => {
if (!runes) return () => {};

Loading…
Cancel
Save