Skip to content

Svelte Virtualizer does not observe scrollRef assigned after onMount #690

@Lechros

Description

@Lechros

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

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions