diff --git a/app/client/src/components/editorComponents/CodeEditor/EvaluatedValuePopup.tsx b/app/client/src/components/editorComponents/CodeEditor/EvaluatedValuePopup.tsx index 4285ca25ee..c921c70fb8 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, { useRef, useState } from "react"; +import React, { memo, useRef, useState } from "react"; import styled from "styled-components"; import _ from "lodash"; import Popper from "pages/Editor/Popper"; @@ -173,78 +173,91 @@ export function PreparedStatementViewer(props: { ); } -export function CurrentValueViewer(props: { - theme: EditorTheme; - evaluatedValue: any; - hideLabel?: boolean; - preparedStatementViewer?: boolean; -}) { - const currentValueWrapperRef = React.createRef(); - const codeWrapperRef = React.createRef(); +export const CurrentValueViewer = memo( + function CurrentValueViewer(props: { + theme: EditorTheme; + evaluatedValue: any; + hideLabel?: boolean; + preparedStatementViewer?: boolean; + }) { + const currentValueWrapperRef = React.createRef(); + const codeWrapperRef = React.createRef(); - let content = ( - - {"undefined"} - - - ); - if (props.evaluatedValue !== undefined) { - if ( - _.isObject(props.evaluatedValue) || - Array.isArray(props.evaluatedValue) - ) { - if (props.preparedStatementViewer) { + let content = ( + + {"undefined"} + + + ); + if (props.evaluatedValue !== undefined) { + if ( + _.isObject(props.evaluatedValue) || + Array.isArray(props.evaluatedValue) + ) { + if (props.preparedStatementViewer) { + content = ( + + + + + ); + } else { + const reactJsonProps = { + theme: + props.theme === EditorTheme.DARK ? "summerfruit" : "rjv-default", + name: null, + enableClipboard: false, + displayObjectSize: false, + displayDataTypes: false, + style: { + fontSize: "12px", + }, + collapsed: 2, + collapseStringsAfterLength: 20, + }; + content = ( + + ); + } + } else { content = ( - + {props.evaluatedValue === null + ? "null" + : props.evaluatedValue.toString()} ); - } else { - const reactJsonProps = { - theme: - props.theme === EditorTheme.DARK ? "summerfruit" : "rjv-default", - name: null, - enableClipboard: false, - displayObjectSize: false, - displayDataTypes: false, - style: { - fontSize: "12px", - }, - collapsed: 2, - collapseStringsAfterLength: 20, - }; - content = ; } - } else { - content = ( - - {props.evaluatedValue === null - ? "null" - : props.evaluatedValue.toString()} - - - ); } - } - return ( - <> - {!props.hideLabel && ( - - Evaluated Value - - )} - - <> - {content} - - - - - ); -} + return ( + <> + {!props.hideLabel && ( + + Evaluated Value + + )} + + <> + {content} + + + + + ); + }, + (prevProps, nextProps) => { + return ( + prevProps.theme === nextProps.theme && + prevProps.hideLabel === nextProps.hideLabel && + // Deep-compare evaluated values to ensure we only rerender + // when the array actually changes + _.isEqual(prevProps.evaluatedValue, nextProps.evaluatedValue) + ); + }, +); function PopoverContent(props: PopoverContentProps) { const typeTextRef = React.createRef();