Skip to content

Commit 5d6b755

Browse files
committed
belts and braces
1 parent 0ee1d56 commit 5d6b755

File tree

1 file changed

+7
-5
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+7
-5
lines changed

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,16 @@ export class Batch {
231231
if (this.#async_effects.length === 0 && this.#pending === 0) {
232232
if (superseeded_batches.length > 0) {
233233
const own = [...this.#callbacks.keys()].map((c) => c());
234-
for (const batch of superseeded_batches) {
235-
// A superseeded batch could have callbacks for e.g. destroying if blocks
236-
// that are not part of the current batch because it already happened in the prior one,
237-
// and the corresponding block effect therefore returning early because nothing was changed from its
238-
// point of view, therefore not adding a callback to the current batch, so we gotta call them here.
234+
// A superseeded batch could have callbacks for e.g. destroying if blocks
235+
// that are not part of the current batch because it already happened in the prior one,
236+
// and the corresponding block effect therefore returning early because nothing was changed from its
237+
// point of view, therefore not adding a callback to the current batch, so we gotta call them here.
238+
// We do it from newest to oldest to ensure the correct callback is applied.
239+
for (const batch of superseeded_batches.reverse()) {
239240
for (const [effect, cb] of batch.#callbacks) {
240241
if (!own.includes(effect())) {
241242
cb();
243+
own.push(effect());
242244
}
243245
}
244246
batch.remove();

0 commit comments

Comments
 (0)