Skip to content

Commit

Permalink
Fix: Prevent state mutation in fetchRevisionsPromise function
Browse files Browse the repository at this point in the history
- Avoid direct mutation of `course.revisions` by creating a new object with updated revisions.
- Ensures compliance with Redux's immutability rules to avoid errors during state updates.
  • Loading branch information
Abishekcs committed Jan 13, 2025
1 parent 35ecd9a commit a5fb923
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/assets/javascripts/actions/revisions_actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {
RECEIVE_REVISIONS,
REVISIONS_LOADING,
Expand Down Expand Up @@ -35,12 +34,19 @@ const fetchAllArticles = async (course) => {

const fetchRevisionsPromise = async (course, users, last_date, dispatch) => {
const { revisions, last_date: new_last_date } = await fetchRevisionsFromUsers(course, users, 7, last_date);
course.revisions = sortRevisionsByDate(revisions);

// we don't await this. When the assessments/references get laoded, the action is dispatched
// Create a new course object with updated revisions
const updatedCourse = {
...course,
revisions: sortRevisionsByDate(revisions),
};

// we don't await this. When the assessments/references get loaded, the action is dispatched
fetchRevisionsAndReferences(revisions, dispatch);
return { course, last_date: new_last_date };

return { course: updatedCourse, last_date: new_last_date };
};

const fetchRevisionsCourseSpecificPromise = async (course, users, last_date, dispatch, articles) => {
const trackedArticles = new Set(
articles.filter(article => article.tracked).map(article => article.title)
Expand Down

0 comments on commit a5fb923

Please sign in to comment.