From 1003262d2cd973f5330f4bb0dd3ecb7a4fca1c85 Mon Sep 17 00:00:00 2001 From: Miroslav Jancarik Date: Fri, 7 Sep 2018 19:40:01 +0200 Subject: [PATCH] fix(iframe): allow updating noloading props after mounting --- src/iframe/HtmlIframe.jsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/iframe/HtmlIframe.jsx b/src/iframe/HtmlIframe.jsx index 29e0f02..d6b75c7 100644 --- a/src/iframe/HtmlIframe.jsx +++ b/src/iframe/HtmlIframe.jsx @@ -18,12 +18,17 @@ export default class HtmlIframe extends React.PureComponent { }; } + static getDerivedStateFromProps(nextProps, prevState) { + return { + visibleInViewport: + nextProps.noloading || prevState.visibleInViewport || false + }; + } + constructor(props, context) { super(props, context); - this.state = { - visibleInViewport: props.noloading || false - }; + this.state = {}; this._registeredVisibilityId = null; @@ -128,10 +133,13 @@ export default class HtmlIframe extends React.PureComponent { } onVisibilityWriter(visibility, observer) { - if (this.state.visibleInViewport === false && visibility > 0) { + if (visibility > 0) { observer && observer.disconnect(); this._unregisterToCheckingVisibility(); - this.setState({ visibleInViewport: true }); + + if (this.state.visibleInViewport === false) { + this.setState({ visibleInViewport: true }); + } } }