Skip to content

fix: cleanup each items in legacy mode #16141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Conversation

paoloricciuti
Copy link
Member

Closes #16040

Not really sure how to test this...i've also run the benchmark and it doesn't seem to be affected...also initially i've also removed the source from every reaction it had but i guess that's taken care by the key block/branch? This also lead me to believe that the memory leak is not really a memory leak and it would be cleaned up when the component it's unmounted but i guess for a situation like this one could still be good to clean the item immediately since it's not accessible in any way anymore.

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

@paoloricciuti
Copy link
Member Author

Uh i guess i should fix also the other two cases

Copy link

changeset-bot bot commented Jun 12, 2025

🦋 Changeset detected

Latest commit: 18fec5c

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

Copy link
Contributor

Playground

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

@paoloricciuti
Copy link
Member Author

Mmm this does make the example @7nik provided a looooot slower tho which is understandable since it's cleaning 1000 items everytime filtering the legacy array so maybe the benchmark did not capture this well enough?

Not sure if we should go ahead and merge this like this...my other idea was to just skip falsy values in the legacy, sources, array and just set the spot to null but i would also need a way to get back the index somehow.

@paoloricciuti
Copy link
Member Author

Uhm actually the fix for await might be wrong as differently from the each the source is reused when the then branch is recreated? Will check maybe tomorrow, it's late and I'm too tired for this now, I might mess up something

@paoloricciuti
Copy link
Member Author

Mmm this technically does work in svelte 4 but it doesn't in svelte 5 (not that anyone should do this)...and by that I mean that reactivity is completely broken.

<script>
	import {beforeUpdate} from "svelte";
	const promise = Promise.resolve({count: 0});

	beforeUpdate(()=>{
		console.log("before");
	});
</script>

{#await promise then thing}
	<button on:click={()=>thing.count++}>{thing.count}</button>
{/await}

@7nik
Copy link
Contributor

7nik commented Jun 13, 2025

I opened alternative #16145 - looks like there is no need to track these signals at all.

@Rich-Harris
Copy link
Member

closing in favour of #16145

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.

Key+each blocks leaking memory in legacy mode
3 participants