Skip to content

Commit 2cfa082

Browse files
committed
fix(root): better compatibility with server-side rendering
Setting the prop 'root' when propTypes are kept in server-side rendering may throw if the DOM is not existing; we ensure root does not necessarily use Element/HTMLElement for validation
1 parent 0381b3d commit 2cfa082

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/IntersectionObserver.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export default class IntersectionObserver extends React.Component {
3939
* Can be specified as string for selector matching within the document.
4040
* Defaults to the browser viewport if not specified or if null.
4141
*/
42-
root: PropTypes.oneOfType([PropTypes.instanceOf(global.Element), PropTypes.string]),
42+
root: PropTypes.oneOfType(
43+
[PropTypes.string].concat(typeof HTMLElement === 'undefined' ? [] : PropTypes.instanceOf(HTMLElement))
44+
),
4345

4446
/**
4547
* Margin around the root. Can have values similar to the CSS margin property,

0 commit comments

Comments
 (0)