Skip to content

Commit

Permalink
Merge pull request #689 from liorbrauer/prevent-unmounted-setstate
Browse files Browse the repository at this point in the history
Prevent calling setState on an unmounted WindowScroller component
  • Loading branch information
bvaughn authored Jun 10, 2017
2 parents efa0793 + cbbacc2 commit 727af33
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/WindowScroller/WindowScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export default class WindowScroller extends PureComponent {
registerScrollListener(this, scrollElement)

window.addEventListener('resize', this._onResize, false)

this._isMounted = true
}

componentWillReceiveProps (nextProps) {
Expand All @@ -106,6 +108,8 @@ export default class WindowScroller extends PureComponent {
unregisterScrollListener(this, this.props.scrollElement || window)

window.removeEventListener('resize', this._onResize, false)

this._isMounted = false
}

render () {
Expand All @@ -127,6 +131,8 @@ export default class WindowScroller extends PureComponent {

// Referenced by utils/onScroll
__handleWindowScrollEvent (event) {
if (!this._isMounted) return

const { onScroll } = this.props

const scrollElement = this.props.scrollElement || window
Expand Down

0 comments on commit 727af33

Please sign in to comment.