-
-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
Describe the bug
In the Svelte Virtualizer, if scrollRef
is assigned after onMount
(e.g. via bind:ref
from external components), the scroll container is not observed. This is because observation only happens once during onMount
.
To Reproduce
Pass scrollRef
to Virtualizer using bind:ref
Ref is set after onMount
Scroll container is not observed
Expected behavior
scrollRef
should be observed even if it's set after onMount
. Changing from onMount
to $effect
could ensure proper observation. Assuming that multiple calls to $observe
are safe, this would be a straightforward fix.
Platform:
- OS: Windows
- Browser: Chrome
- Version of this package: 0.41.3
- Version of framework: Svelte 5+
Additional context
virtua/src/svelte/Virtualizer.svelte
Lines 68 to 78 in 7518bbd
onMount(() => { | |
const assignRef = (scrollable: HTMLElement) => { | |
resizer.$observeRoot(scrollable); | |
scroller.$observe(scrollable); | |
}; | |
if (scrollRef) { | |
assignRef(scrollRef); | |
} else { | |
assignRef(containerRef!.parentElement!); | |
} | |
}); |
Let me know if a PR would be helpful—I'd be glad to make one.
Metadata
Metadata
Assignees
Labels
No labels