Skip to content

Commit ef2d378

Browse files
authored
chore: tweak each block runtime logic (#11862)
* chore: tweak each block runtime logic
1 parent fb57c20 commit ef2d378

File tree

1 file changed

+20
-17
lines changed
  • packages/svelte/src/internal/client/dom/blocks

1 file changed

+20
-17
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,31 +394,34 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
394394

395395
const to_destroy = Array.from(seen);
396396

397-
while (current) {
397+
while (current !== null) {
398398
to_destroy.push(current);
399399
current = current.next;
400400
}
401+
var destroy_length = to_destroy.length;
401402

402-
var controlled_anchor = (flags & EACH_IS_CONTROLLED) !== 0 && length === 0 ? anchor : null;
403+
if (destroy_length > 0) {
404+
var controlled_anchor = (flags & EACH_IS_CONTROLLED) !== 0 && length === 0 ? anchor : null;
403405

404-
if (is_animated) {
405-
for (i = 0; i < to_destroy.length; i += 1) {
406-
to_destroy[i].a?.measure();
407-
}
406+
if (is_animated) {
407+
for (i = 0; i < destroy_length; i += 1) {
408+
to_destroy[i].a?.measure();
409+
}
408410

409-
for (i = 0; i < to_destroy.length; i += 1) {
410-
to_destroy[i].a?.fix();
411+
for (i = 0; i < destroy_length; i += 1) {
412+
to_destroy[i].a?.fix();
413+
}
411414
}
412-
}
413415

414-
pause_effects(to_destroy, controlled_anchor, () => {
415-
for (var i = 0; i < to_destroy.length; i += 1) {
416-
var item = to_destroy[i];
417-
items.delete(item.k);
418-
item.o.remove();
419-
link(item.prev, item.next);
420-
}
421-
});
416+
pause_effects(to_destroy, controlled_anchor, () => {
417+
for (var i = 0; i < destroy_length; i += 1) {
418+
var item = to_destroy[i];
419+
items.delete(item.k);
420+
item.o.remove();
421+
link(item.prev, item.next);
422+
}
423+
});
424+
}
422425

423426
if (is_animated) {
424427
effect(() => {

0 commit comments

Comments
 (0)