From 37d270b21fb56810d7d433cce0ac2b50531bdf6b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 26 Feb 2026 15:58:38 -0500 Subject: [PATCH] WIP --- .../src/internal/client/reactivity/batch.js | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) 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); + } } } }