Skip to content

fix(alerts): ensure hiding works correctly and alerts are not re-added [DHIS2-15438] - #859

Merged
HendrikThePendric merged 4 commits into
masterfrom
fix/correctly-remove-multiple-alerts-hiding-simultaniously-DHIS2-15438
Jul 5, 2024
Merged

fix(alerts): ensure hiding works correctly and alerts are not re-added [DHIS2-15438]#859
HendrikThePendric merged 4 commits into
masterfrom
fix/correctly-remove-multiple-alerts-hiding-simultaniously-DHIS2-15438

Conversation

@HendrikThePendric

@HendrikThePendric HendrikThePendric commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

This PR fixes a bug that was observed in the maps-app where multiple info alerts were added at approximately the same time. These alerts would then also hide at approximately the same time, but one alert would finish first and this would cause the other one to remount and restart its appear/show/hide lifecycle.

It took a long time to debug this issue and I found a few things wrong:

  • It turned out that on occasion the alertStackAlerts was an empty array when it should have been populated. In the next render cycle, the array would have the expected alerts again, but because the array was empty during the previous render cycle, everything was remounting all the time.
  • The fact that both the alerts-array from the alerts-manager and the local alerts array were stateful/reactive and because the latter was updated in response to changes in the former, was causing a double render all the time. This was making the problem a lot more difficult to reason about, and also wasteful. The new hook doesn't have a local reactive state for the alerts, it will only trigger a single re-render when the alerts from the alerts-manager change, or when one of the alerts is done hiding.

After fixing that empty-array and double render problem I realised I had broken some preexisting functionality: As I explain here, there is a fundamental difference between how alerts hide "naturally" VS programatically. I had already catered for this in the original implementation, but broke that while fixing the initial bug. I found this problem by chance: there were no test cases that broke. So I decided to add a test for this as well.

@HendrikThePendric HendrikThePendric self-assigned this Jul 4, 2024
@HendrikThePendric
HendrikThePendric marked this pull request as ready for review July 4, 2024 15:10
@HendrikThePendric HendrikThePendric changed the title chore: add bug reproduction test case fix(alerts): ensure hiding works correctly and alerts are not re-added [DHIS2-15438] Jul 4, 2024

@KaiVandivier KaiVandivier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good -- interesting problem and solution! Thanks for the tests too 🙏 I also reproduced and tested it out in the example app:

Before -

alerts-before.mov

After -

alerts-after.mov

Comment thread adapter/src/components/Alerts.js Outdated
Co-authored-by: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com>
@HendrikThePendric
HendrikThePendric merged commit 6b11fff into master Jul 5, 2024
@HendrikThePendric
HendrikThePendric deleted the fix/correctly-remove-multiple-alerts-hiding-simultaniously-DHIS2-15438 branch July 5, 2024 10:06
dhis2-bot added a commit that referenced this pull request Jul 5, 2024
## [11.6.1](v11.6.0...v11.6.1) (2024-07-05)

### Bug Fixes

* **alerts:** ensure hiding works correctly and alerts are not re-added [DHIS2-15438] ([#859](#859)) ([6b11fff](6b11fff))
@dhis2-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 11.6.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

dhis2-bot added a commit that referenced this pull request Jul 8, 2024
# [12.0.0-alpha.3](v12.0.0-alpha.2...v12.0.0-alpha.3) (2024-07-08)

### Bug Fixes

* **alerts:** ensure hiding works correctly and alerts are not re-added [DHIS2-15438] ([#859](#859)) ([6b11fff](6b11fff))
* fixed dimensions plugins [LIBS-634] ([#858](#858)) ([1f717f3](1f717f3))
* small text change in changelog ([824dd2f](824dd2f))

### Features

* cleanup plugin error boundary [UX-136] ([#856](#856)) ([de252fe](de252fe))
* parse additional namespaces from `d2.config.js` and add to `manifest.webapp` [LIBS-638]  ([#860](#860)) ([62782fe](62782fe))
@dhis2-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 12.0.0-alpha.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants