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;