-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
No error is shown when use a undefined variable #7617
Comments
React does not swallow your exceptions so it must be something else. |
By the way we won’t be able to help unless you provide an example reproducing this. |
I've bumped into this in the past when the call-stack from a Promise results in a reflow of React, catching any errors in the render process (to the best of my ability to debug, anyway). Is it possible that this is what is going on? Edit: Sorry :(. This is what I get for skimming |
@gaearon ran into this today! class Baz extends React.Component {
render() {
return <div>Baz</div>
}
}
class Bar extends React.Component {
render() {
const { foo } = this.state; // Reference Error!
return <div>Bar</div>
}
}
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = {
loaded: false
}
}
componentDidMount() {
Promise.resolve()
.then(() => {
this.setState({ loaded: true })
})
.catch(()=> {
console.log('Swallowed!')
});
}
render() {
const { loaded } = this.state;
return loaded ? <Bar /> : <Baz />;
}
}
ReactDOM.render(<Foo />, document.getElementById('root')); ^^ the example here will result in swallowed errors. wrapping the class Baz extends React.Component {
render() {
return <div>Baz</div>
}
}
class Bar extends React.Component {
render() {
const { foo } = this.state; // Reference Error!
return <div>Bar</div>
}
}
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = {
loaded: false
}
}
componentDidMount() {
Promise.resolve()
.then(() => {
setTimeout(() => this.setState({ loaded: true }));
})
.catch(()=> {
console.log('Not Swallowed!') ;
});
}
render() {
const { loaded } = this.state;
return loaded ? <Bar /> : <Baz />;
}
}
ReactDOM.render(<Foo />, document.getElementById('root')); Is this my own ignorance with promises? For your viewing pleasure: http://codepen.io/nickhudkins/pen/jrAamG |
Yes, but you are swallowing them: .then(() => {
this.setState({ loaded: true })
})
.catch(()=> {
console.log('Swallowed!')
}); Your Even if you don't use If you don’t want to catch errors resulting from componentDidMount() {
Promise.resolve()
.then(() => {
this.setState({ loaded: true })
}, (err) => {
console.log('An error occurred (but not in setState!)', err);
}); In this case, unless you |
I’m closing since there is no reproducible case. |
Awesome. Thank you! I hadn't considered the fact that the setState resulted
|
It’s hard to remember until you spend a few hours debugging it. Don’t worry 😉 |
EDIT: Ahh it may be asynchronous. Goddamn it. Scratch the question. |
It will likely be almost-always async in the future but there are cases when it can't be (e.g. inside an input event handler). |
A small update on this. We just released React 16 beta which shouldn’t emit cryptic errors like this one. Even if the application code swallows an error, React 16 will still print it to the console. It might be too early for you to try React 16 (since ecosystem is still preparing for it), but this error should never occur in the future after you switch to it. |
I am using React v16.9.0, yet I still came across this error. I was, however, able to find the problem. |
I use react with webpack. When I use a variable in my component like
{props.children}
instead ofthis.props.children
the component fail silently. No errors is shown.The text was updated successfully, but these errors were encountered: