Solid: Virtualizer does not render any rows when using Suspense
Describe the bug
When using <Suspense> in solid-js with TanStack virtual, the virtualizer never renders any rows once the async data is resolved. The virtualizer receives the "count" of the data and appears to hold the data in the virtualizer, but the virtualizer never returns any rows.
I have tried a few other variations with using a signal for the ref and/or using queueMicrotask (from https://github.com/TanStack/virtual/pull/790), but neither resolves this.
I have reproduced this issue below using a variation of the Dynamic Solid example from https://github.com/TanStack/virtual/pull/658.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/admiring-smoke-s3klk5
Steps to reproduce
- View the Synchronous List and see the virtualizer is working as expected.
- View the Async List and see the virtualizer never displays any rows.
Expected behavior
The async list should render the rows once suspense is resolved.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: Windows 10
- Browser: Google Chrome
- Version 136.0.7103.116 (Official Build) (64-bit)
tanstack-virtual version
3.13.9
TypeScript version
5.8.3
Additional context
In my project, I am using TanStack Query to retrieve the data, TanStack Router for routing, and TanStack Table to display the data. In the example, I am not using any of these for simplicity, and the problem persists.
Terms & Code of Conduct
- [x] I agree to follow this project's Code of Conduct
- [x] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
I had exactly the same issue with getVirtualItems returning an empty array for data that was fetched asynchronously, which I thought was the reason. But apparently the issue was with a short delay for setting up parentRef. In my specific use-case it was even funnier, because I tried using virtualised inside a dropdown component with having parentRef attached to a div that was not initially displayed (for closed dropdown 😅).
My fix was to "re-initiate" virtualizer on dropdown open, by calling measure method. I also found that there were _didMount and _willUpdate methods that most likely would do the same trick, but decided not to use then as they are marked private.
onOpenChange={(open) => {
if (open) {
virtualizer.measure();
}
}}
Not sure if it helps with your specific case, but just wanted to highlight that having parentRef properly attached to a DOM element seems to have big impact
Was this resolved? I am sitting with a similar issue. I am fetching the list async and it is clear that the items are actually inside the dropdown component, but when I click on the dropdown it is empty. When I close the dropdown it shows all the data for a split second before it closes. I am also able to see the data in the dropdown if I refresh the page and quickly click on the dropdown. I have spent hours today trying to resolve this, but I have had no luck.
@HaleyBoles @JSEvgeny @BuiltByPhillip Not yet resolved, unfortunately. If anyone has time to review this with the Solid adapter, that would be super helpful.
I had simular issue. I separated the scroller component from the other virtualizer logic. // VirtualList
//Scroller export function Scroller({ children, ref, }: { children: React.ReactNode; ref: React.RefObject<HTMLDivElement | null>; }) { return ( <div className="w-full h-full overflow-auto" ref={ref}> {children} ); }
In my keys this works
useEffect(() => { rowVirtualizer.measure(); }, []);
In getScrollElement function check if element is connected to the DOM before returning it
getScrollElement: () => {
if (!props.tableContainerRef?.isConnected) {
return null;
}
return props.tableContainerRef
}