react-jsonschema-form
react-jsonschema-form copied to clipboard
Upgrading from v2 to v3 or v4 breaks preselection in `anyOf` schema
Prerequisites
- [x] I have read the documentation;
- [x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [x] I'm providing a couple of sample sandboxes demonstrating the issue.
Description
I'm not sure this is technically a bug, as I haven't found the broken behaviour documented anywhere. But it does work in v2
, breaks in v3.0.0+
and I consider it an essential feature.
Here is a working v2.5.1
. sandbox ... and here is a sandbox with identical code, but broken, because it runs on v3.0.0.
Steps to Reproduce
- Create an
anyOf
schema with two distinct types ofanyOf
items - Render a
<Form>
with this schema, andformData
exclusively corresponding to the second schema item
Expected (v2.5.1.
) behavior
Form renders with the second anyOf
item selected - the item matched by formData
Actual (v3.0.0
) behavior
Form always renders with the first anyOf
item selected - regardless of formData
not complying with the UI-selected schema
Hmm, do you know which change in v3 might have broken this?
-- Ashwin Ramaswami
On Mon, Mar 21, 2022 at 12:29 PM michal-kurz @.***> wrote:
Prerequisites
- I have read the documentation https://react-jsonschema-form.readthedocs.io/;
- In the case of a bug report, I understand that providing a SSCCE http://sscce.org/ example is tremendously useful to the maintainers.
- I'm providing a couple of sample sandboxes demonstrating the issue.
Description
I'm not sure this is technically a bug, as I haven't found the broken behaviour documented anywhere. But does work in v2, breaks in v3.0.0+ and I consider it an essential feature.
Here https://codesandbox.io/s/rjsf-anyof-broken-option-preselection-v2-5-1-8h76z?file=/src/Test.tsx is a working v2.5.1. sandbox ... and here https://codesandbox.io/s/rjsf-anyof-broken-option-preselection-v3-0-hbbikm?file=/src/Test.tsx is a sandbox with identical code, but broken, because it runs of v3.0.0. Steps to Reproduce
- Create an anyOf schema with two distinct type of anyOf items
- Render a <Form> with this schema, and formData exclusively corresponding to the second schema item
Expected (v2.5.1.) behavior
Form renders with the second anyOf item selected - the item matched by formData Actual (v3.0.0) behavior
Form always renderes with the first anyOf item selected - regardless of formData not complying with the UI-selected schema
— Reply to this email directly, view it on GitHub https://github.com/rjsf-team/react-jsonschema-form/issues/2773, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM4MXYWTA6URDVK6HZIWMLVBCPWDANCNFSM5RIHM2UA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
@epicfaace I have no idea, I haven't compared the code at all. But I suppose this part of migration docs might have something to do with it.
bump, also running into this - @michal-kurz did you find any workaround?
@ksbrar Unfortunately not, we're running on v2 for this reason, because this is critical for us.
@michal-kurz it would help if -- do you mind making a PR that includes a test that breaks due to this bug?
In this case it works on v2.5.1
because the list of enums has only one value. When we add more than one values in enum, default value also breaks.
@epicfaace I added a PR with test. Is there a way to fix this problem?
@andreySimonenko In your PR, when you change the default from ["<default value>"]
to "<default value>"
things work. I'm curious why are you providing an array of values as a default for a type that expects a single value.
Closing as not a bug. I'm guessing that the old 2.x code incorrectly allowed defaults of arrays when the type itself wasn't an array
@heath-freenome
For the record: I strongly believe this issue was closed incorrectly. The fact that we used an array is not relevant to the bug. If we use a simple string value for the default, the situation is the same:
- on
v 2.5.1
, the second item gets correctly pre-selected whenformData
only satisfies second item's shape - on
v 3.0.0
, the first item gets incorrectly pre-selected whenformData
only satisfies second item's shape
However on v5.3.1
, this works again, and now works as expected!! 🎉 🎉
Not sure what broke v3 and v4, but now we can migrate to v5, I'm happy :)
The API has really progressed a long way since, thank you very much the excellent work you're putting in this project! ❤️ And thanks to whoever fixed this issue.