fix: incorrect state merging in redux store (#1437)

omit stale config entries while merging in new config state

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Improved state update handling across several modules to enhance
performance and maintain consistency without impacting user experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210628784568830
This commit is contained in:
Pujit Mehrotra
2025-06-25 14:51:01 -04:00
committed by GitHub
parent a7ef06ea25
commit 17b7428779
3 changed files with 13 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';
import { merge } from 'lodash-es';
import { type DynamixConfig } from '@app/core/types/ini.js';
import { loadDynamixConfigFile } from '@app/store/actions/load-dynamix-config-file.js';
@@ -20,7 +19,7 @@ export const dynamix = createSlice({
initialState,
reducers: {
updateDynamixConfig(state, action: PayloadAction<RecursivePartial<SliceState>>) {
return merge(state, action.payload);
return Object.assign(state, action.payload);
},
},
extraReducers(builder) {
@@ -29,11 +28,14 @@ export const dynamix = createSlice({
});
builder.addCase(loadDynamixConfigFile.fulfilled, (state, action) => {
merge(state, action.payload, { status: FileLoadStatus.LOADED });
return {
...(action.payload as DynamixConfig),
status: FileLoadStatus.LOADED,
};
});
builder.addCase(loadDynamixConfigFile.rejected, (state, action) => {
merge(state, action.payload, {
Object.assign(state, action.payload, {
status: FileLoadStatus.FAILED_LOADING,
});
});

View File

@@ -2,7 +2,6 @@ import { join } from 'path';
import type { PayloadAction } from '@reduxjs/toolkit';
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { merge } from 'lodash-es';
import type { RootState } from '@app/store/index.js';
import type { StateFileToIniParserMap } from '@app/store/types.js';
@@ -176,7 +175,7 @@ export const emhttp = createSlice({
}>
) {
const { field } = action.payload;
return merge(state, { [field]: action.payload.state });
return Object.assign(state, { [field]: action.payload.state });
},
},
extraReducers(builder) {
@@ -185,18 +184,16 @@ export const emhttp = createSlice({
});
builder.addCase(loadStateFiles.fulfilled, (state, action) => {
merge(state, action.payload, { status: FileLoadStatus.LOADED });
Object.assign(state, action.payload, { status: FileLoadStatus.LOADED });
});
builder.addCase(loadStateFiles.rejected, (state, action) => {
merge(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
Object.assign(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
});
builder.addCase(loadSingleStateFile.fulfilled, (state, action) => {
if (action.payload) {
// const changedKey = Object.keys(action.payload)[0]
// emhttpLogger.debug('Key', changedKey, 'Difference in changes', getDiff(action.payload, { [changedKey]: state[changedKey] } ))
merge(state, action.payload);
Object.assign(state, action.payload);
} else {
emhttpLogger.warn('Invalid payload returned from loadSingleStateFile()');
}

View File

@@ -2,7 +2,6 @@ import { format } from 'util';
import type { PayloadAction } from '@reduxjs/toolkit';
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { merge } from 'lodash-es';
import type { RootState } from '@app/store/index.js';
import { logger } from '@app/core/log.js';
@@ -48,7 +47,7 @@ export const registration = createSlice({
initialState,
reducers: {
updateRegistrationState(state, action: PayloadAction<Partial<{ keyFile: string }>>) {
return merge(state, action.payload);
return Object.assign(state, action.payload);
},
},
extraReducers(builder) {
@@ -57,11 +56,11 @@ export const registration = createSlice({
});
builder.addCase(loadRegistrationKey.fulfilled, (state, action) => {
merge(state, action.payload, { status: FileLoadStatus.LOADED });
Object.assign(state, action.payload, { status: FileLoadStatus.LOADED });
});
builder.addCase(loadRegistrationKey.rejected, (state, action) => {
merge(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
Object.assign(state, action.payload, { status: FileLoadStatus.FAILED_LOADING });
});
},
});