Skip to content

Commit

Permalink
Fix redux-persist store prop override during state init in ReduxState…
Browse files Browse the repository at this point in the history
…Sync
  • Loading branch information
ivangabriele committed Sep 19, 2024
1 parent d075168 commit e7d37c0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frontend/src/libs/ReduxStateSync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { initializeStateFromOtherTab, sendStateToOtherTab, stampAction } from '.
import type { InternalAction, Message, ReduxStateSyncOptions, StampedAction } from './types'
import type { MainAppDispatch } from '@store'
import type { Action } from 'redux'
import type { AnyObject } from 'yup'

class ReduxStateSync {
#channel: BroadcastChannel
Expand Down Expand Up @@ -116,9 +117,15 @@ class ReduxStateSync {

export const reduxStateSync = new ReduxStateSync()

export const withReduxStateSync = appReducer => (state, action: Action | InternalAction) => {
export const withReduxStateSync = appReducer => (state: AnyObject, action: Action | InternalAction) => {
if ('payload' in action && action.type === InternalActionType.InitializeStateFromOtherTab) {
return appReducer(action.payload, action)
return appReducer(
{
...state,
...action.payload
},
action
)
}

return appReducer(state, action)
Expand Down

0 comments on commit e7d37c0

Please sign in to comment.