@@ -34,26 +34,29 @@ export const buildSharedStateMiddleware = (
3434 const preferenceKey = syncEnabled && hasVerifiedEmail && prefsReady ? 'shared' : 'local' ;
3535 const shared = { } ;
3636
37- Object . keys ( sharedStateFilters ) . forEach ( ( key ) => {
38- const filter = sharedStateFilters [ key ] ;
39- const { source, property, transform } = filter ;
40- let value = nextState [ source ] [ property ] ;
41- if ( transform ) {
42- value = transform ( value ) ;
43- }
37+ // Skip prefSet for 'local' preferences
38+ if ( preferenceKey === 'shared' ) {
39+ Object . keys ( sharedStateFilters ) . forEach ( ( key ) => {
40+ const filter = sharedStateFilters [ key ] ;
41+ const { source, property, transform } = filter ;
42+ let value = nextState [ source ] [ property ] ;
43+ if ( transform ) {
44+ value = transform ( value ) ;
45+ }
4446
45- shared [ key ] = value ;
46- } ) ;
47+ shared [ key ] = value ;
48+ } ) ;
4749
48- if ( ! isEqual ( oldShared , shared ) ) {
49- // only update if the preference changed from last call in the same session
50- oldShared = shared ;
51- dispatch ( doPreferenceSet ( preferenceKey , shared , SHARED_PREFERENCE_VERSION ) ) ;
52- }
50+ if ( ! isEqual ( oldShared , shared ) ) {
51+ // only update if the preference changed from last call in the same session
52+ oldShared = shared ;
53+ dispatch ( doPreferenceSet ( preferenceKey , shared , SHARED_PREFERENCE_VERSION ) ) ;
54+ }
5355
54- if ( sharedStateCb ) {
55- // Pass dispatch to the callback to consumers can dispatch actions in response to preference set
56- sharedStateCb ( { dispatch, getState, syncId : timeout } ) ;
56+ if ( sharedStateCb ) {
57+ // Pass dispatch to the callback to consumers can dispatch actions in response to preference set
58+ sharedStateCb ( { dispatch, getState, syncId : timeout } ) ;
59+ }
5760 }
5861 clearTimeout ( timeout ) ;
5962 return actionResult ;
0 commit comments