Skip to content

Commit

Permalink
WP-778: Fix infinite loop for state update in useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc committed Nov 26, 2024
1 parent 16ed8e2 commit c1c4ecd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions client/src/components/Applications/AppForm/AppForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -171,24 +170,23 @@ const HandleDependentFieldChanges = ({ app, formStateUpdateHandler }) => {
updatedValues,
formStateUpdateHandler
);
valueUpdated = true;
}
if (previousValues.execSystemId !== values.execSystemId) {
updatedValues = execSystemChangeHandler(
app,
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]);
Expand Down Expand Up @@ -926,6 +924,7 @@ export const AppSchemaForm = ({ app }) => {
) : null}
</div>
<Button
id="submit"
attr="submit"
size="medium"
type="primary"
Expand All @@ -936,6 +935,7 @@ export const AppSchemaForm = ({ app }) => {
Submit
</Button>
<Button
id="reset"
onClick={handleReset}
className="btn-resetForm"
type="link"
Expand Down
1 change: 1 addition & 0 deletions client/src/components/_common/Form/FormField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const FormField = ({

<InputGroup>
<Button
size="middle"
type="secondary"
onClick={() => setOpenTapisFileModal(true)}
>
Expand Down

0 comments on commit c1c4ecd

Please sign in to comment.