fix: prescriptor effects not properly cleaned up on removal#39
Merged
fix: prescriptor effects not properly cleaned up on removal#39
Conversation
- Created SvelteExample component with default props. - Added Storybook stories for SvelteExample. - Introduced a new MDX file for documentation of the Svelte example. - Updated dependencies in bun.lock and package.json to latest versions. - Implemented Tailwind CSS for styling in the new components. - Fixed issues with array item removal in SvelteObject and SvelteValue components. - Added a new story to demonstrate the array item removal issue and its solution. - Configured Svelte with Vite preprocess for better integration.
🦋 Changeset detectedLatest commit: fae17cf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.