Skip to content

Commit 4a78c04

Browse files
committed
Don't nuke the entire context.state.
1 parent ea7ba22 commit 4a78c04

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/vue/src/pinia.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,32 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
6767
/* Set latest state to scope */
6868
const transformedState = options.stateTransformer ? options.stateTransformer(store.$state) : store.$state;
6969
const scope = getCurrentScope();
70+
const currentState = scope.getScopeData().contexts.state;
7071

7172
if (typeof transformedState !== 'undefined' && transformedState !== null) {
7273
const client = getClient();
7374
const options = client && client.getOptions();
7475
const normalizationDepth = (options && options.normalizeDepth) || 3; // default state normalization depth to 3
76+
const piniaStateContext = { type: 'pinia', value: transformedState };
7577

76-
const newStateContext = { state: { type: 'pinia', value: transformedState } };
78+
const newState = {
79+
...(currentState || {}),
80+
state: piniaStateContext,
81+
};
7782

7883
addNonEnumerableProperty(
79-
newStateContext,
84+
newState,
8085
'__sentry_override_normalization_depth__',
8186
3 + // 3 layers for `state.value.transformedState
8287
normalizationDepth, // rest for the actual state
8388
);
8489

85-
scope.setContext('state', newStateContext);
90+
scope.setContext('state', newState);
8691
} else {
87-
scope.setContext('state', null);
92+
scope.setContext('state', {
93+
...(currentState || {}),
94+
state: { type: 'pinia', value: 'undefined' },
95+
});
8896
}
8997
});
9098
});

0 commit comments

Comments
 (0)