Skip to content

Commit 303f24e

Browse files
committed
fix: ensure unowned derived dependencies are not duplicated when reactions are skipped
1 parent b0c4fa5 commit 303f24e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

.changeset/stale-keys-taste.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: ensure unowned derived dependencies are not duplicated when reactions are skipped

packages/svelte/src/internal/client/runtime.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,9 @@ export function update_reaction(reaction) {
404404
skipped_deps = 0;
405405
untracked_writes = null;
406406
active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
407-
// prettier-ignore
408407
skip_reaction =
409408
(flags & UNOWNED) !== 0 &&
410-
(!is_flushing_effect ||
411-
// If we were previously not in a reactive context and we're reading an unowned derived
412-
// that was created inside another reaction, then we don't fully know the real owner and thus
413-
// we need to skip adding any reactions for this unowned
414-
((previous_reaction === null || previous_untracking) &&
415-
/** @type {Derived} */ (reaction).parent !== null));
409+
(!is_flushing_effect || previous_reaction === null || previous_untracking);
416410

417411
derived_sources = null;
418412
set_component_context(reaction.ctx);
@@ -933,7 +927,10 @@ export function get(signal) {
933927
skipped_deps++;
934928
} else if (new_deps === null) {
935929
new_deps = [signal];
936-
} else {
930+
} else if (!skip_reaction || !new_deps.includes(signal)) {
931+
// Normally we can push duplicated dependencies to `new_deps`, but if we're inside
932+
// an unowned derived because skip_reaction is true, then we need to ensure that
933+
// we don't have duplicates
937934
new_deps.push(signal);
938935
}
939936
}

0 commit comments

Comments
 (0)