File tree 2 files changed +55
-17
lines changed
packages/react-error-overlay/src
2 files changed +55
-17
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
22
22
import {
23
23
permanentRegister as permanentRegisterConsole ,
24
24
} from './effects/proxyConsole' ;
25
+ import { massage as massageWarning } from './utils/warnings' ;
25
26
26
27
import {
27
28
consume as consumeError ,
@@ -210,23 +211,17 @@ function inject() {
210
211
registerStackTraceLimit ( ) ;
211
212
212
213
permanentRegisterConsole ( 'error' , warning => {
213
- const nIndex = warning . indexOf ( '\n' ) ;
214
- let message = warning ;
215
- if ( nIndex !== - 1 ) {
216
- message = message . substring ( 0 , nIndex ) ;
217
- }
218
- const stack = warning . substring ( nIndex + 1 ) ;
219
- window . requestAnimationFrame ( function ( ) {
220
- return crash (
221
- // $FlowFixMe
222
- {
223
- message : message ,
224
- stack : stack ,
225
- __unmap_source : '/static/js/bundle.js' ,
226
- } ,
227
- false
228
- ) ;
229
- } ) ;
214
+ const data = massageWarning ( warning ) ;
215
+ if ( data == null ) return ;
216
+ crash (
217
+ // $FlowFixMe
218
+ {
219
+ message : data . message ,
220
+ stack : data . stack ,
221
+ __unmap_source : '/static/js/bundle.js' ,
222
+ } ,
223
+ false
224
+ ) ;
230
225
} ) ;
231
226
}
232
227
Original file line number Diff line number Diff line change
1
+ // @flow
2
+
3
+ // This is a list of React warnings to display
4
+ // There must be zero or one capture group; and the capture group is assumed to be a missing stack frame.
5
+ const warnings = [
6
+ / ^ .* R e a c t .c r e a t e E l e m e n t : t y p e i s i n v a l i d .+ C h e c k y o u r c o d e a t ( .* ?: .* ) [ . ] $ / ,
7
+ ] ;
8
+ // This is a list of information to remove from React warnings, it's not particularly useful to show
9
+ const removals = [ / C h e c k y o u r c o d e a t ( .* ?: .* ) [ . ] / ] ;
10
+
11
+ function massage ( warning : string ) : { message: string , stack : string } | null {
12
+ const nIndex = warning . indexOf ( '\n' ) ;
13
+ let message = warning ;
14
+ if ( nIndex !== - 1 ) {
15
+ message = message . substring ( 0 , nIndex ) ;
16
+ }
17
+ let stack = warning . substring ( nIndex + 1 ) ;
18
+
19
+ let found = false ;
20
+ for ( const warning of warnings ) {
21
+ const m = message . match ( warning ) ;
22
+ if ( ! m ) {
23
+ continue ;
24
+ }
25
+ found = true ;
26
+ if ( ! m [ 1 ] ) {
27
+ break ;
28
+ }
29
+ stack = `in render (at ${ m [ 1 ] } )\n${ stack } ` ;
30
+ break ;
31
+ }
32
+ if ( ! found ) {
33
+ return null ;
34
+ }
35
+
36
+ for ( const trim of removals ) {
37
+ message = message . replace ( trim , '' ) ;
38
+ }
39
+
40
+ return { message, stack } ;
41
+ }
42
+
43
+ export { massage } ;
You can’t perform that action at this time.
0 commit comments