Skip to content

Fix Crash in useSelectableCollection when ref not attached to dom node in first render #1629

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

Closed
wants to merge 2 commits into from

Conversation

snowystinger
Copy link
Member

Closes #1622

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@adobe-bot
Copy link

Build successful! 🎉

Comment on lines +340 to +341
// If no default focus key is selected and the collection is mounted, focus the collection itself.
if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {
Copy link
Member

@LFDanLu LFDanLu Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this makes sense for stopping the error but there might be an issue since then focus never gets set on the ListBox itself (this useEffect only happens on the initial render). That would mean the focus remains on the select button itself and pressing up/down would open and close the select menu instead of navigating through the items in the list.

Perhaps this should be extracted to it's own useEffect? Maybe useListBox shouldn't be pulled out into the Select component? Maybe the useEffect should fire if ref.current updates? Not sure

Copy link
Member Author

@snowystinger snowystinger Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I had some similar reservations, however, in practice it seems to work, though the example code didn't have any of the focus/selection code running yet.
I updated the example to match our code on our documentation page so that I could try out the concern that focus would remain on the button, basically a copy paste from https://react-spectrum.adobe.com/react-aria/useSelect.html#example and now it would appear that this check is unnecessary. It behaves with or without it.

I think the outcome of this is

  1. this person can update their code to be more like our documentation Edit, they were trying to move it on purpose, so we'll still need to do Component css packages #2
  2. we should still perform this check somewhere, but maybe some more thought should be put into it, i'll try some other configurations later hopefully this week
  3. figure out why their selection code isn't working

@devongovett devongovett added the waiting Waiting on Issue Author label Mar 18, 2021
@adobe-bot
Copy link

Build successful! 🎉

@snowystinger
Copy link
Member Author

Closing because this only hides the problem

@snowystinger snowystinger deleted the snowystinger-patch-1 branch March 24, 2021 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting Waiting on Issue Author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash in useSelectableCollection when ref not attached to dom node in first render
4 participants