Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vast-ties-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: null out current_batch before committing branches
9 changes: 5 additions & 4 deletions packages/svelte/src/internal/client/dom/blocks/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export class BranchManager {
this.#transition = transition;
}

#commit = () => {
var batch = /** @type {Batch} */ (current_batch);

/**
* @param {Batch} batch
*/
#commit = (batch) => {
// if this batch was made obsolete, bail
if (!this.#batches.has(batch)) return;

Expand Down Expand Up @@ -221,7 +222,7 @@ export class BranchManager {
this.anchor = hydrate_node;
}

this.#commit();
this.#commit(batch);
}
}
}
19 changes: 10 additions & 9 deletions packages/svelte/src/internal/client/reactivity/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Batch {
/**
* When the batch is committed (and the DOM is updated), we need to remove old branches
* and append new ones by calling the functions added inside (if/each/key/etc) blocks
* @type {Set<() => void>}
* @type {Set<(batch: Batch) => void>}
*/
#commit_callbacks = new Set();

Expand Down Expand Up @@ -207,19 +207,19 @@ export class Batch {
reset_branch(e, t);
}
} else {
// If sources are written to, then work needs to happen in a separate batch, else prior sources would be mixed with
// newly updated sources, which could lead to infinite loops when effects run over and over again.
previous_batch = this;
current_batch = null;

// append/remove branches
for (const fn of this.#commit_callbacks) fn();
for (const fn of this.#commit_callbacks) fn(this);
this.#commit_callbacks.clear();

if (this.#pending === 0) {
this.#commit();
}

// If sources are written to, then work needs to happen in a separate batch, else prior sources would be mixed with
// newly updated sources, which could lead to infinite loops when effects run over and over again.
previous_batch = this;
current_batch = null;

flush_queued_effects(render_effects);
flush_queued_effects(effects);

Expand Down Expand Up @@ -358,6 +358,7 @@ export class Batch {
if (batches.size > 1) {
this.previous.clear();

var previous_batch = current_batch;
var previous_batch_values = batch_values;
var is_earlier = true;

Expand Down Expand Up @@ -421,7 +422,7 @@ export class Batch {
}
}

current_batch = null;
current_batch = previous_batch;
batch_values = previous_batch_values;
}

Expand Down Expand Up @@ -479,7 +480,7 @@ export class Batch {
this.flush();
}

/** @param {() => void} fn */
/** @param {(batch: Batch) => void} fn */
oncommit(fn) {
this.#commit_callbacks.add(fn);
}
Expand Down
Loading