marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.89k stars 5.23k forks source link

Use of FormDataConsumer with a disabled TextInput creates a bad setState() #9615

Closed Revarh closed 7 months ago

Revarh commented 8 months ago

What you were expecting: I am using SimpleForm and I want to use FormDataConsumer to update inputs.

What happened instead: When I use FormDataConsumer along with a disabled props in a TextInput, it creates a bad setState() and breaks my form:

Warning: Cannot update a component (SaveButton) while rendering a different component (TextInput). To locate the bad setState() call inside TextInput, follow the stack trace as described in https://reactjs.org/link/setstate-in-render

Steps to reproduce: Create an editing form, use FormDataConsumer and then disable a textInput.

Other information: You can try the bug here: https://github.com/Revarh/test_bug_react-admin Use yarn, then yarn start

Environment

nicofrand commented 8 months ago

I have a similar issue where the data passed to my provider has my disabled field set to undefined.

Revarh commented 8 months ago

I added a test repo to my original query. Thank you everyone!

aMahdaoui commented 8 months ago

Same behavior while trying to update Firebase document :

barecode property received as undefined when TextInput is disabled

FirebaseError: [code=invalid-argument]: Function updateDoc() called with invalid data.
Unsupported field value: undefined (found in field bareCode in document products/cvbz95WZmSZhAT5vHjQl)
adguernier commented 8 months ago

Thanks for this report, after investigating, I can reproduce and see the error in the console. It seems this issue in related to #9498.

Until it fixed, you can prevent this error by setting disabled in InputProps, such as: <TextInput source="id" fullWidth InputProps={{ disabled: true }} />

slax57 commented 8 months ago

Quick update: I spent half a day trying to figure out what exactly is causing this warning, and how to work around it, but with no luck. I'm pretty convinced this is due to a state mismanagement in the react-hook-form library, consecutive to the change they recently made in the way the disabled inputs are handled. But I couldn't reproduce it in a RHF only sandbox so far...

Nevertheless, this issue will probably be resolved along when we address issue #9498, which will require some time because we will probably need to implement support for the readOnly prop on all inputs.

slax57 commented 7 months ago

Fixed by https://github.com/marmelab/react-admin/pull/9656