From 3af63acbe39b01dedac43bb0cbbb7952e31b8d29 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Sun, 26 Jan 2025 23:57:47 +0530 Subject: [PATCH] feat: avoid re-run during rendering --- src/components/run/RunSettings.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/run/RunSettings.tsx b/src/components/run/RunSettings.tsx index 98cd5720..1f40f60e 100644 --- a/src/components/run/RunSettings.tsx +++ b/src/components/run/RunSettings.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { GenericModal } from "../ui/GenericModal"; import { MenuItem, TextField, Typography, Switch, FormControlLabel } from "@mui/material"; import { Dropdown } from "../ui/DropdownMui"; @@ -29,12 +29,17 @@ export const RunSettingsModal = ({ isOpen, handleStart, handleClose, isTask, par const [showInterpreterSettings, setShowInterpreterSettings] = useState(false); - const startImmediately = () => { - handleStart(settings); - }; + // Run immediately without modal if settings don't need to be shown + useEffect(() => { + if (!showInterpreterSettings) { + handleStart(settings); // Start the run + } + // Ensure this runs only when the component mounts or settings change + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [showInterpreterSettings]); + // Do not render the modal if settings are not shown if (!showInterpreterSettings) { - startImmediately(); return null; }