Skip to content

fix(svelte-virtual): force store update when setOptions is called#1143

Open
isaackaara wants to merge 1 commit intoTanStack:mainfrom
isaackaara:fix/svelte-setOptions-store-update
Open

fix(svelte-virtual): force store update when setOptions is called#1143
isaackaara wants to merge 1 commit intoTanStack:mainfrom
isaackaara:fix/svelte-setOptions-store-update

Conversation

@isaackaara
Copy link

When options like count change but the visible range stays the same, onChange never fires (it only fires on range changes via maybeNotify). This means the Svelte store is not updated, so the component doesn't re-render — even though the virtualizer has new items.

Reproduction: increase count while scrolled near the top of the list. The new items are never rendered because the range (e.g. 0–9) hasn't changed.

Fix: call virtualizerWritable.set(virtualizer) after _willUpdate() so the store is always refreshed when setOptions is called explicitly. Svelte treats same-reference objects as changed (due to safe_not_equal returning true for objects), so this correctly triggers a re-render.

This mirrors what vue-virtual already does: it calls triggerRef(state) after _willUpdate() for the same reason.

Fixes #969

When options like `count` change but the visible range stays the same,
`onChange` is never called (it only fires on range changes). This means
the Svelte store is not updated and the component does not re-render.

Fix by calling `virtualizerWritable.set(virtualizer)` after _willUpdate()
so the store always reflects the latest virtualizer state after any
options change. This mirrors how vue-virtual uses `triggerRef(state)`
after _willUpdate().

Fixes TanStack#969
@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

⚠️ No Changeset found

Latest commit: 9051624

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

Svelte: setting count does not re-render correctly

1 participant