File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,12 @@ export function createSelectorHook(context = ReactReduxContext): UseSelector {
99
99
) {
100
100
const toCompare = selector ( state )
101
101
if ( ! equalityFn ( selected , toCompare ) ) {
102
+ let stack : string | undefined = undefined
103
+ try {
104
+ throw new Error ( )
105
+ } catch ( e ) {
106
+ ; ( { stack } = e as Error )
107
+ }
102
108
console . warn (
103
109
'Selector ' +
104
110
( selector . name || 'unknown' ) +
@@ -108,6 +114,7 @@ export function createSelectorHook(context = ReactReduxContext): UseSelector {
108
114
state,
109
115
selected,
110
116
selected2 : toCompare ,
117
+ stack,
111
118
}
112
119
)
113
120
}
@@ -120,11 +127,18 @@ export function createSelectorHook(context = ReactReduxContext): UseSelector {
120
127
) {
121
128
// @ts -ignore
122
129
if ( selected === state ) {
130
+ let stack : string | undefined = undefined
131
+ try {
132
+ throw new Error ( )
133
+ } catch ( e ) {
134
+ ; ( { stack } = e as Error )
135
+ }
123
136
console . warn (
124
137
'Selector ' +
125
138
( selector . name || 'unknown' ) +
126
139
' returned the root state when called. This can lead to unnecessary rerenders.' +
127
- '\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.'
140
+ '\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.' ,
141
+ { stack }
128
142
)
129
143
}
130
144
}
Original file line number Diff line number Diff line change @@ -805,6 +805,7 @@ describe('React', () => {
805
805
} ) ,
806
806
selected : expect . any ( Number ) ,
807
807
selected2 : expect . any ( Number ) ,
808
+ stack : expect . any ( String ) ,
808
809
} )
809
810
)
810
811
} )
@@ -920,7 +921,10 @@ describe('React', () => {
920
921
)
921
922
922
923
expect ( consoleSpy ) . toHaveBeenCalledWith (
923
- expect . stringContaining ( 'returned the root state when called.' )
924
+ expect . stringContaining ( 'returned the root state when called.' ) ,
925
+ expect . objectContaining ( {
926
+ stack : expect . any ( String ) ,
927
+ } )
924
928
)
925
929
} )
926
930
} )
You can’t perform that action at this time.
0 commit comments