From 76926d4be3c29be73052a470431b62bb11ecdd7c Mon Sep 17 00:00:00 2001 From: Gabriele Petronella Date: Thu, 4 May 2023 16:09:07 +0200 Subject: [PATCH] Try to fix infinite re-rendering --- src/Popover/Popover.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Popover/Popover.tsx b/src/Popover/Popover.tsx index f3eb2ba4..c259adbc 100644 --- a/src/Popover/Popover.tsx +++ b/src/Popover/Popover.tsx @@ -3,6 +3,7 @@ import * as ReactDOM from 'react-dom'; import cx from 'classnames'; import debounce = require('lodash/debounce'); import uniq = require('lodash/uniq'); +import isEqual = require('lodash/isEqual'); import { getContextWrapper, Children } from '../utils'; const NO_SIZE_WRAPPER = 'no-size-wrapper'; @@ -259,7 +260,7 @@ export class Popover extends React.Component { const { top: childY, left: childX } = this.getOffsetRect(this.children); const { top: popoverY, left: popoverX } = this.getOffsetRect(popoverNode); - this.setState({ + const newState = { child: { width: childWidth, height: childHeight, @@ -272,7 +273,14 @@ export class Popover extends React.Component { x: popoverX, y: popoverY } - }); + }; + + if ( + !isEqual(this.state.child, newState.child) || + !isEqual(this.state.popover, newState.popover) + ) { + this.setState(newState); + } } };