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
fix(hooks): prevent overwrite of itemRefs when hooks rerender #1205
Conversation
I'm a little cautious because I don't know the reason of why the refs were being initialized this way. |
Another solution would be adding this (instead of the proposed changes) so that it resets if items change.
|
Hi! Thanks for looking into this! Maybe resetting the itemRefs when isOpen changes and becomes false? Would that make sense? In any case these changes will need testing. |
690b17f
to
819b957
Compare
We can do that but to me it makes more sense to reset when items change. What do you think?
Added tests that verifies my fix works on memoized components. |
05acf77
to
cd480ac
Compare
I think it makes more sense to clear the refs on Also I'd make a separate test component with the memoized components. And use that for memo-related tests. And leave the previous test component as it is. |
08de88b
to
d88b36c
Compare
@silviuaavram Added the effect and updated the test logic per your comments. For some reason I'm getting some validation hangups, though. |
What validation hangups? I see that there is coverage missing from the new code so the build fails. I am thinking about this recently and about #1176 I am very inclined to go ahead with having a I also think this will simplify the code a bit as well. It will be a breaking change, but moving from one API to another should not be a big deal. |
Oh, I completely missed the coverage error. I can add the missing tests. I'm not very familiar with react-select, looking at the API it seems they accept an I'm all for having the |
Even though they have And regarding to your use case, I imagine you have the |
We could potentially default it to that logic and add the prop as an override? So that we don't need to pass in |
I agree, it does keep things easier as well. I just don't feel confident of providing 2 APIs that don't do the same thing. The current |
bbf628f
to
ff39381
Compare
ff39381
to
1a2b6d3
Compare
Codecov Report
@@ Coverage Diff @@
## master #1205 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 1631 1674 +43
Branches 464 474 +10
=========================================
+ Hits 1631 1674 +43
Continue to review full report at Codecov.
|
@silviuaavram So I don't know what the conclusion ultimately was, but I fixed the coverage issues I was having. I just want to Downshift work smoothly with my memoized items, right now it is a big performance hit on my components. I still can't figure out why I get my I pulled latest from master and I get an error on one of the Ultimately I want to know if we want to merge these changes or if I should close and wait for another solution. |
Great, thanks! So I think we can probably go ahead with this fix. Going further in v7 we should switch to Will review this and merge if ok. |
Closing this one for #1219 as I refactored the tests a little bit. Apart from this refactor everything looks good to me! |
What:
Fixes #1178.
Why:
When memoizing the components, the refs would be reset on the hook rerender, and since not all items call the
getItemProps
prop getter, theitemRefs
object would be incomplete, causing issues when keyboard navigating.How:
Initialized the refs with a value so that the value isn't being overwritten. Testing locally I didn't see any issues with this (
useSelect
anduseCombobox
), on both memoized and non memozied components. Tests passed.Checklist:
When trying to commit I kept getting this error:
I had to
--no-verify
to be able to open the PR, I haven't been able to figure out why it is doing that. Found this issue 🤷