fix: read batch-local array on each-block commit (#18879)

Another extraction from #18861 which I'm pretty sure you can also
construct a buggy reproduction for today, but with #18861 it's strictly
necessary so we don't need to come up with one now
pull/18871/merge
Simon H 1 day ago committed by GitHub
parent 58297c5a73
commit da2f83343b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: read batch-local array on each-block commit

@ -216,9 +216,6 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
tag(each_array, '{#each ...}');
}
/** @type {V[]} */
var array;
/** @type {Map<Batch, Set<any>>} */
var pending = new Map();
@ -234,6 +231,11 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
state.pending.delete(batch);
// The effect doesn't necessarily re-run in a batch right before that batch commits
// (its view of the collection may not have changed), so we read the collection
// as the committing batch sees it rather than using the most recent block run's result
var array = get(each_array);
state.fallback = fallback;
reconcile(state, array, anchor, flags, get_key);
@ -264,7 +266,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
}
var effect = block(() => {
array = /** @type {V[]} */ (get(each_array));
var array = /** @type {V[]} */ (get(each_array));
var length = array.length;
/** `true` if there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */

Loading…
Cancel
Save