Skip to content

Commit 885c8bc

Browse files
authored
fix(client): circular function calls leads to memory leak (#1049)
* fix(client): circular function call leads to memory leak * allow children validation
1 parent fc7897f commit 885c8bc

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

client/src/components/DynamicJsonForm.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface DynamicJsonFormProps {
2828

2929
export interface DynamicJsonFormRef {
3030
validateJson: () => { isValid: boolean; error: string | null };
31+
hasJsonError: () => boolean;
3132
}
3233

3334
const isTypeSupported = (
@@ -129,6 +130,10 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(
129130
// on every keystroke which would be inefficient and error-prone
130131
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
131132

133+
const hasJsonError = () => {
134+
return !!jsonError;
135+
};
136+
132137
// Debounce JSON parsing and parent updates to handle typing gracefully
133138
const debouncedUpdateParent = useCallback(
134139
(jsonString: string) => {
@@ -253,6 +258,7 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(
253258

254259
useImperativeHandle(ref, () => ({
255260
validateJson,
261+
hasJsonError,
256262
}));
257263

258264
const renderFormFields = (

client/src/components/ToolsTab.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ const ToolsTab = ({
102102
const { copied, setCopied } = useCopy();
103103

104104
// Function to check if any form has validation errors
105-
const checkValidationErrors = () => {
105+
const checkValidationErrors = (validateChildren: boolean = false) => {
106106
const errors = Object.values(formRefs.current).some(
107-
(ref) => ref && !ref.validateJson().isValid,
107+
(ref) =>
108+
ref &&
109+
(validateChildren ? !ref.validateJson().isValid : ref.hasJsonError()),
108110
);
109111
setHasValidationErrors(errors);
110112
return errors;
@@ -675,7 +677,7 @@ const ToolsTab = ({
675677
<Button
676678
onClick={async () => {
677679
// Validate JSON inputs before calling tool
678-
if (checkValidationErrors()) return;
680+
if (checkValidationErrors(true)) return;
679681

680682
try {
681683
setIsToolRunning(true);

0 commit comments

Comments
 (0)