1
1
import React , { Component , PropTypes } from 'react'
2
+ import ReactDOM from 'react-dom'
2
3
import style from './style.js'
3
4
import ErrorStackParser from 'error-stack-parser'
4
5
import assign from 'object-assign'
5
6
import { isFilenameAbsolute , makeUrl , makeLinkText } from './lib'
6
7
7
- export default class RedBox extends Component {
8
+ export class RedBoxError extends Component {
8
9
static propTypes = {
9
10
error : PropTypes . instanceOf ( Error ) . isRequired ,
10
11
filename : PropTypes . string ,
@@ -13,7 +14,7 @@ export default class RedBox extends Component {
13
14
useColumns : PropTypes . bool ,
14
15
style : PropTypes . object ,
15
16
}
16
- static displayName = 'RedBox '
17
+ static displayName = 'RedBoxError '
17
18
static defaultProps = {
18
19
useLines : true ,
19
20
useColumns : true
@@ -75,3 +76,31 @@ export default class RedBox extends Component {
75
76
)
76
77
}
77
78
}
79
+
80
+ // "Portal" component for actual RedBoxError component to
81
+ // render to (directly under body). Prevents bugs as in #27.
82
+ export default class RedBox extends Component {
83
+ static propTypes = {
84
+ error : PropTypes . instanceOf ( Error ) . isRequired
85
+ }
86
+ static displayName = 'RedBox'
87
+ componentDidMount ( ) {
88
+ this . el = document . createElement ( 'div' )
89
+ document . body . appendChild ( this . el )
90
+ this . renderRedBoxError ( )
91
+ }
92
+ componentDidUpdate ( ) {
93
+ this . renderRedBoxError ( )
94
+ }
95
+ componentWillUnmount ( ) {
96
+ React . unmountComponentAtNode ( this . el )
97
+ document . body . removeChild ( this . el )
98
+ this . el = null
99
+ }
100
+ renderRedBoxError ( ) {
101
+ ReactDOM . render ( < RedBoxError { ...this . props } /> , this . el )
102
+ }
103
+ render ( ) {
104
+ return null
105
+ }
106
+ }
0 commit comments