we don't need this logic anymore; switch oder of current/previous in update_derived so current batch has correct previous value

async-another-try-pt-3
Simon Holthausen 1 day ago
parent 08abbd3c96
commit 61f58a5566
No known key found for this signature in database

@ -654,26 +654,10 @@ export class Batch {
var next_batch = /** @type {Batch | null} */ (/** @type {unknown} */ (current_batch)); var next_batch = /** @type {Batch | null} */ (/** @type {unknown} */ (current_batch));
if (this.#pending === 0 && (this.#scheduled.length === 0 || next_batch !== null)) { if (this.#pending === 0) {
this.#unlink(); this.#unlink();
} }
// Edge case: During traversal new branches might create effects that run immediately and set state,
// causing an effect to be scheduled again. We need to traverse the current batch
// once more in that case - most of the time this will just clean up dirty branches.
// TODO I think we can delete this now since we re-iterate above
if (this.#scheduled.length > 0) {
if (next_batch !== null) {
for (const e of this.#scheduled) {
next_batch.#scheduled.push(e);
}
this.#scheduled = [];
} else {
next_batch = this;
}
}
if (next_batch !== null) { if (next_batch !== null) {
old_values.clear(); old_values.clear();
next_batch.#process(); next_batch.#process();

@ -436,8 +436,9 @@ export function update_derived(derived) {
// to the previous batch, not the new one (which can already exist if an earlier // to the previous batch, not the new one (which can already exist if an earlier
// effect wrote to a source). Not adding it to either can cause bugs, so we add it to both. // effect wrote to a source). Not adding it to either can cause bugs, so we add it to both.
// See https://github.com/sveltejs/svelte/pull/18117 for more details. // See https://github.com/sveltejs/svelte/pull/18117 for more details.
previous_batch?.capture(derived, value, true); // Order matters: current_batch first so it gets the correct previous value.
current_batch?.capture(derived, value, true); current_batch?.capture(derived, value, true);
previous_batch?.capture(derived, value, true, current_batch !== null);
} else { } else {
derived.v = value; derived.v = value;
derived.wv = increment_write_version(); derived.wv = increment_write_version();

Loading…
Cancel
Save