Skip to content

Commit

Permalink
DDF-4903 Fix render loop caused by poller in dropdown.js (#4906)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Dimka authored and djblue committed Jun 4, 2019
1 parent 0bbfffe commit 1ed85a7
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const React = require('react')
const { createPortal } = require('react-dom')

import styled from '../styles/styled-components'
import isEqual from 'lodash/isEqual'

class Poller extends React.Component {
constructor(props) {
Expand All @@ -17,7 +18,10 @@ class Poller extends React.Component {
window.cancelAnimationFrame(this.id)
}
loop = () => {
this.setState(this.props.fn())
const state = this.props.fn()
if (!isEqual(state, this.state)) {
this.setState(state)
}
this.id = window.requestAnimationFrame(this.loop)
}
render() {
Expand Down Expand Up @@ -160,8 +164,9 @@ class Dropdown extends React.Component {
}
}
getRect = () => {
const rect = this.ref !== undefined ? this.ref.getBoundingClientRect() : {}
return { rect }
const { x, y, width, height } =
this.ref !== undefined ? this.ref.getBoundingClientRect() : {}
return { rect: { x, y, width, height } }
}
componentDidMount() {
document.addEventListener('mousedown', this.onMouseDown)
Expand Down

0 comments on commit 1ed85a7

Please sign in to comment.