fix: cleanup non render effects created inside block effects #13586
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Svelte 5 rewrite
This closes #13573.
Needed note: i'm not familiar with the whole effects orchestration so this code is the result of debugging the cause + trying to fix the issue + debugging the bugs caused by the issue. This means there might be a far easier way to achieve the same thing that i missed. I tried to cleanup the code as much as possible but there might be a cleaner way to achieve the same thing (i will also try to look at this tomorrow with a fresh mind to see if i missed something stupid). In the meantime this could at least be used as a starting point to:
A small recap of the issue is: when updating effects children of
BLOCK_EFFECT
were never cleaned up. This usually it's not a problem because those are generally template effects that will either be handled by the block itself (withpause
andresume
) or cleaned up when the component unmounts. However if the user does something like the test that i've added they are creating an effect in the block which needs to be cleaned up. So my solution was to move the check to avoid cleaning upRENDER_EFFECT
's inside thedestroy_effect_children
while also adding the logic to keep the linked list up to date. I've also had to add aforce
parameter because if we are coming fromdestroy_effect
rather thanupdate_effect
we want to clean everything and i had to add a constant to differenciate betweenRENDER_EFFECT
andPRE_EFFECT
because otherwisePRE_EFFECTS
would not be cleaned up (originally they wereRENDER_EFFECTS
.I opted into still making
PRE_EFFECT
's also aRENDER_EFFECT
to avoid touching too much and i think it's probably fine like this.Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint