Skip to content

Commit

Permalink
fix: Load the source map before displaying the error
Browse files Browse the repository at this point in the history
  • Loading branch information
borela authored and davidnpma committed May 31, 2017
1 parent 9d135ec commit 3c126ec
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import style from './style.js'
import ErrorStackParser from 'error-stack-parser'
import assign from 'object-assign'
import {isFilenameAbsolute, makeUrl, makeLinkText} from './lib'
import { mapStackTrace } from 'sourcemapped-stacktrace'

export class RedBoxError extends Component {
static propTypes = {
Expand All @@ -21,6 +22,26 @@ export class RedBoxError extends Component {
useLines: true,
useColumns: true
}

state = {}

constructor(props) {
super(props)
this.mapError(props.error)
}

componentWillReceiveProps(nextProps) {
this.mapError(nextProps.error)
}

mapError(error) {
mapStackTrace(error.stack, mappedStack => {
const mappedError = error;
mappedError.stack = mappedStack.join('\n');
this.setState({ error: mappedError });
});
}

renderFrames (frames) {
const {filename, editorScheme, useLines, useColumns} = this.props
const {frame, file, linkToFile} = assign({}, style, this.props.style)
Expand Down Expand Up @@ -48,8 +69,13 @@ export class RedBoxError extends Component {
)
})
}

render () {
const {error, className} = this.props
const {error} = this.state
if (!error)
return null

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

let frames
Expand Down

0 comments on commit 3c126ec

Please sign in to comment.