Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anyOf field incorrectly updating after change #1486

Closed
2 tasks done
SuriGill opened this issue Oct 16, 2019 · 4 comments
Closed
2 tasks done

anyOf field incorrectly updating after change #1486

SuriGill opened this issue Oct 16, 2019 · 4 comments

Comments

@SuriGill
Copy link
Contributor

Prerequisites

Description

Since updating to react 16, the anyOf field doesn't correctly update after receiving props. It will override the selected option incorrectly. This can be resolved by migrating to the componentDidUpdate method instead of the componentWillReceiveProps that's currently marked unsafe. componentWillReceiveProps will update state synchronously and componentDidUpdate will update state asynchronously.

Steps to Reproduce

  1. Go to anyOf field in storybook of the latest version of master
  2. Add a new entry and keep it selected as option 1 and enter some text in the input field
  3. Add another entry and select option 2 and enter some text in the input field
  4. Move the option 2 up in the array.
    anyOfError

Expected behavior

The array should have the two positions switched.

Actual behavior

The array only has one position switched correctly, while the other has the wrong selected option even though the state has been changed.

Version

v.1.8.0

@epicfaace
Copy link
Member

Just confirming -- is the same issue is happening with the latest code on the master branch (https://rjsf-team.github.io/react-jsonschema-form/)? We added in a few changes that might have fixed it in #1352

@SuriGill
Copy link
Contributor Author

Yes, when running the devserver playground of the latest version on the master branch with the changes from #1352, I still run into this problem.

@SuriGill
Copy link
Contributor Author

SuriGill commented Oct 22, 2019

I've also found another issue that is related to the anyOf schema incorrectly rendering. I was unsure if I should make another ticket or include it in this issue. The steps to reproduce:

  1. Go to anyOf field in storybook of the latest version of master
  2. Add two new entries in the items
  3. Move item one down
  4. Try typing in the second item
    anyOfError2

The expected behaviour is that the second item input should correctly update. However, the first item is updating and incorrectly at that as well.

This issue has to do with the schema not re-rendering after a change because the only prop that is changing is the idSchema which is not resolved in shouldComponentUpdate here:
https://github.com/rjsf-team/react-jsonschema-form/blob/master/src/components/fields/SchemaField.js#L413

@epicfaace
Copy link
Member

Fixed by #1491 and #1493.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants