react-jsonschema-form
react-jsonschema-form copied to clipboard
liveOmit & omitExtraData not work with empty oneOf
Prerequisites
- [X] I have searched the existing issues
- [X] I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [X] I have read the documentation
- [X] Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
What theme are you using?
core
Version
5.x
Current Behavior
With both liveOmit and omitExtraData set to true and a field with oneOf: [], changing form will cause error (playground reproduction):
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"style": {
"type": "string",
"oneOf": []
}
}
}
index-90aec295.js:43 Uncaught TypeError: Cannot use 'in' operator to search for '$ref' in undefined
at ug (index-90aec295.js:43:9733)
at ug (index-90aec295.js:43:9972)
at ug (index-90aec295.js:43:10407)
at Eet (index-90aec295.js:43:10484)
at Pet.toPathSchema (index-90aec295.js:43:11713)
at onChange (index-90aec295.js:64:28374)
at index-90aec295.js:64:5148
at index-90aec295.js:64:1174
at index-90aec295.js:64:5148
at index-90aec295.js:64:11289
After add an option to oneOf, it will work: playground
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"style": {
"type": "string",
"oneOf": [
{
"const": "abc"
}
]
}
}
}
Expected Behavior
change the form without error
Steps To Reproduce
- set both
liveOmitandomitExtraDataForm props totrue - set a field's schema to
oneOf: [] - change form values through other field
- error
Cannot use 'in' operator to search for '$ref' in undefined
Environment
- OS:
- Node:
- npm:
Anything else?
Maybe this line throw the error
https://github.com/rjsf-team/react-jsonschema-form/blob/d58775b444b04465a6ae01300e1f3e18e6145c95/packages/utils/src/schema/toPathSchema.ts#L41
@YuJianghao This is not a valid JSON Schema per the spec:
This keyword's value MUST be a non-empty array.
We can accept a PR to handle this case and log a warning if it would improve the experience of using RJSF