Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] Ability to display errors in console instead of redbox #462

Closed
icek opened this issue Jan 19, 2017 · 8 comments
Closed

[3.0] Ability to display errors in console instead of redbox #462

icek opened this issue Jan 19, 2017 · 8 comments

Comments

@icek
Copy link

icek commented Jan 19, 2017

Errors displayed in Redbox are useless for me especially when it comes to line numbers.

When sourcemaps are used, Chrome console can show exact error location (eg: SomeComponent.js:12:13) and you can jump directly into that file and chrome will highlight line causing error. Redbox on the other hand show line number in a bundled file (eg: bundle.js:33052:13) if you are patient you can search for this line...

Example of how useless it is:
screen shot 2017-01-19 at 03 15 52

I digged a little and found that there is a property errorReporter on AppContainer so I tried to implement custom component for redirecting errors back to console, but I don't know how to make it work. Here is my initial approach:

import React from "react";

export default class NormalConsoleErrorInsteadOfRedbox extends React.Component {
    componentDidMount() {
        console.error(this.props.error);
    }

    componentDidUpdate () {
        console.error(this.props.error);
    }

    render() {
        return null; // <div/>
    }
}

used like this:

ReactDOM.render(
    <AppContainer errorReporter="NormalConsoleErrorInsteadOfRedbox">
        <Root/>
    </AppContainer>,
    rootEl
);

and now I get:

Warning: Unknown prop `error` on <NormalConsoleErrorInsteadOfRedbox> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in NormalConsoleErrorInsteadOfRedbox (created by AppContainer)
    in AppContainer

React 15.4.2, react-hot-loader 3.0.0-beta.6

@icek
Copy link
Author

icek commented Jan 19, 2017

Nevermind, here is a quick workaround:

delete AppContainer.prototype.unstable_handleError;

ReactDOM.render(
    <AppContainer>
        <Root/>
    </AppContainer>,
    rootEl
);

and same error in console:

screen shot 2017-01-19 at 03 37 36

@jtomaszewski
Copy link

jtomaszewski commented Jan 19, 2017

Same here. Thanks for the workaround @icek , it works for me for now.

I think if redbox would show the error AND log it in the console at the same time, would be okay. Could be switched on/off with a prop.

@calesce
Copy link
Collaborator

calesce commented Jan 28, 2017

I'm thinking we can add an <AppContainer> without an unstable_handleError method. Until we either get better (or faster) source maps as well as better error boundaries in React, the Redbox is far from perfect.

@AlexKvazos
Copy link

AlexKvazos commented Mar 7, 2017

Can't we make it so that Redbox doesn't stop the error from logging into the console with proper sourcemaps?

Edit: suggested originally by @jtomaszewski

@wkwiatek
Copy link
Collaborator

wkwiatek commented Mar 8, 2017

I updated PR #494 so that the default behaviour will be console.error.

However, if you like RedBox for some reason there will be a possibility to add custom error catcher (documented in docs/TipsAndTricks.md).

There's still an issue opened for tracking errors #164, so I believe we can continue thinking about better approach. Nice solution would be to have 'redbox' only on a component that fails, and it can be achieved on react-proxy level.

Would that work for most of you guys?

@vincent-ly
Copy link

@icek Thanks for the quick fix!

@jeswin
Copy link

jeswin commented May 27, 2017

@icek The workaround saved my day. The red box is a poor developer experience compared to full call stack information in the console.

@twig-openlearning
Copy link

Workaround saved my sanity. I don't know why we're forced to use something like RedBox that provides little benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants