react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Form refresh issue after edit

Open qcalmel opened this issue 1 year ago • 12 comments

Hello, i've an issue when I edit a record : If I delete an existing field value, save form and just after, modify another field and save form again, my previous field to which I deleted the value, returns to its previous value. When form is refreshed after save, If I check the React Query dev tool, the data are however good It's occurs only when field value was previously set to null Little precision : I use Airtable as database, and records fields that are null are not retrieved from the record data

Steps to reproduce:

Environment

  • React-admin version: 4.14.4
  • Last version that did not exhibit the issue : 3.11.3 (yeah big jump 😅)
  • React version: 17.0.0
  • Browser: Chrome, Safari, Firefox

qcalmel avatar Oct 03 '23 10:10 qcalmel

I tried to reproduce your issue in the provided stackblitz without success. Can you double check your instructions?

djhi avatar Oct 03 '23 12:10 djhi

hi, a video is better than a long speech : https://jam.dev/c/e2986df8-780c-4152-969f-9d60132f1265 the bug occurs also if you use refresh button : https://jam.dev/c/480ecc35-a796-4f21-ba8e-2995d3efc2dc

qcalmel avatar Oct 03 '23 14:10 qcalmel

Finally reproduced it. Thanks. Tracked it to the fact that react-hook-form does not accept null nor undefined values (https://react-hook-form.com/docs/usecontroller). We should detect it however and sets the defaultValue to an empty string when we receive null.

In the mean time, you'll have to update your dataProvider to return an empty string for fields that are null and set them back to null in the update

djhi avatar Oct 03 '23 14:10 djhi

Data is lost on page refresh as well, for example :

  • [x] Input test in Name field
  • [x] Save
  • [x] Refresh the page

shavidze avatar Oct 04 '23 07:10 shavidze

About the above-mentioned issue:

The codebase is quite complex and large, what I guess is that save function in useEditController does not work as expected.

shavidze avatar Oct 04 '23 09:10 shavidze

Finally reproduced it. Thanks. Tracked it to the fact that react-hook-form does not accept null nor undefined values (https://react-hook-form.com/docs/usecontroller). We should detect it however and sets the defaultValue to an empty string when we receive null.

In the mean time, you'll have to update your dataProvider to return an empty string for fields that are null and set them back to null in the update

Thanks for temporary fix solution, i almost found this solution but I returned null value instead of empty string 😅

qcalmel avatar Oct 04 '23 15:10 qcalmel

@djhi we would like to work on this Issue.

gitstart avatar Oct 16 '23 10:10 gitstart

@gitstart you don't need our permission: you can open a PR mentioning this issue.

fzaninotto avatar Oct 16 '23 11:10 fzaninotto

@fzaninotto I tried to work on it but the project is very complex and with high level abstractions. My brain was burnt 😃

shavidze avatar Oct 16 '23 11:10 shavidze

@gitstart there are already 3 open PRs for your account (https://github.com/marmelab/react-admin/pulls/gitstart), for all of which changes are requested but not made. May I suggest your team starts by focusing on getting those PRs merged before attempting to open a new one?

slax57 avatar Oct 16 '23 12:10 slax57

@slax57 Apologies for not being able to address the requests. For this PR we addressed the query after that no reviews were given. In this PR we will try to rebase, if it doesn't work out will close this PR and push a new one against the next branch. Last PR will be reassigned and a solution will be pushed asap. Thank you for your cooperation.

gitstart avatar Oct 18 '23 07:10 gitstart

@gitstart I reviewed the 1st PR and requested some changes and fixes. Thanks.

slax57 avatar Oct 18 '23 11:10 slax57