@@ -67,24 +67,32 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
67
67
/* Set latest state to scope */
68
68
const transformedState = options . stateTransformer ? options . stateTransformer ( store . $state ) : store . $state ;
69
69
const scope = getCurrentScope ( ) ;
70
+ const currentState = scope . getScopeData ( ) . contexts . state ;
70
71
71
72
if ( typeof transformedState !== 'undefined' && transformedState !== null ) {
72
73
const client = getClient ( ) ;
73
74
const options = client && client . getOptions ( ) ;
74
75
const normalizationDepth = ( options && options . normalizeDepth ) || 3 ; // default state normalization depth to 3
76
+ const piniaStateContext = { type : 'pinia' , value : transformedState } ;
75
77
76
- const newStateContext = { state : { type : 'pinia' , value : transformedState } } ;
78
+ const newState = {
79
+ ...( currentState || { } ) ,
80
+ state : piniaStateContext ,
81
+ } ;
77
82
78
83
addNonEnumerableProperty (
79
- newStateContext ,
84
+ newState ,
80
85
'__sentry_override_normalization_depth__' ,
81
86
3 + // 3 layers for `state.value.transformedState
82
87
normalizationDepth , // rest for the actual state
83
88
) ;
84
89
85
- scope . setContext ( 'state' , newStateContext ) ;
90
+ scope . setContext ( 'state' , newState ) ;
86
91
} else {
87
- scope . setContext ( 'state' , null ) ;
92
+ scope . setContext ( 'state' , {
93
+ ...( currentState || { } ) ,
94
+ state : { type : 'pinia' , value : 'undefined' } ,
95
+ } ) ;
88
96
}
89
97
} ) ;
90
98
} ) ;
0 commit comments