Skip to content

Commit 73e5261

Browse files
authored
Merge pull request #128 from workfloworchestrator/1954-clone-deep
1954 clone deep
2 parents cadc77d + ce409ce commit 73e5261

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pydantic-forms': patch
3+
---
4+
5+
Fixes formInput values reference bug

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { FieldValues, useForm } from 'react-hook-form';
1616
import { Subscription } from 'react-hook-form/dist/utils/createSubject';
1717

1818
import i18next from 'i18next';
19+
import _ from 'lodash';
1920
import { z } from 'zod';
2021
import { zodI18nMap } from 'zod-i18n-map';
2122

@@ -309,7 +310,10 @@ function PydanticFormContextProvider({
309310

310311
const submitFormFn = useCallback(() => {
311312
setIsSending(true);
312-
addFormInputData(rhf?.getValues(), !!errorDetails);
313+
const rhfValues = rhf.getValues();
314+
// Note. If we don't use cloneDeep here we are adding a reference to the rhfValues
315+
// that changes on every change in the form and triggering effects before we want to.
316+
addFormInputData(_.cloneDeep(rhfValues), !!errorDetails);
313317
window.scrollTo(0, 0);
314318
}, [rhf, errorDetails, addFormInputData]);
315319

0 commit comments

Comments
 (0)