-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Labels
Description
Expected behavior
An error thrown by a child of the intersection observer should end up in the user deifned error boundary that was placed outside of the intersection observer.
Current behavior
The intersection observer catches all errors, istead of only handling a missing DOM node situation.
Steps to reproduce
Render an app like this:
import React from 'react';
import IntersectionObserver from '@researchgate/react-intersection-observer';
class MyErrorBoundary extends React.Component {
state = {hasError: false};
componentDidCatch(error, info) {
console.log('I am not called!');
}
static getDerivedStateFromError(error) {
return {hasError: true};
}
render() {
console.log('I am called?');
return this.state.hasError ? 'oy' : this.props.children;
}
}
class ChildWithError extends React.Component {
render() {
return (
<button
onClick={() => {
this.setState(() => {
throw new Error('Some forbidden Button was clicked! ');
});
}}
>
click here to trigger error
</button>
);
}
}
class App extends React.Component {
render() {
return (
<MyErrorBoundary>
<IntersectionObserver onChange={() => {}} threshold={0.5}>
<div>
<ChildWithError />
</div>
</IntersectionObserver>
</MyErrorBoundary>
);
}
}
You will find the console.log('I am not called!'); is not called.
Context (environment)
- Version: 1.1.0 / 1.1.1
- Platform: Darwin host 18.7.0 Darwin Kernel Version 18.7.0: Thu Jan 23 06:52:12 PST 2020; root:xnu-4903.278.25~1/RELEASE_X86_64 x86_64