Skip to content

Commit 9dafb2c

Browse files
committed
fix: ensure each block inert items are disposed of if the each block is also inert
1 parent feb2d85 commit 9dafb2c

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.changeset/curly-dogs-breathe.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 each block inert items are disposed of if the each block is also inert

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { source, mutable_source, internal_set } from '../../reactivity/sources.j
3535
import { array_from, is_array } from '../../../shared/utils.js';
3636
import { INERT } from '../../constants.js';
3737
import { queue_micro_task } from '../task.js';
38-
import { active_effect } from '../../runtime.js';
38+
import { active_effect, active_reaction } from '../../runtime.js';
3939

4040
/**
4141
* The row of a keyed each block that is currently updating. We track this
@@ -204,7 +204,8 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
204204
}
205205

206206
if (!hydrating) {
207-
reconcile(array, state, anchor, render_fn, flags, get_key);
207+
var is_inert = /** @type {Effect} */ (active_reaction.f & INERT) !== 0;
208+
reconcile(array, state, anchor, render_fn, flags, is_inert, get_key);
208209
}
209210

210211
if (fallback_fn !== null) {
@@ -248,10 +249,11 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
248249
* @param {Element | Comment | Text} anchor
249250
* @param {(anchor: Node, item: MaybeSource<V>, index: number | Source<number>) => void} render_fn
250251
* @param {number} flags
252+
* @param {boolean} is_inert
251253
* @param {(value: V, index: number) => any} get_key
252254
* @returns {void}
253255
*/
254-
function reconcile(array, state, anchor, render_fn, flags, get_key) {
256+
function reconcile(array, state, anchor, render_fn, flags, is_inert, get_key) {
255257
var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
256258
var should_update = (flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0;
257259

@@ -390,9 +392,9 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
390392
stashed = [];
391393

392394
while (current !== null && current.k !== key) {
393-
// If the item has an effect that is already inert, skip over adding it
394-
// to our seen Set as the item is already being handled
395-
if ((current.e.f & INERT) === 0) {
395+
// If the each block isn't inert and an item has an effect that is already inert,
396+
// skip over adding it to our seen Set as the item is already being handled
397+
if (is_inert || (current.e.f & INERT) === 0) {
396398
(seen ??= new Set()).add(current);
397399
}
398400
stashed.push(current);
@@ -415,8 +417,9 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
415417
var to_destroy = seen === undefined ? [] : array_from(seen);
416418

417419
while (current !== null) {
418-
// Inert effects are currently outroing and will be removed once the transition is finished
419-
if ((current.e.f & INERT) === 0) {
420+
// If the each block isn't inert, then item effects that are inert means they are currently
421+
// already outroing and will be removed once the transition is finished
422+
if (is_inert || (current.e.f & INERT) === 0) {
420423
to_destroy.push(current);
421424
}
422425
current = current.next;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,15 @@ export function resume_effect(effect) {
574574
*/
575575
function resume_children(effect, local) {
576576
if ((effect.f & INERT) === 0) return;
577-
effect.f ^= INERT;
578577

579578
// If a dependency of this effect changed while it was paused,
580579
// apply the change now
581580
if (check_dirtiness(effect)) {
582581
update_effect(effect);
583582
}
584583

584+
effect.f ^= INERT;
585+
585586
var child = effect.first;
586587

587588
while (child !== null) {

0 commit comments

Comments
 (0)