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: prevent mutation when updating course properties in Calendar's selectDay function #6139

Conversation

Abishekcs
Copy link
Contributor

@Abishekcs Abishekcs commented Jan 17, 2025

What this PR does

This PR fixes a mutation bug in the selectDay function of the Calendar component. The course object was being directly mutated, which violates React's & Redux state management principles and can lead to unintended side effects.

Cause of the bug

The course object from this.props was being directly modified when updating the day_exceptions and no_day_exceptions properties. Since props are supposed to be immutable and plus this props is from redux slice passed all the way from Course component, this direct mutation could cause unexpected behaviors, such as incorrect renders or state inconsistencies.

Fix of the bug

The fix involves avoiding direct mutation by creating a shallow copy of the course object and updating its properties immutably before passing it to the updateCourse function.

Screenshots

Before:

Before.mp4

After:

After.mp4

@Abishekcs Abishekcs marked this pull request as draft January 17, 2025 19:30
@Abishekcs Abishekcs force-pushed the fix/immutable-update-of-course-slice branch from 1cd2969 to 8b54f7d Compare January 17, 2025 20:01
@Abishekcs Abishekcs marked this pull request as ready for review January 18, 2025 08:36
@Abishekcs Abishekcs marked this pull request as draft January 18, 2025 16:10
@Abishekcs Abishekcs force-pushed the fix/immutable-update-of-course-slice branch from 8b54f7d to 64abc31 Compare January 27, 2025 20:45
@Abishekcs Abishekcs marked this pull request as ready for review January 27, 2025 20:49
@ragesoss ragesoss merged commit ca22cf9 into WikiEducationFoundation:master Jan 28, 2025
1 check passed
@Abishekcs Abishekcs deleted the fix/immutable-update-of-course-slice branch January 28, 2025 20:00
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.

2 participants