@@ -35,8 +35,9 @@ import { source, mutable_source, internal_set } from '../../reactivity/sources.j
3535import { array_from , is_array } from '../../../shared/utils.js' ;
3636import { INERT } from '../../constants.js' ;
3737import { queue_micro_task } from '../task.js' ;
38- import { active_effect , active_reaction } from '../../runtime.js' ;
38+ import { active_effect , active_reaction , get } from '../../runtime.js' ;
3939import { DEV } from 'esm-env' ;
40+ import { derived_safe_equal } from '../../reactivity/deriveds.js' ;
4041
4142/**
4243 * The row of a keyed each block that is currently updating. We track this
@@ -135,15 +136,17 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
135136
136137 var was_empty = false ;
137138
138- block ( ( ) => {
139+ // TODO: ideally we could use derived for runes mode but because of the ability
140+ // to use a store which can be mutated, we can't do that here as mutating a store
141+ // will still result in the collection array being the same from the store
142+ var each_array = derived_safe_equal ( ( ) => {
139143 var collection = get_collection ( ) ;
140144
141- var array = is_array ( collection )
142- ? collection
143- : collection == null
144- ? [ ]
145- : array_from ( collection ) ;
145+ return is_array ( collection ) ? collection : collection == null ? [ ] : array_from ( collection ) ;
146+ } ) ;
146147
148+ block ( ( ) => {
149+ var array = get ( each_array ) ;
147150 var length = array . length ;
148151
149152 if ( was_empty && length === 0 ) {
@@ -254,7 +257,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
254257 // that a mutation occurred and it's made the collection MAYBE_DIRTY, so reading the
255258 // collection again can provide consistency to the reactive graph again as the deriveds
256259 // will now be `CLEAN`.
257- get_collection ( ) ;
260+ get ( each_array ) ;
258261 } ) ;
259262
260263 if ( hydrating ) {
0 commit comments