Skip to content

The new React lifecycle methods - breaking change #3953

@magaton

Description

@magaton

Prerequisites

What theme are you using?

mui

Is your feature request related to a problem? Please describe.

Up until version 5.13.2 our app, based on rjsf (mui) was working well. Exceptions are the issues I have already filed:

But with version 5.13.3 in Form.tsx UNSAFE_componentWillReceiveProps was replaced with: componentDidUpdate and getSnapshotBeforeUpdate.

Here is the gist of the problem. We have 3 screen admin UI, each with its own schema and UI schema. We also have a couple of custom select widgets that take a value from formData, do some calculations, and update the state (formData) with the result array.
The issue happens on the initial render of, e.g. 2nd screen, where based on the formData from the 1st screen we need to set defaults (update formData). With UNSAFE_componentWillReceiveProps, it was working well, namely when our custom selects fired, the change was detected in UNSAFE_componentWillReceiveProps and the screen was re-rendered, but now, componentDidUpdate is not called on the initial render (as described in jsdocs and react docs).

I understand that the main use case supported by the current design is to change state based on onChange property in the <Form>, but in our case (initial render), there is no onChange event. We read passed formData in the custom widget, do the calculation, and update the state that is then used for conditional schemas on the 2nd screen.

What would be the recommended way to force re-render in our custom select widget, now that there is no UNSAFE_componentWillReceiveProps?

We feel stuck :(
I filed this issue as a feature since it is related to our multi-form scenario with custom widgets, so not really a common use case. Sorry, if not appropriate.

Thanks very much in advance!

Describe the solution you'd like

Any idea/workaround/feature-switch that would allow re-rendering from our custom widgets.

Describe alternatives you've considered

We are not a react shop, so most of our investigation was chasing our own tail. We have tried:

  • adding static getDerivedState, no luck
  • force props.onChange in our custom select which seems to help, but this results with a React warning and smells badly
  • detect the initial render with useRef - it does help when our custom select works with the previous formData, but we also have a custom select that needs both previous formData and specific fields on the 2nd form filled (so it is not just initial render, that we need to handle).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions