Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKUSelector infinite loop fix #995

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tibiiordachevtex
Copy link

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
Dec-06-2021 16-45-53

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.
Screenshot 2021-11-23 at 17 27 15

Here is a gif of how the selector acts after
Dec-06-2021 16-42-48

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)

@tibiiordachevtex tibiiordachevtex requested a review from a team as a code owner December 6, 2021 14:54
@vtex-io-ci-cd
Copy link
Contributor

vtex-io-ci-cd bot commented Dec 6, 2021

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 馃

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 馃槥

@vtex-io-docs-bot
Copy link

vtex-io-docs-bot bot commented Dec 6, 2021

Beep boop 馃

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 馃
  • I'll do it later 馃槥

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 馃帀馃帀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant