Skip to content

Commit cd754fa

Browse files
committed
fix(redux): Improve Redux state attachment handling
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.
1 parent 2b3735a commit cd754fa

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

packages/react/src/redux.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,17 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):
9898
<S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {
9999
options.attachReduxState &&
100100
addGlobalEventProcessor((event, hint) => {
101-
hint.attachments = [
102-
...(hint.attachments || []),
103-
{ filename: 'reduxState.json', data: JSON.stringify(event.contexts && event.contexts.state) || ' ' },
104-
];
101+
if (
102+
event.contexts &&
103+
event.contexts.state &&
104+
event.contexts.state.state &&
105+
event.contexts.state.state.type === 'redux'
106+
) {
107+
hint.attachments = [
108+
...(hint.attachments || []),
109+
{ filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },
110+
];
111+
}
105112
return event;
106113
});
107114

packages/types/src/context.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ export interface Contexts extends Record<string, Context | undefined> {
1010
response?: ResponseContext;
1111
trace?: TraceContext;
1212
cloud_resource?: CloudResourceContext;
13+
state?: ReduxStateContext;
14+
}
15+
16+
export interface ReduxStateContext extends Record<string, unknown> {
17+
state: {
18+
[key: string]: any;
19+
type: string;
20+
value: any;
21+
};
1322
}
1423

1524
export interface AppContext extends Record<string, unknown> {

0 commit comments

Comments
 (0)