SIGN IN SIGN UP
sveltejs / svelte UNCLAIMED

web development for the rest of us

0 0 70 JavaScript

fix: prevent batch unlinking twice (#18303)

Merged #18298 a bit too soon - there's still a situation which can
corrput the linked list: If we merge one batch into another, it will
unlink the batch immediately. But `discard` also calls it, running the
unlink logic again, which can corrupt the linked list.

Sketch:

1. Batch A is pending.
2. Batch B starts later, intersects A, resolves first, and merges into
A.
3. B is unlinked immediately, but `A.oncommit(() => B.discard())`
remains.
4. Independent batch C is created while A is still pending and is linked
after A.
5. A commits, calls `B.discard()`, and B's stale `#prev`/`#next` can set
`A.#next = null` / `last_batch = A`, disconnecting C.

Not able to produce a failing test from it but it's definitely a fix we
need to make.

Also moved `#link` into a constructor, because it is (and should be)
used only once.

Also made the action after an error `discard` instead of just `#unlink`
because this batch is done for and e.g. pending `settled` should
resolve, too.
S
Simon H committed
638ab370a561f97552229589f2f334655426fe5c
Parent: 0da9f9e
Committed by GitHub <noreply@github.com> on 5/27/2026, 8:52:40 PM