Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem is this solving?
There is an app called wishlist-io that uses the SKUSelector. When adding the prop "visibleVariations" to that SKUSelector, an infinite loop will occur breaking the functionality (the SKUSelector wont update, it will keep the default selection that is coming from the product-context).
One of the reason for the problem seems to be this useEffectSkipMount, that uses an object as a dependency. Even if the fields of the object stay the same, the reference change, so the useEffect will be executed, and the state of selectedVariation will change, causing a re-render.
This ramda deep compare that I added, just checks if the variation really changed.
How to test it?
In order to test, I created 1 workspace that illustrates the behaviour after the change.
workspace - tibidev; account - miniprix
Screenshots or example usage:
Here is a gif of how the selector acts before
It's not seen in the gif, but for a moment the selection changed, but then it is back to the default one from the product-context, this can be seen in the photo below.
Here is a gif of how the selector acts after
Describe alternatives you've considered, if any.
I tried to dive even deeper and see why the variation change reference in the first place, but I had no results after a while.
Related to / Depends on
How does this PR make you feel? 馃敆
![https://media.giphy.com/media/l7fdqmHQ1jCg2HzQlx/giphy.gif](put .gif link here - can be found under "advanced" on giphy)