Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react): Use state context for Redux integration #5471

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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