Skip to content

Conversation

@Refzlund
Copy link
Owner

@Refzlund Refzlund commented Nov 26, 2025

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.Object with 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.svelte

  • Changed prescriptors from $state([]) to $state.raw([]). This prevents deep proxy tracking and avoids proxy equality issues when using indexOf/findIndex.

  • Added $effect.root() for individual prescriptor effects. Each prescriptor now creates its own effect scope via createPrescriptorEffects(), which returns a cleanup function. This allows proper cleanup when the prescriptor is removed.

  • Added removed flag 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:

    1. Sets prescriptor.removed = true
    2. Calls the effect cleanup function
    3. Filters the prescriptor from the array (instead of using splice)
  • Stored and called the parent's removePrescriptor cleanup. The component now properly removes itself from its parent when destroyed via onDestroy.

  • Fixed return type of addPrescriptor in type definition. Changed from void to () => void.

Root Cause

The previous implementation created effects inside a single $effect.pre() that iterated over all prescriptors. When a prescriptor was removed via splice, 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.

- 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-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: fae17cf

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

This PR includes changesets to release 1 package
Name Type
svelte-object 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

@Refzlund Refzlund merged commit 1986e34 into master Nov 26, 2025
1 check passed
@Refzlund Refzlund deleted the fix-prescriptor-effect-cleanup branch November 26, 2025 13:40
@github-actions github-actions bot mentioned this pull request Nov 26, 2025
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.

bug: array item removal doesn't work when using I.Object name={index} inside {#each} with children snippet

1 participant