Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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/rare-hounds-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: tweak effect self invalidation logic
17 changes: 15 additions & 2 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,28 @@ export function handle_error(error, effect, previous_effect, component_context)
* @param {Effect} effect
* @param {number} [depth]
*/
function schedule_possible_effect_self_invalidation(signal, effect, depth = 0) {
function schedule_possible_effect_self_invalidation(
signal,
effect,
depth = 0,
visited = new Set()
) {
var reactions = signal.reactions;
if (reactions === null) return;

for (var i = 0; i < reactions.length; i++) {
var reaction = reactions[i];
if (visited.has(reaction)) {
continue;
}
visited.add(reaction);

if ((reaction.f & DERIVED) !== 0) {
schedule_possible_effect_self_invalidation(
/** @type {Derived} */ (reaction),
effect,
depth + 1
depth + 1,
visited
);
} else if (effect === reaction) {
if (depth === 0) {
Expand Down Expand Up @@ -457,6 +468,8 @@ export function update_reaction(reaction) {
if (
is_runes() &&
untracked_writes !== null &&
!untracking &&
deps !== null &&
(reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0
) {
for (i = 0; i < /** @type {Source[]} */ (untracked_writes).length; i++) {
Expand Down