Skip to content

Commit

Permalink
feat(react): Use state context for Redux integration (#5471)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Jul 26, 2022
1 parent 80c66f8 commit 96255d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/react/src/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export interface SentryEnhancerOptions<S = any> {

const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
const ACTION_BREADCRUMB_TYPE = 'info';
const STATE_CONTEXT_KEY = 'redux.state';

const defaultOptions: SentryEnhancerOptions = {
actionTransformer: action => action,
Expand Down Expand Up @@ -106,9 +105,9 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):
/* Set latest state to scope */
const transformedState = options.stateTransformer(newState);
if (typeof transformedState !== 'undefined' && transformedState !== null) {
scope.setContext(STATE_CONTEXT_KEY, transformedState);
scope.setContext('state', { type: 'redux', value: transformedState });
} else {
scope.setContext(STATE_CONTEXT_KEY, null);
scope.setContext('state', null);
}

/* Allow user to configure scope with latest state */
Expand Down
18 changes: 12 additions & 6 deletions packages/react/test/redux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ describe('createReduxEnhancer', () => {
const updateAction = { type: ACTION_TYPE, newValue: 'updated' };
store.dispatch(updateAction);

expect(mockSetContext).toBeCalledWith('redux.state', {
value: 'updated',
expect(mockSetContext).toBeCalledWith('state', {
type: 'redux',
value: {
value: 'updated',
},
});
});

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

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

expect(mockSetContext).toBeCalledWith('redux.state', {
superSecret: 'REDACTED',
value: 123,
expect(mockSetContext).toBeCalledWith('state', {
type: 'redux',
value: {
superSecret: 'REDACTED',
value: 123,
},
});
});

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

// Check that state is cleared
expect(mockSetContext).toBeCalledWith('redux.state', null);
expect(mockSetContext).toBeCalledWith('state', null);
});

it('transforms actions', () => {
Expand Down

0 comments on commit 96255d4

Please sign in to comment.