From d6d9f37bb39a7ff9f49418feecef58923b957dec Mon Sep 17 00:00:00 2001 From: Chandra Y Date: Wed, 27 Nov 2024 10:56:57 -0600 Subject: [PATCH] WP-778: Fix infinite loop for state update in useEffect (#1019) * WP-778: Fix infinite loop for state update in useEffect * remove unnecessary changes --- client/src/components/Applications/AppForm/AppForm.jsx | 8 +++----- client/src/components/_common/Form/FormField.jsx | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/client/src/components/Applications/AppForm/AppForm.jsx b/client/src/components/Applications/AppForm/AppForm.jsx index ddb106435..e2372c24c 100644 --- a/client/src/components/Applications/AppForm/AppForm.jsx +++ b/client/src/components/Applications/AppForm/AppForm.jsx @@ -152,7 +152,6 @@ const HandleDependentFieldChanges = ({ app, formStateUpdateHandler }) => { const { values, setValues } = useFormikContext(); React.useEffect(() => { if (previousValues) { - let valueUpdated = false; let updatedValues = { ...values }; // Set the current allocation @@ -171,7 +170,6 @@ const HandleDependentFieldChanges = ({ app, formStateUpdateHandler }) => { updatedValues, formStateUpdateHandler ); - valueUpdated = true; } if (previousValues.execSystemId !== values.execSystemId) { updatedValues = execSystemChangeHandler( @@ -179,16 +177,16 @@ const HandleDependentFieldChanges = ({ app, formStateUpdateHandler }) => { values, formStateUpdateHandler ); - valueUpdated = true; } if ( previousValues.execSystemLogicalQueue !== values.execSystemLogicalQueue ) { updatedValues = updateValuesForQueue(app, values); - valueUpdated = true; } - if (valueUpdated) setValues(updatedValues); + if (JSON.stringify(updatedValues) !== JSON.stringify(values)) { + setValues(updatedValues); + } } setPreviousValues(values); }, [app, values, setValues, formStateUpdateHandler]); diff --git a/client/src/components/_common/Form/FormField.jsx b/client/src/components/_common/Form/FormField.jsx index 1e5dbc7a1..412d14dea 100644 --- a/client/src/components/_common/Form/FormField.jsx +++ b/client/src/components/_common/Form/FormField.jsx @@ -138,6 +138,7 @@ const FormField = ({