From f48e9d988310541efa6d40aa4cdd12d054673618 Mon Sep 17 00:00:00 2001 From: Matheus Wichman Date: Mon, 9 Dec 2019 23:34:53 -0300 Subject: [PATCH] Fix cloned record reverts values when submitting --- cypress/integration/edit.js | 17 +++++++++++++++++ .../src/form/useInitializeFormWithRecord.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cypress/integration/edit.js b/cypress/integration/edit.js index b3006bd6305..fc045d9c070 100644 --- a/cypress/integration/edit.js +++ b/cypress/integration/edit.js @@ -146,6 +146,23 @@ describe('Edit Page', () => { ); }); + it('should not revert values when saving a record that was cloned', () => { + EditPostPage.navigate(); + cy.get(EditPostPage.elements.input('title')).should(el => + expect(el).to.have.value('Sed quo et et fugiat modi') + ); + + EditPostPage.clone(); + CreatePostPage.setInputValue('input', 'title', 'Lorem Ipsum'); + + // The next assertion has to occur immediately, thus CreatePostPage.submit() is not used + cy.get(CreatePostPage.elements.submitButton).click(); + + cy.get(CreatePostPage.elements.input('title')).then(el => { + expect(el).to.have.value('Lorem Ipsum'); + }); + }); + it('should persit emptied inputs', () => { EditPostPage.navigate(); EditPostPage.gotoTab(3); diff --git a/packages/ra-core/src/form/useInitializeFormWithRecord.ts b/packages/ra-core/src/form/useInitializeFormWithRecord.ts index 77a4828fafb..febfb420926 100644 --- a/packages/ra-core/src/form/useInitializeFormWithRecord.ts +++ b/packages/ra-core/src/form/useInitializeFormWithRecord.ts @@ -26,7 +26,7 @@ const useInitializeFormWithRecord = record => { } }); }); - }, [form, record]); + }, [form, JSON.stringify(record)]); // eslint-disable-line react-hooks/exhaustive-deps }; export default useInitializeFormWithRecord;