@@ -412,16 +412,25 @@ export default class EachBlockWrapper extends Wrapper {
412
412
? `@outro_and_destroy_block`
413
413
: `@destroy_block` ;
414
414
415
- block . chunks . update . push ( b `
416
- const ${ this . vars . each_block_value } = ${ snippet } ;
415
+ const all_dependencies = new Set ( this . block . dependencies ) ; // TODO should be dynamic deps only
416
+ this . node . expression . dynamic_dependencies ( ) . forEach ( ( dependency : string ) => {
417
+ all_dependencies . add ( dependency ) ;
418
+ } ) ;
417
419
418
- ${ this . block . has_outros && b `@group_outros();` }
419
- ${ this . node . has_animation && b `for (let #i = 0; #i < ${ view_length } ; #i += 1) ${ iterations } [#i].r();` }
420
- ${ this . renderer . options . dev && b `@validate_each_keys(#ctx, ${ this . vars . each_block_value } , ${ this . vars . get_each_context } , ${ get_key } );` }
421
- ${ iterations } = @update_keyed_each(${ iterations } , #dirty, ${ get_key } , ${ dynamic ? 1 : 0 } , #ctx, ${ this . vars . each_block_value } , ${ lookup } , ${ update_mount_node } , ${ destroy } , ${ create_each_block } , ${ update_anchor_node } , ${ this . vars . get_each_context } );
422
- ${ this . node . has_animation && b `for (let #i = 0; #i < ${ view_length } ; #i += 1) ${ iterations } [#i].a();` }
423
- ${ this . block . has_outros && b `@check_outros();` }
424
- ` ) ;
420
+ if ( all_dependencies . size ) {
421
+ block . chunks . update . push ( b `
422
+ if (${ block . renderer . dirty ( Array . from ( all_dependencies ) ) } ) {
423
+ const ${ this . vars . each_block_value } = ${ snippet } ;
424
+
425
+ ${ this . block . has_outros && b `@group_outros();` }
426
+ ${ this . node . has_animation && b `for (let #i = 0; #i < ${ view_length } ; #i += 1) ${ iterations } [#i].r();` }
427
+ ${ this . renderer . options . dev && b `@validate_each_keys(#ctx, ${ this . vars . each_block_value } , ${ this . vars . get_each_context } , ${ get_key } );` }
428
+ ${ iterations } = @update_keyed_each(${ iterations } , #dirty, ${ get_key } , ${ dynamic ? 1 : 0 } , #ctx, ${ this . vars . each_block_value } , ${ lookup } , ${ update_mount_node } , ${ destroy } , ${ create_each_block } , ${ update_anchor_node } , ${ this . vars . get_each_context } );
429
+ ${ this . node . has_animation && b `for (let #i = 0; #i < ${ view_length } ; #i += 1) ${ iterations } [#i].a();` }
430
+ ${ this . block . has_outros && b `@check_outros();` }
431
+ }
432
+ ` ) ;
433
+ }
425
434
426
435
if ( this . block . has_outros ) {
427
436
block . chunks . outro . push ( b `
0 commit comments