From eda63fe6880b6dfcfb49d2a8bc2a11e84b533b72 Mon Sep 17 00:00:00 2001 From: Ashit Rath Date: Mon, 26 Aug 2024 14:52:58 +0530 Subject: [PATCH] chore: JSONform - useRegisterFieldValidity remove unused dependency in useEffect (#35869) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Removes unused dependency in `useRegisterFieldValidity` of JSONForm Introduced in https://github.com/appsmithorg/appsmith/pull/35717 ## Automation /ok-to-test tags="@tag.JSONForm" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: e59355e8484e4dd0707d6c0b7a13b0b96b2b3507 > Cypress dashboard. > Tags: `@tag.JSONForm` > Spec: >
Mon, 26 Aug 2024 06:45:22 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **Performance Improvements** - Optimized the `useRegisterFieldValidity` function by reducing the number of dependencies in its `useEffect` hook, potentially enhancing performance by minimizing unnecessary updates. - **Bug Fixes** - Streamlined control flow for error handling within the `useRegisterFieldValidity` function to ensure consistent behavior when validating fields and managing errors. --- .../fields/useRegisterFieldValidity.ts | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts b/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts index 663afb547a..58c2811ebd 100644 --- a/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts +++ b/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts @@ -35,31 +35,25 @@ function useRegisterFieldValidity({ */ setTimeout(() => { try { - isValid - ? startAndEndSpanForFn("JSONFormWidget.clearErrors", {}, () => { - if (error) { - clearErrors(fieldName); - } - }) - : startAndEndSpanForFn("JSONFormWidget.setError", {}, () => { - setError(fieldName, { - type: fieldType, - message: "Invalid field", - }); + if (isValid) { + if (error) { + startAndEndSpanForFn("JSONFormWidget.clearErrors", {}, () => { + clearErrors(fieldName); }); + } + } else { + startAndEndSpanForFn("JSONFormWidget.setError", {}, () => { + setError(fieldName, { + type: fieldType, + message: "Invalid field", + }); + }); + } } catch (e) { Sentry.captureException(e); } }, 0); - }, [ - isValid, - fieldName, - fieldType, - setMetaInternalFieldState, - error, - clearErrors, - setError, - ]); + }, [isValid, fieldName, fieldType, error, clearErrors, setError]); useEffect(() => { setMetaInternalFieldState((prevState) => {