@@ -8,6 +8,9 @@ import Config from './config';
88const observerOptions = [ 'root' , 'rootMargin' , 'threshold' ] ;
99const observableProps = [ 'root' , 'rootMargin' , 'threshold' , 'disabled' ] ;
1010const { hasOwnProperty, toString } = Object . prototype ;
11+ const missingNodeError = new Error (
12+ "ReactIntersectionObserver: Can't find DOM node in the provided children. Make sure to render at least one DOM node in the tree."
13+ ) ;
1114
1215const getOptions = ( props ) => {
1316 return observerOptions . reduce ( ( options , key ) => {
@@ -110,9 +113,7 @@ class IntersectionObserver extends React.Component {
110113 return false ;
111114 }
112115 if ( ! this . targetNode ) {
113- throw new Error (
114- "ReactIntersectionObserver: Can't find DOM node in the provided children. Make sure to render at least one DOM node in the tree."
115- ) ;
116+ throw missingNodeError ;
116117 }
117118 this . observer = createObserver ( getOptions ( this . props ) ) ;
118119 this . target = this . targetNode ;
@@ -190,15 +191,27 @@ class ErrorBoundary extends React.Component {
190191 forwardedRef : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
191192 } ;
192193
194+ static getDerivedStateFromError ( ) {
195+ return { hasError : true } ;
196+ }
197+
198+ state = {
199+ hasError : false ,
200+ } ;
201+
193202 componentDidCatch ( error , info ) {
194- if ( Config . errorReporter ) {
195- Config . errorReporter ( error , info ) ;
203+ if ( error === missingNodeError ) {
204+ Config . errorReporter && Config . errorReporter ( error , info ) ;
196205 }
197206 }
198207
199208 render ( ) {
200209 const { forwardedRef, ...props } = this . props ;
201210
211+ if ( this . state . hasError ) {
212+ return props . children ;
213+ }
214+
202215 return < IntersectionObserver ref = { forwardedRef } { ...props } /> ;
203216 }
204217}
0 commit comments