Skip to content

fix: each block breaking with effects interspersed among items#17550

Merged
Rich-Harris merged 6 commits intosveltejs:mainfrom
hmnd:push-tnqrozrlkxxn
Jan 27, 2026
Merged

fix: each block breaking with effects interspersed among items#17550
Rich-Harris merged 6 commits intosveltejs:mainfrom
hmnd:push-tnqrozrlkxxn

Conversation

@hmnd
Copy link
Copy Markdown
Contributor

@hmnd hmnd commented Jan 26, 2026

fixes #17433

Alternative to #17541. The single advance at the start of the loop in #17541 (comment) fixes the sample in that pr, but effects could be interspersed elsewhere among the block's items. Since current gets advanced several more times further down, it can still result in a freeze with a sample like the one I've added here.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 26, 2026

🦋 Changeset detected

Latest commit: 3a73842

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions
Copy link
Copy Markdown
Contributor

Playground

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

Comment thread packages/svelte/src/internal/client/dom/blocks/each.js Outdated
@hmnd
Copy link
Copy Markdown
Contributor Author

hmnd commented Jan 26, 2026

Hmm I changed the example to use $effect.pre instead of create subscriber. It not only fails against main, but also causes the tests following it to fail as well. Does that suggest the $effect.pre isn't getting cleaned up on destroy correctly?

@Rich-Harris
Copy link
Copy Markdown
Member

err.... hmm. certainly sounds that way. hypothesis (with no evidence): the linked list is somehow getting broken, such that destroying the each block doesn't cause all the child effects to be destroyed

@hmnd
Copy link
Copy Markdown
Contributor Author

hmnd commented Jan 26, 2026

Oh that happens with either effect.pre or createsubscriber... Maybe something like #17541 is needed for both?

@hmnd
Copy link
Copy Markdown
Contributor Author

hmnd commented Jan 27, 2026

I think you're right, but on second thought, it's likely not a real concern after this pr. I think I was seeing it break other tests because the crash happens midway through reconciliation which messes with the linked list globally. Then because tests run in the same process, they would start off with a corrupt effect tree and break again, etc.

I was worried skipping non branch effects within each's process would mess with them getting cleaned up but that's taken care of further upstream in effect handling.

Copy link
Copy Markdown
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris Rich-Harris merged commit 02b5d94 into sveltejs:main Jan 27, 2026
14 checks passed
@github-actions github-actions Bot mentioned this pull request Jan 27, 2026
@hmnd hmnd deleted the push-tnqrozrlkxxn branch January 28, 2026 05:44
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.

Possible regression from #17258: {#each} null ref after push() on Proxy array (Svelte 5.45.5+)

2 participants