Skip to content

fix: prevent batch unlinking twice#18303

Merged
Rich-Harris merged 1 commit into
mainfrom
batch-unlink-twice-fix
May 27, 2026
Merged

fix: prevent batch unlinking twice#18303
Rich-Harris merged 1 commit into
mainfrom
batch-unlink-twice-fix

Conversation

@dummdidumm

@dummdidumm dummdidumm commented May 27, 2026

Copy link
Copy Markdown
Member

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.

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.
@changeset-bot

changeset-bot Bot commented May 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0657c85

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@18303

@Rich-Harris Rich-Harris merged commit 638ab37 into main May 27, 2026
21 checks passed
@Rich-Harris Rich-Harris deleted the batch-unlink-twice-fix branch May 27, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants