-
-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Listbox Virtualizer is not actually virtualizing the list #1288
Comments
Thanks for the ticket @wonderbeel . The I think updating docs should avoid this mistake right? 😁 |
Updating docs would be enough indeed, another option could be to try to solve it directly in the Let me know which solution sounds more reasonable to you guys and I will try to open a MR today or tomorrow. |
Can you share more info about the latter solution? 😁 |
My idea was something like this <script lang="ts">
export interface ListboxVirtualizerProps<T extends AcceptableValue = AcceptableValue> {
/** List of items */
options: T[]
/** Estimated size (in px) of each item */
estimateSize?: number
/** text content for each item to achieve type-ahead feature */
textContent?: (option: T) => string
/** Number of visible items **/
visibleItems?: number
}
</script>
<script setup lang="ts" generic="T extends AcceptableValue = AcceptableValue">
...
const visibleItems = computed(() => props.visibleItems ?? 10)
const estimateSize = computed() => props.estimateSize ?? 28)
...
</script>
<template>
<div :style="{ height: `${estimateSize * visibleItems}px`, width: '100%', position: 'relative', overflow: 'auto' }">
<div
data-radix-vue-virtualizer
:style="{
position: 'relative',
width: '100%',
height: `${virtualizer.getTotalSize()}px`,
}"
>
<component
:is="is"
v-for="{ is, item } in virtualizedItems"
:key="item.index"
/>
</div>
</div>
</template> (haven't tested it just a thing that I wrote on the fly looking at the component code) |
Thanks for the example @wonderbeel ! However since the |
Added some docs on v2, can you help check and see if it make sense? 😁 |
Hey @zernonia let me apologize actually, I wanted to open a PR for that but between COVID and other personal stuff I didn't find time to do it. |
Environment
Link to minimal reproduction
https://stackblitz.com/~/github.com/wonderbeel/listbox-virtualizer-reproduction
Steps to reproduce
Open the reproduction and look at the number of items rendered in the virtual lists on the right (or with the browser inspector)
Describe the bug
We noticed that a component in our codebase was extremely slow despite using the virtualizer, as if it were not actually virtualizing the list: upon investigation, it was confirmed that this was indeed the case.
Digging into the Radix Vue codebase, it seems that a height is provided to the virtualizer (see Radix Vue ListboxVirtualizer.vue); however, looking at the TanStack virtual example, they also provide a fixed height to the element that wraps the virtualizer itself (see TanStack RowVirtualizerFixed.vue), also their documentation always explicitly mentions this requirement (see TanStack Virtual Documentation) whereas Radix does not mention it at all (see Radix Vue Listbox Documentation).
I am not sure if this is truly a bug because if we set a height on
ListboxContent
orListboxGroup
the virtualizer works as expected; however, there is no explanation of this in the documentation so in my opinion we have two potential fixes:Let me know if you have other questions or need extra details 😃 .
Expected behavior
Listbox virtualizer should render 10~20 items not 1000
Context & Screenshots (if applicable)
No response
The text was updated successfully, but these errors were encountered: