fix: improve SnackbarNotification cleanup#244
Conversation
📝 WalkthroughWalkthroughSnackbarNotification's cleanup lifecycle is refactored to clear state exclusively after the MUI Snackbar exits, rather than on close with a delayed timeout. The ChangesSnackbar Lifecycle Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
||
| const onClose = () => { | ||
| setOpen(false); | ||
| setTimeout(clearMessage, NOTIFICATION_TIMEOUT); |
There was a problem hiding this comment.
@priscila-moneo could u explain the rationale of this on the PR description ?
smarcet
left a comment
There was a problem hiding this comment.
@priscila-moneo please review comments
ref: https://app.clickup.com/t/86b9y6h89
Rationale
Previously, the SnackbarNotification component sometimes rendered a second, empty snackbar (with only the icon) after the intended message disappeared. This was caused by the cleanup logic: when the snackbar message was cleared, the component briefly rendered with empty content before unmounting, due to the timing of state updates and the use of setTimeout.
This change improves the cleanup flow by leveraging the Snackbar’s onExited event, which fires only after the exit animation completes (either after autoHideDuration or manual close). Now, the message state is cleared only after the snackbar is fully closed, preventing any intermediate render with empty content. This ensures a smoother user experience and eliminates redundant or empty snackbar displays.
Summary by CodeRabbit