Skip to content

Commit

Permalink
fix(redux): Improve Redux state attachment handling
Browse files Browse the repository at this point in the history
Refactors the code responsible for attaching the Redux
state to Sentry events. The change enhances
efficiency by avoiding the addition of empty JSON
attachments when there is no Redux state available.
  • Loading branch information
malay44 committed Sep 6, 2023
1 parent 2b3735a commit 35fa934
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/react/src/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):
<S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {
options.attachReduxState &&
addGlobalEventProcessor((event, hint) => {
hint.attachments = [
...(hint.attachments || []),
{ filename: 'reduxState.json', data: JSON.stringify(event.contexts && event.contexts.state) || ' ' },
];
if (event.contexts && event.contexts.state && event.contexts.state.type === 'redux') {
hint.attachments = [
...(hint.attachments || []),
{ filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.value) },
];
}
return event;
});

Expand Down

0 comments on commit 35fa934

Please sign in to comment.