Skip to content

Commit a63c984

Browse files
committed
fix: maintain reactivity for properties of deriveds with no deps
fixes #17111, fixes #17352
1 parent 2cd6ddf commit a63c984

File tree

1 file changed

+8
-1
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ export function update_derived(derived) {
360360
// the underlying value will be updated when the fork is committed.
361361
// otherwise, the next time we get here after a 'real world' state
362362
// change, `derived.equals` may incorrectly return `true`
363-
if (!current_batch?.is_fork) {
363+
// Exception: deriveds with no deps should always update `derived.v`
364+
// since they will never change and need the value after fork commits
365+
if (!current_batch?.is_fork || derived.deps === null) {
364366
derived.v = value;
365367
}
366368

@@ -381,6 +383,11 @@ export function update_derived(derived) {
381383
if (effect_tracking() || current_batch?.is_fork) {
382384
batch_values.set(derived, value);
383385
}
386+
// For deriveds with no deps, set CLEAN to prevent re-evaluation
387+
// since they can never become dirty from dependency changes
388+
if (derived.deps === null) {
389+
set_signal_status(derived, CLEAN);
390+
}
384391
} else {
385392
var status = (derived.f & CONNECTED) === 0 ? MAYBE_DIRTY : CLEAN;
386393
set_signal_status(derived, status);

0 commit comments

Comments
 (0)