From 9051624486651081f52dc5d9291c0151f1f9210d Mon Sep 17 00:00:00 2001 From: Isaac Hunja Date: Wed, 11 Mar 2026 14:20:48 +0300 Subject: [PATCH] fix(svelte-virtual): force store update when setOptions is called 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 #969 --- packages/svelte-virtual/src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/svelte-virtual/src/index.ts b/packages/svelte-virtual/src/index.ts index f16aa03ce..1607d8c2c 100644 --- a/packages/svelte-virtual/src/index.ts +++ b/packages/svelte-virtual/src/index.ts @@ -53,6 +53,11 @@ function createVirtualizerBase< }, }) virtualizer._willUpdate() + // Force store update in case the range didn't change (e.g. count increased + // but scroll position stayed the same). Without this, the store only + // updates when onChange fires (on range change), so changes like a new + // count that don't shift the visible range would not trigger a re-render. + virtualizerWritable.set(virtualizer) } virtualizerWritable = writable(virtualizer, () => {