diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index eede5097f7..b75b629f57 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -524,19 +524,46 @@ export class Batch { } apply() { + if (!batches.has(this)) { + console.warn('wtf', this.id); + } + if (!async_mode_flag || (!this.is_fork && batches.size === 1)) return; + console.log(this.id, batches.size); + // if there are multiple batches, we are 'time travelling' — // we need to override values with the ones in this batch... batch_values = new Map(this.current); + var is_earlier = true; + // ...and undo changes belonging to other batches + // that don't coincide with this batch for (const batch of batches) { - if (batch === this) continue; + if (batch === this) { + is_earlier = false; + continue; + } + + var coincides = false; - for (const [source, previous] of batch.previous) { - if (!batch_values.has(source)) { - batch_values.set(source, previous); + if (is_earlier) { + for (const source of batch.current.keys()) { + if (this.current.has(source)) { + coincides = true; + break; + } + } + } + + console.log(batch.id, { coincides }); + + if (!coincides) { + for (const [source, previous] of batch.previous) { + if (!batch_values.has(source)) { + batch_values.set(source, previous); + } } } }