Skip to content
Source
Sign inSign up
TanStack/virtual

fix(svelte-virtual): read a scroll element bound after the store subscribes #1368

Openclean99(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1368/headopened

Showing 3 changed files with 48 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/bound-rows-render.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/svelte-virtual': patch
+---
+​
+Read the scroll element again after Svelte updates the DOM, so a virtualizer whose scroll element is assigned with `bind:this` after the store is subscribed renders its rows.
12 additions and 1 deletionpackages/svelte-virtual/src/index.tsModified
View file
@@ -7,6 +7,7 @@
observeWindowRect,
windowScroll,
} from '@tanstack/virtual-core'
+import { tick } from 'svelte'
import { derived, writable } from 'svelte/store'
import type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'
import type { Readable, Writable } from 'svelte/store'
@@ -64,7 +65,17 @@
​
virtualizerWritable = writable(virtualizer, () => {
setOptions({})
- return virtualizer._didMount()
+ let subscribed = true
+ // The store is usually subscribed before `bind:this` assigns the scroll
+ // element, so read it again once Svelte has updated the DOM.
+ tick().then(() => {
+ if (subscribed) virtualizer._willUpdate()
+ })
+ const cleanup = virtualizer._didMount()