react-admin
react-admin copied to clipboard
Form refresh issue after edit
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:
-
Select a record from post list
-
if "Name" input was empty, add value, save form, and refresh stackblitz render window
-
delete "Name" value
-
save form
-
change value of checkbox
-
save form
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
I tried to reproduce your issue in the provided stackblitz without success. Can you double check your instructions?
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
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
Data is lost on page refresh as well, for example :
- [x] Input
test
inName field
- [x] Save
- [x] Refresh the page
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.
Finally reproduced it. Thanks. Tracked it to the fact that react-hook-form does not accept
null
norundefined
values (https://react-hook-form.com/docs/usecontroller). We should detect it however and sets thedefaultValue
to an empty string when we receivenull
.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 tonull
in theupdate
Thanks for temporary fix solution, i almost found this solution but I returned null value instead of empty string 😅
@djhi we would like to work on this Issue.
@gitstart you don't need our permission: you can open a PR mentioning this issue.
@fzaninotto I tried to work on it but the project is very complex and with high level abstractions. My brain was burnt 😃
@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 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 I reviewed the 1st PR and requested some changes and fixes. Thanks.