fix(svelte-virtual): force store update when setOptions is called#1143
Conversation
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 detectedLatest commit: cbdf629 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 |
|
View your CI Pipeline Execution ↗ for commit cbdf629
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where Svelte virtual lists would not re-render when count changes but the visible range stays the same (e.g., the user is scrolled near the top). The fix forces a Svelte store update after _willUpdate() in setOptions, ensuring the component re-renders even when onChange doesn't fire.
Changes:
- Added
virtualizerWritable.set(virtualizer)after_willUpdate()insetOptionsto force a store update, mirroring howvue-virtualusestriggerRef(state)in the same scenario.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When options like
countchange but the visible range stays the same,onChangenever fires (it only fires on range changes viamaybeNotify). This means the Svelte store is not updated, so the component doesn't re-render — even though the virtualizer has new items.Reproduction: increase
countwhile 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 whensetOptionsis called explicitly. Svelte treats same-reference objects as changed (due tosafe_not_equalreturningtruefor objects), so this correctly triggers a re-render.This mirrors what
vue-virtualalready does: it callstriggerRef(state)after_willUpdate()for the same reason.Fixes #969