marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
5.31k stars 155 forks source link

improve: Virtualize mo.ui.multiselect to handle large lists #1654

Closed wasimsandhu closed 1 week ago

wasimsandhu commented 1 week ago

📝 Summary

Completes #588.

Screenshot 2024-06-20 at 12 42 22 AM

🔍 Description of Changes

Installed [react-virtuoso](https://github.com/petyosi/react-virtuoso) and passed <Virtuoso /> to <Combobox />.

Because cmdk does not support filtering with virtualization, I used the existing filter function in MultiselectPlugin.tsx to filter the options array directly.

📋 Checklist

📜 Reviewers

@mscolnick

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 21, 2024 2:24am
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 21, 2024 2:24am
wasimsandhu commented 1 week ago

After wrestling with @tanstack/react-virtual for a few hours, using Virtuoso was surprisingly easy.

Installed react-virtuoso and passed <Virtuoso /> to <Combobox />.

It broke cmdk filtering since the <ComboboxItem> components are wrapped in the virtuoso element:

TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

The cmdk FAQ recommends implementing filtering on your own for virtualization anyway, so that's what I did.

wasimsandhu commented 1 week ago

Tested multiselect on my own machine and it's buttery smooth now -- did not spot any regressions.

I did see that <Combobox> is used in switchable-multi-select and form.tsx -- I did not get a chance to do regression tests for those.

mscolnick commented 1 week ago

awesome work @wasimsandhu!