From bfc8b6a46f75aafd0a33bd5d3774b0fffc1c8030 Mon Sep 17 00:00:00 2001 From: Satish Gandham Date: Tue, 25 May 2021 22:07:38 +0530 Subject: [PATCH] Memoize the evaluate popup placement value --- .../CodeEditor/EvaluatedValuePopup.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/client/src/components/editorComponents/CodeEditor/EvaluatedValuePopup.tsx b/app/client/src/components/editorComponents/CodeEditor/EvaluatedValuePopup.tsx index 05feedb6c5..3f252c739f 100644 --- a/app/client/src/components/editorComponents/CodeEditor/EvaluatedValuePopup.tsx +++ b/app/client/src/components/editorComponents/CodeEditor/EvaluatedValuePopup.tsx @@ -1,4 +1,4 @@ -import React, { memo, useRef, useState } from "react"; +import React, { memo, useMemo, useRef, useState } from "react"; import styled from "styled-components"; import _ from "lodash"; import Popper from "pages/Editor/Popper"; @@ -310,13 +310,15 @@ function EvaluatedValuePopup(props: Props) { const [contentHovered, setContentHovered] = useState(false); const wrapperRef = useRef(null); - let placement: Placement = "left-start"; - if (wrapperRef.current) { - const boundingRect = wrapperRef.current.getBoundingClientRect(); - if (boundingRect.left < theme.evaluatedValuePopup.width) { - placement = "right-start"; + const placement: Placement = useMemo(() => { + if (wrapperRef.current) { + const boundingRect = wrapperRef.current.getBoundingClientRect(); + if (boundingRect.left < theme.evaluatedValuePopup.width) { + return "right-start"; + } } - } + return "left-start"; + }, [wrapperRef.current]); return (