fix: prescriptor effects not properly cleaned up on removal #39
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.
Summary
Fixes #38 — an issue where prescriptor effects were not being properly cleaned up when a prescriptor was removed. This caused problems when using
I.Objectwith array indices as names inside{#each}loops - removed items would "reappear" because the prescriptor's cached value would be written back to the array.Changes
SvelteObject.svelteChanged
prescriptorsfrom$state([])to$state.raw([]). This prevents deep proxy tracking and avoids proxy equality issues when usingindexOf/findIndex.Added
$effect.root()for individual prescriptor effects. Each prescriptor now creates its own effect scope viacreatePrescriptorEffects(), which returns a cleanup function. This allows proper cleanup when the prescriptor is removed.Added
removedflag to prescriptors. Effects now check this flag and bail out early if the prescriptor has been removed, preventing stale writes.Fixed the cleanup function returned by
addPrescriptor. It now:prescriptor.removed = truesplice)Stored and called the parent's
removePrescriptorcleanup. The component now properly removes itself from its parent when destroyed viaonDestroy.Fixed return type of
addPrescriptorin type definition. Changed fromvoidto() => void.Root Cause
The previous implementation created effects inside a single
$effect.pre()that iterated over all prescriptors. When a prescriptor was removed viasplice, the effect would continue running for the removed prescriptor until the next full re-run, causing stale values to be written back.Testing
Manual testing with the array item removal story shows that items are now properly removed without reappearing.