@@ -336,16 +336,6 @@ function reconcile_tracked_array(array, each_block, anchor, render_fn, flags, ke
336
336
/** @type {Array<import('#client').EachItemBlock> } */
337
337
var to_destroy = [ ] ;
338
338
339
- /** @type {Array<import('#client').EachItemBlock> } */
340
- var to_animate = [ ] ;
341
-
342
- if ( is_animated ) {
343
- for ( block of a_blocks ) {
344
- // TODO can we avoid measuring blocks that will be destroyed?
345
- block . a ?. measure ( ) ;
346
- }
347
- }
348
-
349
339
// Step 1 — trim common suffix
350
340
while ( a > 0 && b > 0 && a_blocks [ a - 1 ] . k === keys [ b - 1 ] ) {
351
341
block = b_blocks [ -- b ] = a_blocks [ -- a ] ;
@@ -400,6 +390,21 @@ function reconcile_tracked_array(array, each_block, anchor, render_fn, flags, ke
400
390
map_set ( indexes , keys [ i ] , i ) ;
401
391
}
402
392
393
+ /** @type {Array<import('#client').EachItemBlock> } */
394
+ var to_animate = [ ] ;
395
+ if ( is_animated ) {
396
+ // for all blocks that were in both the old and the new list,
397
+ // measure them and store them in `to_animate` so we can
398
+ // apply animations once the DOM has been updated
399
+ for ( i = 0 ; i < a_blocks . length ; i += 1 ) {
400
+ block = a_blocks [ i ] ;
401
+ if ( indexes . has ( block . k ) ) {
402
+ block . a ?. measure ( ) ;
403
+ to_animate . push ( block ) ;
404
+ }
405
+ }
406
+ }
407
+
403
408
// populate the `sources` array for each old block with
404
409
// its new index, so that we can calculate moves
405
410
for ( i = start ; i < a ; i += 1 ) {
@@ -437,7 +442,7 @@ function reconcile_tracked_array(array, each_block, anchor, render_fn, flags, ke
437
442
block = create_block ( array [ b ] , keys [ b ] , b , render_fn , flags ) ;
438
443
} else {
439
444
block = b_blocks [ b ] ;
440
- if ( ! is_animated && should_update ) {
445
+ if ( should_update ) {
441
446
update_block ( block , array [ b ] , b , flags ) ;
442
447
}
443
448
}
@@ -449,16 +454,16 @@ function reconcile_tracked_array(array, each_block, anchor, render_fn, flags, ke
449
454
450
455
last_block = b_blocks [ b ] = block ;
451
456
}
452
- }
453
457
454
- if ( to_animate . length > 0 ) {
455
- user_effect ( ( ) => {
456
- untrack ( ( ) => {
457
- for ( block of to_animate ) {
458
- block . a ?. apply ( ) ;
459
- }
458
+ if ( to_animate . length > 0 ) {
459
+ user_effect ( ( ) => {
460
+ untrack ( ( ) => {
461
+ for ( block of to_animate ) {
462
+ block . a ?. apply ( ) ;
463
+ }
464
+ } ) ;
460
465
} ) ;
461
- } ) ;
466
+ }
462
467
}
463
468
464
469
var remaining = to_destroy . length ;
0 commit comments