Skip to content

Commit

Permalink
Merge pull request #6112 from Abishekcs/fix/redux-state-mutation
Browse files Browse the repository at this point in the history
Fix: Prevent state mutation in fetchRevisionsPromise function
  • Loading branch information
ragesoss authored Jan 13, 2025
2 parents 3938a93 + a5fb923 commit 3b708e8
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 3b708e8

Please sign in to comment.