Received form data and retrieved schemas are shared and must not be mutated
Detect
- In your code: a schema returned by
retrieveSchema()orschemaUtils.retrieveSchema()that you change in place, such as by assigning to itsproperties. - In your
onChange,onBluroronSubmithandlers: in-place writes into the receivedformData.
Change
The formData you receive from onChange, onBlur, onSubmit and the other callbacks shares unchanged subtrees with the previous value, the formData you passed included, so mutating it in place corrupts your own state. Treat it as immutable; Form data is deep-frozen in development covers what to change.
Schemas returned by retrieveSchema() are shared the same way: it may return the same instance across calls. Copy one before changing it:
const retrieved = schemaUtils.retrieveSchema(schema, formData);
-retrieved.title = 'Address';
+const titled = { ...retrieved, title: 'Address' };
The root schema is treated as immutable too; see A root schema changed in place is not read again.
Verify
- A schema you change is a copy, and later
retrieveSchema()calls return the unchanged schema.
Also read: