-
Notifications
You must be signed in to change notification settings - Fork 1.2k
useOption hook throws errors when used with Virtualizer and filtering #3426
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
Comments
I see in our example that typing "6" for instance, causes a bunch of blank space. Thanks for the issue! This isn't a problem in our React Spectrum component implementation, that might be a good place to start comparing. The React Aria examples are meant to be smaller code examples, so I'm sure we just overlooked something. One interesting thing is that if you cause a re-render of the list (ie scrolling) after typing 6, all the blank rows go away, so the collection would appear to be stale for a moment as you suggested. I also wouldn't want to call a hook conditionally, it would have undefined behavior potentially. Best to avoid. |
Circling back on this, I noticed the errors occur in react versions 16 and 17, but not in version 18. I'm curious if you all have any thoughts or insight on that? |
Hey, thanks for the ping. I had some time and took a look at your codesandbox again. Couple of things I noticed:
here's the fixed/working version https://codesandbox.io/s/dawn-cloud-duddgc?file=/src/ComboBox.tsx |
Closing since looks like there is a working version. |
Thanks for the bump. Yes, STRICT MODE was the issue here. Removing strict mode, resolved the issue |
Hi there. I am trying to implement a combobox with virtualizer similar to this code sandbox example.
https://codesandbox.io/s/yb9cq?file=/src/App.tsx
It appears that when filtering the options through entering a custom text input, the useOption hook throws an error. it seems like the hook is trying to find the rendered option in the collection state, but that the option is no longer in that set, because it has been filtered out. I believe it is the function created at line 125 in this file. https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/listbox/src/useOption.ts
To get around this n the example codesandbox, the useOption hook is called conditionally, (line 67 of ListBox.js) which is an implementation that I am not sure reflects best practices, as it requires an exception/ignore to general es-lint standards.
Also this implementation results in blank space being rendered where a filtered option would go, instead of removing that space entirely. see the attached screen grab.
Screen.Recording.2022-08-22.at.2.14.22.PM.mov
At this present moment, I have removed to the virtualizer to achieve the functionality desired, but our team will need to implement an implementation with a virtualizer in the near future. Please let me know if something is off with the implemenation linked in the codesandbox, or if I need to provide additional information.
Thanks, Andrew
The text was updated successfully, but these errors were encountered: