Skip to content

Commit

Permalink
fix: always set state.error, return markup from initial render
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgahan authored and davidnpma committed Jun 10, 2017
1 parent 50c8ccc commit c26e255
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ export class RedBoxError extends Component {

// Other eval follow a specific pattern and can be easily parsed.
const isEval = stackLines[1].search(/\(eval at/) !== -1
if (!isEval)
if (!isEval) {
// mapping will be deferred until `componentDidMount`
this.state = { error, mapped: false }
return
}

// The first line is the error message.
let fixedLines = [stackLines.shift()]
Expand Down Expand Up @@ -112,11 +115,9 @@ export class RedBoxError extends Component {
}

render () {
// The error is received as a property and after it gets mapped to the source
// map, it’ll be stored in the state.
const {error, mapped} = this.state
if (!mapped)
return null
// The error is received as a property to initialize state.error, which may
// be updated when it is mapped to the source map.
const {error} = this.state

const {className} = this.props
const {redbox, message, stack, frame} = assign({}, style, this.props.style)
Expand Down

0 comments on commit c26e255

Please sign in to comment.