Skip to content

Commit 96255d4

Browse files
authored
feat(react): Use state context for Redux integration (#5471)
Switch to using state context as outlined by https://develop.sentry.dev/sdk/event-payloads/contexts/#state-context
1 parent 80c66f8 commit 96255d4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/react/src/redux.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export interface SentryEnhancerOptions<S = any> {
6868

6969
const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
7070
const ACTION_BREADCRUMB_TYPE = 'info';
71-
const STATE_CONTEXT_KEY = 'redux.state';
7271

7372
const defaultOptions: SentryEnhancerOptions = {
7473
actionTransformer: action => action,
@@ -106,9 +105,9 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):
106105
/* Set latest state to scope */
107106
const transformedState = options.stateTransformer(newState);
108107
if (typeof transformedState !== 'undefined' && transformedState !== null) {
109-
scope.setContext(STATE_CONTEXT_KEY, transformedState);
108+
scope.setContext('state', { type: 'redux', value: transformedState });
110109
} else {
111-
scope.setContext(STATE_CONTEXT_KEY, null);
110+
scope.setContext('state', null);
112111
}
113112

114113
/* Allow user to configure scope with latest state */

packages/react/test/redux.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ describe('createReduxEnhancer', () => {
6363
const updateAction = { type: ACTION_TYPE, newValue: 'updated' };
6464
store.dispatch(updateAction);
6565

66-
expect(mockSetContext).toBeCalledWith('redux.state', {
67-
value: 'updated',
66+
expect(mockSetContext).toBeCalledWith('state', {
67+
type: 'redux',
68+
value: {
69+
value: 'updated',
70+
},
6871
});
6972
});
7073

@@ -84,9 +87,12 @@ describe('createReduxEnhancer', () => {
8487

8588
Redux.createStore((state = initialState) => state, enhancer);
8689

87-
expect(mockSetContext).toBeCalledWith('redux.state', {
88-
superSecret: 'REDACTED',
89-
value: 123,
90+
expect(mockSetContext).toBeCalledWith('state', {
91+
type: 'redux',
92+
value: {
93+
superSecret: 'REDACTED',
94+
value: 123,
95+
},
9096
});
9197
});
9298

@@ -103,7 +109,7 @@ describe('createReduxEnhancer', () => {
103109
Redux.createStore((state = initialState) => state, enhancer);
104110

105111
// Check that state is cleared
106-
expect(mockSetContext).toBeCalledWith('redux.state', null);
112+
expect(mockSetContext).toBeCalledWith('state', null);
107113
});
108114

109115
it('transforms actions', () => {

0 commit comments

Comments
 (0)