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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(alertbar): skip init on component update #300

Merged
1 commit merged into from
Sep 29, 2020
Merged

Conversation

ghost
Copy link

@ghost ghost commented Sep 28, 2020

Fixes an infinite loop caused by an unconditional setstate on component updates. It doesn't seem necessary to re-run init when the props are updated anyway. The core problem was the setState in the show() method, which was called by init(), which was run on every update (or more precisely, when state was the same as the previous state).

  • Since we're not reusing init, I've just moved what we were doing there to didMount
  • Since show was called on didMount and just changing state, I'm now starting with that state on mount. That meant show could also be removed. This meant that the animation logic had to be changed, which I've done as well.

I've tried to stick to the existing code as much as possible. Starting out with the .visible class could maybe be refactored to starting out without a class, and then hiding when a .hiding class is added instead for example. But I figured that those kinds of more elaborate changes were out of scope for this PR.

Closes #299

@ghost ghost self-requested a review as a code owner September 28, 2020 14:07
@ghost ghost force-pushed the fix-alertbar-infinite-loop branch from 42f2b68 to b08c8a9 Compare September 28, 2020 14:15
@ghost

This comment has been minimized.

@ghost

This comment has been minimized.

@cypress
Copy link

cypress bot commented Sep 28, 2020



Test summary

494 0 0 0


Run details

Project ui
Status Passed
Commit a6171a4
Started Sep 29, 2020 9:08 AM
Ended Sep 29, 2020 9:19 AM
Duration 11:31 💡
OS Linux Ubuntu Linux - 18.04
Browser Electron 80

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@ghost

This comment has been minimized.

@ghost ghost marked this pull request as draft September 28, 2020 14:41
@ghost ghost force-pushed the fix-alertbar-infinite-loop branch from b08c8a9 to b250d42 Compare September 29, 2020 09:03
fixes an infinite loop caused by an unconditional setstate on component updates
@ghost ghost force-pushed the fix-alertbar-infinite-loop branch from b250d42 to a6171a4 Compare September 29, 2020 09:05
@ghost ghost marked this pull request as ready for review September 29, 2020 09:08
Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

Great work!

@ghost
Copy link
Author

ghost commented Sep 29, 2020

Great work!

Thanks! Thanks for the help debugging!

@ghost ghost merged commit 2a505f9 into master Sep 29, 2020
@ghost ghost deleted the fix-alertbar-infinite-loop branch September 29, 2020 09:23
@dhis2-bot
Copy link
Contributor

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

Successfully merging this pull request may close these issues.

100% cpu usage with certain use of the alertstack/alertbar
2 participants