From 782515b3952fdb4c97f2f124615fb30788c341ed Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Thu, 1 Aug 2024 17:22:52 +0200 Subject: [PATCH] enh: improve viz responsiveness and remove unnecessary renders --- .../actions/VisualizationActionIframe.tsx | 28 +++++++++---------- front/lib/api/assistant/visualization.ts | 12 +++++--- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/front/components/assistant/conversation/actions/VisualizationActionIframe.tsx b/front/components/assistant/conversation/actions/VisualizationActionIframe.tsx index 0e27c296c686a..f46c9100dbefd 100644 --- a/front/components/assistant/conversation/actions/VisualizationActionIframe.tsx +++ b/front/components/assistant/conversation/actions/VisualizationActionIframe.tsx @@ -133,9 +133,7 @@ export function VisualizationActionIframe({ onRetry: () => void; }) { - const [contentHeight, setContentHeight] = useState(0); - const [iframeLoaded, setIframeLoaded] = useState(false); - const [showSpinner, setShowSpinner] = useState(true); + const [contentHeight, setContentHeight] = useState(0); const [activeIndex, setActiveIndex] = useState(1); const vizIframeRef = useRef(null); @@ -154,21 +152,17 @@ export function VisualizationActionIframe({ const { code, complete: codeFullyGenerated } = visualization; + const iframeLoaded = contentHeight > 0; + const showSpinner = + (!codeFullyGenerated && !code) || (codeFullyGenerated && !iframeLoaded); + useEffect(() => { if (!codeFullyGenerated) { - // Display spinner over the code block while waiting for code generation. - setShowSpinner(!code); setActiveIndex(0); - } else if (iframeLoaded) { - // Display iframe if code is generated and iframe has loaded. - setShowSpinner(false); - setActiveIndex(1); } else { - // Show spinner while iframe is loading. - setShowSpinner(true); setActiveIndex(1); } - }, [codeFullyGenerated, code, iframeLoaded]); + }, [codeFullyGenerated, code]); useEffect(() => { if (!containerRef.current) { @@ -202,7 +196,8 @@ export function VisualizationActionIframe({
@@ -221,7 +216,11 @@ export function VisualizationActionIframe({
{codeFullyGenerated && (