react-jsonschema-form
react-jsonschema-form copied to clipboard
Optimizations to improve performance on complex conditional schemas
~I've picked up from where #1666 has left off, hoping that the work I've done so far will be enough to add this feature.~
~In addition to the changes outlined in #1666, I've tried to address changes requested in that review, and fix a few other issues as well.~
~Here's a link to just the changes that I've personally made since I branched from the work in #1666~
Since conditional support was added in #2700, this branch only exists to preserve the optimizations I've done to improve performance in complex schemas. We struggle with performance on complex conditional schemas because we re-run validation on every input change to determine if the condition has changed. Presently, I've worked around this with lots of memoization and attempts to get ajv to use its internal cache, but we could probably do this better/smarter than what I've done so far.
Checklist
- [ ] I'm updating documentation
- [ ] I've checked the rendering of the Markdown text I've added
- [X] I'm adding or updating code
- [X] I've added and/or updated tests
- [ ] I've updated docs if needed
- [X] I'm adding a new feature
- [X] I've updated the playground with an example use of the feature
Converting this PR to a draft because while I think my changes in 78fc62c (#2466) are a step forward, I think it's going to break some things and I don't want to indicate that this should be merged as-is without more tests (in addition to fixing the ones that fail).
I tried it out a bit and I think this looks great! If we can get it in a mergeable state where only the if-then-else changes are included in this PR, I think we are pretty close.
A few comments:
- Currently if you type a value in a conditional field, and then change the parent such that the field is removed, the value is still included in formData and will be submitted, unless
additionalProperties: falseis included. Is this the preferred behaviour? I can see pros and cons of both resetting the value of the formData and including it, but I'm leaning towards resetting the values. - The memoization changes seem to cause issues when omitExtraData is set to true - I'm getting "maximum call size exceeded". See attached screenshot.

Thanks for taking a look @jimmycallin!
Currently if you type a value in a conditional field, and then change the parent such that the field is removed, the value is still included in formData and will be submitted, unless
additionalProperties: falseis included. Is this the preferred behaviour? I can see pros and cons of both resetting the value of the formData and including it, but I'm leaning towards resetting the values.
For my use case, I need the option to keep data as an additional property if its field is removed. As our users fill out the form, we want to be as nondestructive as possible with their data, and give them the opportunity to 'backtrack' without having to re-fill fields that they may have already completed.
Shouldn't this concern be handled by omitExtraData and liveOmit? It seems like liveOmit is working properly (except for your concern) ~~, but nothing is being omitted on submit if liveOmit is false, so that will need to be fixed (I'm actually seeing this issue in the current playground version 😬)~~ . I'm also not actually seeing a difference in behavior when I change additionalProperties like you note.
The memoization changes seem to cause issues when omitExtraData is set to true - I'm getting "maximum call size exceeded". See attached screenshot.
Good catch, and thanks for attaching the stack trace! I'm having trouble reproducing this, but you guided me to find that I can't actually change the data in the "All Of If Then Else" example if liveOmit is true. Possible that these are related issues.
Edit: I realize now that unless liveOmit is enabled, omitExtraData applies only to the submitted data and not the formData.
Thanks for that PR @nickgros 🎉
Is there anything I can help you with to be able to complete this feature? Would love to this merged sooner than later
I need support for if-then-else and it's great to see there's a PR, but appears stalled. Anything I can help with?
I don't yet want to close this because I think there's still some value in my changes, but I think https://github.com/rjsf-team/react-jsonschema-form/pull/2506 is a better foundation. I'll see if I can integrate those changes into this PR (and in doing so, see if there's a meaningful difference in behavior between how these handle if/then/else)
@nickgros Does it make sense to rethink these changes on top of the v5 beta's @rjsf/validator-ajv8?
This is probably not the right way to optimize validation. Closing