From a9d8e05c42bb33bcc76140195fe903432120331c Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Sat, 22 Aug 2020 14:36:43 +0200 Subject: [PATCH 1/6] refactor: form.jsx is no longer using componentwillreceiveprops --- packages/antd/package-lock.json | 6 +- packages/core/src/components/Form.js | 163 +++++---------------------- packages/core/src/utils.js | 114 ++++++++++++++++++- 3 files changed, 144 insertions(+), 139 deletions(-) diff --git a/packages/antd/package-lock.json b/packages/antd/package-lock.json index f2c1cf2968..39783547bc 100644 --- a/packages/antd/package-lock.json +++ b/packages/antd/package-lock.json @@ -3885,9 +3885,9 @@ } }, "@rjsf/core": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/@rjsf/core/-/core-2.2.2.tgz", - "integrity": "sha512-4d6DHIiTJEkUq5vyl4LIxLGIYYKKnHcprf94oVchUtGQvRFjNUDFxeFQoyr90oaxcBMs2WDDcCgjcFaKVyfErg==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@rjsf/core/-/core-2.3.0.tgz", + "integrity": "sha512-OZKYHt9tjKhzOH4CvsPiCwepuIacqI++cNmnL2fsxh1IF+uEWGlo3NLDWhhSaBbOv9jps6a5YQcLbLtjNuSwug==", "dev": true, "requires": { "@babel/runtime-corejs2": "^7.8.7", diff --git a/packages/core/src/components/Form.js b/packages/core/src/components/Form.js index d9061270db..ddad8dd79a 100644 --- a/packages/core/src/components/Form.js +++ b/packages/core/src/components/Form.js @@ -6,18 +6,23 @@ import _isEmpty from "lodash/isEmpty"; import { default as DefaultErrorList } from "./ErrorList"; import { - getDefaultFormState, retrieveSchema, shouldRender, - toIdSchema, - getDefaultRegistry, deepEquals, toPathSchema, isObject, + getRegistry, + validate, + getStateFromProps, } from "../utils"; -import validateFormData, { toErrorList } from "../validate"; +import { toErrorList } from "../validate"; import { mergeObjects } from "../utils"; +function handleChange(props, state) { + const { lastProps, ...formState } = state; + props.onChange(formState); +} + export default class Form extends Component { static defaultProps = { uiSchema: {}, @@ -31,134 +36,38 @@ export default class Form extends Component { constructor(props) { super(props); - this.state = this.getStateFromProps(props, props.formData); + this.state = getStateFromProps(props, props.formData); + } + + formElement = null; + + componentDidMount() { if ( this.props.onChange && !deepEquals(this.state.formData, this.props.formData) ) { - this.props.onChange(this.state); + handleChange(this.props, this.state); } - this.formElement = null; } - - UNSAFE_componentWillReceiveProps(nextProps) { - const nextState = this.getStateFromProps(nextProps, nextProps.formData); + componentDidUpdate(prevProps) { if ( - !deepEquals(nextState.formData, nextProps.formData) && - !deepEquals(nextState.formData, this.state.formData) && - this.props.onChange + this.props.onChange && + !deepEquals(this.state.formData, this.props.formData) ) { - this.props.onChange(nextState); + handleChange(this.props, this.state); } - this.setState(nextState); } - getStateFromProps(props, inputFormData) { - const state = this.state || {}; - const schema = "schema" in props ? props.schema : this.props.schema; - const uiSchema = "uiSchema" in props ? props.uiSchema : this.props.uiSchema; - const edit = typeof inputFormData !== "undefined"; - const liveValidate = - "liveValidate" in props ? props.liveValidate : this.props.liveValidate; - const mustValidate = edit && !props.noValidate && liveValidate; - const rootSchema = schema; - const formData = getDefaultFormState(schema, inputFormData, rootSchema); - const retrievedSchema = retrieveSchema(schema, rootSchema, formData); - const customFormats = props.customFormats; - const additionalMetaSchemas = props.additionalMetaSchemas; - - const getCurrentErrors = () => { - if (props.noValidate) { - return { errors: [], errorSchema: {} }; - } else if (!props.liveValidate) { - return { - errors: state.schemaValidationErrors || [], - errorSchema: state.schemaValidationErrorSchema || {}, - }; - } - return { - errors: state.errors || [], - errorSchema: state.errorSchema || {}, - }; - }; - - let errors, - errorSchema, - schemaValidationErrors, - schemaValidationErrorSchema; - if (mustValidate) { - const schemaValidation = this.validate( - formData, - schema, - additionalMetaSchemas, - customFormats - ); - errors = schemaValidation.errors; - errorSchema = schemaValidation.errorSchema; - schemaValidationErrors = errors; - schemaValidationErrorSchema = errorSchema; - } else { - const currentErrors = getCurrentErrors(); - errors = currentErrors.errors; - errorSchema = currentErrors.errorSchema; - schemaValidationErrors = state.schemaValidationErrors; - schemaValidationErrorSchema = state.schemaValidationErrorSchema; - } - if (props.extraErrors) { - errorSchema = mergeObjects( - errorSchema, - props.extraErrors, - !!"concat arrays" - ); - errors = toErrorList(errorSchema); - } - const idSchema = toIdSchema( - retrievedSchema, - uiSchema["ui:rootFieldId"], - rootSchema, - formData, - props.idPrefix - ); - const nextState = { - schema, - uiSchema, - idSchema, - formData, - edit, - errors, - errorSchema, - additionalMetaSchemas, - }; - if (schemaValidationErrors) { - nextState.schemaValidationErrors = schemaValidationErrors; - nextState.schemaValidationErrorSchema = schemaValidationErrorSchema; + static getDerivedStateFromProps(props, state) { + if (!deepEquals(state.lastProps, props)) { + return getStateFromProps(props, props.formData, state); } - return nextState; } shouldComponentUpdate(nextProps, nextState) { return shouldRender(this, nextProps, nextState); } - validate( - formData, - schema = this.props.schema, - additionalMetaSchemas = this.props.additionalMetaSchemas, - customFormats = this.props.customFormats - ) { - const { validate, transformErrors } = this.props; - const { rootSchema } = this.getRegistry(); - const resolvedSchema = retrieveSchema(schema, rootSchema, formData); - return validateFormData( - formData, - resolvedSchema, - validate, - transformErrors, - additionalMetaSchemas, - customFormats - ); - } - renderErrors() { const { errors, errorSchema, schema, uiSchema } = this.state; const { ErrorList, showErrorList, formContext } = this.props; @@ -222,7 +131,7 @@ export default class Form extends Component { onChange = (formData, newErrorSchema) => { if (isObject(formData) || Array.isArray(formData)) { - const newState = this.getStateFromProps(this.props, formData); + const newState = getStateFromProps(this.props, formData, this.state); formData = newState.formData; } const mustValidate = !this.props.noValidate && this.props.liveValidate; @@ -251,7 +160,7 @@ export default class Form extends Component { } if (mustValidate) { - let schemaValidation = this.validate(newFormData); + let schemaValidation = validate(newFormData, this.props); let errors = schemaValidation.errors; let errorSchema = schemaValidation.errorSchema; const schemaValidationErrors = errors; @@ -287,7 +196,7 @@ export default class Form extends Component { } this.setState( state, - () => this.props.onChange && this.props.onChange(this.state) + () => this.props.onChange && handleChange(this.props, this.state) ); }; @@ -331,7 +240,7 @@ export default class Form extends Component { } if (!this.props.noValidate) { - let schemaValidation = this.validate(newFormData); + let schemaValidation = validate(newFormData, this.props); let errors = schemaValidation.errors; let errorSchema = schemaValidation.errorSchema; const schemaValidationErrors = errors; @@ -387,22 +296,6 @@ export default class Form extends Component { ); }; - getRegistry() { - // For BC, accept passed SchemaField and TitleField props and pass them to - // the "fields" registry one. - const { fields, widgets } = getDefaultRegistry(); - return { - fields: { ...fields, ...this.props.fields }, - widgets: { ...widgets, ...this.props.widgets }, - ArrayFieldTemplate: this.props.ArrayFieldTemplate, - ObjectFieldTemplate: this.props.ObjectFieldTemplate, - FieldTemplate: this.props.FieldTemplate, - definitions: this.props.schema.definitions || {}, - rootSchema: this.props.schema, - formContext: this.props.formContext || {}, - }; - } - submit() { if (this.formElement) { this.formElement.dispatchEvent( @@ -434,7 +327,7 @@ export default class Form extends Component { } = this.props; const { schema, uiSchema, formData, errorSchema, idSchema } = this.state; - const registry = this.getRegistry(); + const registry = getRegistry(this.props); const _SchemaField = registry.fields.SchemaField; const FormTag = tagName ? tagName : "form"; if (deprecatedAutocomplete) { diff --git a/packages/core/src/utils.js b/packages/core/src/utils.js index e6c8a147bd..6d39791a1f 100644 --- a/packages/core/src/utils.js +++ b/packages/core/src/utils.js @@ -2,7 +2,7 @@ import React from "react"; import * as ReactIs from "react-is"; import mergeAllOf from "json-schema-merge-allof"; import fill from "core-js/library/fn/array/fill"; -import validateFormData, { isValid } from "./validate"; +import validateFormData, { isValid, toErrorList } from "./validate"; import union from "lodash/union"; import jsonpointer from "jsonpointer"; @@ -1243,3 +1243,115 @@ export function schemaRequiresTrueValue(schema) { return false; } + +export function getRegistry(props) { + const { fields, widgets } = getDefaultRegistry(); + return { + fields: { ...fields, ...props.fields }, + widgets: { ...widgets, ...props.widgets }, + ArrayFieldTemplate: props.ArrayFieldTemplate, + ObjectFieldTemplate: props.ObjectFieldTemplate, + FieldTemplate: props.FieldTemplate, + definitions: props.schema.definitions || {}, + rootSchema: props.schema, + formContext: props.formContext || {}, + }; +} + +export function validate( + formData, + props, + schema = props.schema, + additionalMetaSchemas = props.additionalMetaSchemas, + customFormats = props.customFormats +) { + const { validate, transformErrors } = props; + const { rootSchema } = getRegistry(props); + const resolvedSchema = retrieveSchema(schema, rootSchema, formData); + return validateFormData( + formData, + resolvedSchema, + validate, + transformErrors, + additionalMetaSchemas, + customFormats + ); +} + +export function getStateFromProps(props, inputFormData, state = {}) { + const edit = typeof inputFormData !== "undefined"; + const mustValidate = edit && !props.noValidate && props.liveValidate; + const formData = getDefaultFormState( + props.schema, + inputFormData, + props.schema + ); + const retrievedSchema = retrieveSchema(props.schema, props.schema, formData); + + const getCurrentErrors = () => { + if (props.noValidate) { + return { errors: [], errorSchema: {} }; + } else if (!props.liveValidate) { + return { + errors: state.schemaValidationErrors || [], + errorSchema: state.schemaValidationErrorSchema || {}, + }; + } + return { + errors: state.errors || [], + errorSchema: state.errorSchema || {}, + }; + }; + + let errors, errorSchema, schemaValidationErrors, schemaValidationErrorSchema; + if (mustValidate) { + const schemaValidation = validate( + formData, + props, + props.schema, + props.additionalMetaSchemas, + props.customFormats + ); + errors = schemaValidation.errors; + errorSchema = schemaValidation.errorSchema; + schemaValidationErrors = errors; + schemaValidationErrorSchema = errorSchema; + } else { + const currentErrors = getCurrentErrors(); + errors = currentErrors.errors; + errorSchema = currentErrors.errorSchema; + schemaValidationErrors = state.schemaValidationErrors; + schemaValidationErrorSchema = state.schemaValidationErrorSchema; + } + if (props.extraErrors) { + errorSchema = mergeObjects( + errorSchema, + props.extraErrors, + !!"concat arrays" + ); + errors = toErrorList(errorSchema); + } + const idSchema = toIdSchema( + retrievedSchema, + props.uiSchema["ui:rootFieldId"], + props.schema, + formData, + props.idPrefix + ); + const nextState = { + schema: props.schema, + uiSchema: props.uiSchema, + idSchema, + formData, + edit, + errors, + errorSchema, + additionalMetaSchemas: props.additionalMetaSchemas, + lastProps: props, + }; + if (schemaValidationErrors) { + nextState.schemaValidationErrors = schemaValidationErrors; + nextState.schemaValidationErrorSchema = schemaValidationErrorSchema; + } + return nextState; +} From 2d3501933f5302f1d210cb53bc6828597290b735 Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Wed, 26 Aug 2020 11:21:54 +0200 Subject: [PATCH 2/6] return null from getDerivedStateFromProps as default --- packages/core/src/components/Form.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/components/Form.js b/packages/core/src/components/Form.js index ddad8dd79a..3328281704 100644 --- a/packages/core/src/components/Form.js +++ b/packages/core/src/components/Form.js @@ -62,6 +62,7 @@ export default class Form extends Component { if (!deepEquals(state.lastProps, props)) { return getStateFromProps(props, props.formData, state); } + return null; } shouldComponentUpdate(nextProps, nextState) { From 33aee981bdc6d919483b12f88620b3b5e1940db0 Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Mon, 31 Aug 2020 22:18:52 +0200 Subject: [PATCH 3/6] change deepEquals to shallow equals in getDerivedStateFromProps --- packages/core/src/components/Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/components/Form.js b/packages/core/src/components/Form.js index 3328281704..e23210ac6e 100644 --- a/packages/core/src/components/Form.js +++ b/packages/core/src/components/Form.js @@ -59,7 +59,7 @@ export default class Form extends Component { } static getDerivedStateFromProps(props, state) { - if (!deepEquals(state.lastProps, props)) { + if (state.lastProps !== props) { return getStateFromProps(props, props.formData, state); } return null; From 4532e453eee27cba11143d2c7a6a97039fe24649 Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Mon, 31 Aug 2020 23:53:34 +0200 Subject: [PATCH 4/6] checking each key for shallow changes in getDerivedStateFromProps --- packages/core/src/components/Form.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/components/Form.js b/packages/core/src/components/Form.js index e23210ac6e..8a727aed2d 100644 --- a/packages/core/src/components/Form.js +++ b/packages/core/src/components/Form.js @@ -59,7 +59,10 @@ export default class Form extends Component { } static getDerivedStateFromProps(props, state) { - if (state.lastProps !== props) { + if ( + Object.keys(props).length !== Object.keys(state.lastProps).length || + Object.keys(props).some(key => state.lastProps[key] != props[key]) + ) { return getStateFromProps(props, props.formData, state); } return null; From a40ce1618933a86bd65b7aef497b771a00666733 Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Sun, 27 Feb 2022 13:39:58 +0100 Subject: [PATCH 5/6] Revert change for deepEquals function --- packages/core/src/components/Form.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/src/components/Form.js b/packages/core/src/components/Form.js index 8a727aed2d..3f6063a05c 100644 --- a/packages/core/src/components/Form.js +++ b/packages/core/src/components/Form.js @@ -59,10 +59,7 @@ export default class Form extends Component { } static getDerivedStateFromProps(props, state) { - if ( - Object.keys(props).length !== Object.keys(state.lastProps).length || - Object.keys(props).some(key => state.lastProps[key] != props[key]) - ) { + if (!deepEquals(props, state.lastProps)) { return getStateFromProps(props, props.formData, state); } return null; From ed618c92f7ce4e2086f47500272c14d7f74b4a11 Mon Sep 17 00:00:00 2001 From: Jimmy Callin Date: Sun, 27 Feb 2022 13:52:48 +0100 Subject: [PATCH 6/6] moved util functions back as static functions to Form --- packages/core/src/components/Form.js | 139 +++++++++++++++++++++++++-- packages/core/src/utils.js | 114 +--------------------- 2 files changed, 130 insertions(+), 123 deletions(-) diff --git a/packages/core/src/components/Form.js b/packages/core/src/components/Form.js index 3f6063a05c..db48f58b67 100644 --- a/packages/core/src/components/Form.js +++ b/packages/core/src/components/Form.js @@ -6,16 +6,16 @@ import _isEmpty from "lodash/isEmpty"; import { default as DefaultErrorList } from "./ErrorList"; import { + getDefaultFormState, retrieveSchema, shouldRender, + toIdSchema, deepEquals, toPathSchema, isObject, - getRegistry, - validate, - getStateFromProps, + getDefaultRegistry, } from "../utils"; -import { toErrorList } from "../validate"; +import validateFormData, { toErrorList } from "../validate"; import { mergeObjects } from "../utils"; function handleChange(props, state) { @@ -36,7 +36,7 @@ export default class Form extends Component { constructor(props) { super(props); - this.state = getStateFromProps(props, props.formData); + this.state = Form.getStateFromProps(props, props.formData); } formElement = null; @@ -60,11 +60,116 @@ export default class Form extends Component { static getDerivedStateFromProps(props, state) { if (!deepEquals(props, state.lastProps)) { - return getStateFromProps(props, props.formData, state); + return Form.getStateFromProps(props, props.formData, state); } return null; } + static getStateFromProps(props, inputFormData, state = {}) { + const edit = typeof inputFormData !== "undefined"; + const mustValidate = edit && !props.noValidate && props.liveValidate; + const formData = getDefaultFormState( + props.schema, + inputFormData, + props.schema + ); + const retrievedSchema = retrieveSchema( + props.schema, + props.schema, + formData + ); + + const getCurrentErrors = () => { + if (props.noValidate) { + return { errors: [], errorSchema: {} }; + } else if (!props.liveValidate) { + return { + errors: state.schemaValidationErrors || [], + errorSchema: state.schemaValidationErrorSchema || {}, + }; + } + return { + errors: state.errors || [], + errorSchema: state.errorSchema || {}, + }; + }; + + let errors, + errorSchema, + schemaValidationErrors, + schemaValidationErrorSchema; + if (mustValidate) { + const schemaValidation = Form.validate( + formData, + props, + props.schema, + props.additionalMetaSchemas, + props.customFormats + ); + errors = schemaValidation.errors; + errorSchema = schemaValidation.errorSchema; + schemaValidationErrors = errors; + schemaValidationErrorSchema = errorSchema; + } else { + const currentErrors = getCurrentErrors(); + errors = currentErrors.errors; + errorSchema = currentErrors.errorSchema; + schemaValidationErrors = state.schemaValidationErrors; + schemaValidationErrorSchema = state.schemaValidationErrorSchema; + } + if (props.extraErrors) { + errorSchema = mergeObjects( + errorSchema, + props.extraErrors, + !!"concat arrays" + ); + errors = toErrorList(errorSchema); + } + const idSchema = toIdSchema( + retrievedSchema, + props.uiSchema["ui:rootFieldId"], + props.schema, + formData, + props.idPrefix + ); + const nextState = { + schema: props.schema, + uiSchema: props.uiSchema, + idSchema, + formData, + edit, + errors, + errorSchema, + additionalMetaSchemas: props.additionalMetaSchemas, + lastProps: props, + }; + if (schemaValidationErrors) { + nextState.schemaValidationErrors = schemaValidationErrors; + nextState.schemaValidationErrorSchema = schemaValidationErrorSchema; + } + return nextState; + } + + static validate( + formData, + props, + schema = props.schema, + additionalMetaSchemas = props.additionalMetaSchemas, + customFormats = props.customFormats + ) { + const { validate, transformErrors } = props; + const { rootSchema } = Form.getRegistry(props); + const resolvedSchema = retrieveSchema(schema, rootSchema, formData); + return validateFormData( + formData, + resolvedSchema, + validate, + transformErrors, + additionalMetaSchemas, + customFormats + ); + } + shouldComponentUpdate(nextProps, nextState) { return shouldRender(this, nextProps, nextState); } @@ -132,7 +237,7 @@ export default class Form extends Component { onChange = (formData, newErrorSchema) => { if (isObject(formData) || Array.isArray(formData)) { - const newState = getStateFromProps(this.props, formData, this.state); + const newState = Form.getStateFromProps(this.props, formData, this.state); formData = newState.formData; } const mustValidate = !this.props.noValidate && this.props.liveValidate; @@ -161,7 +266,7 @@ export default class Form extends Component { } if (mustValidate) { - let schemaValidation = validate(newFormData, this.props); + let schemaValidation = Form.validate(newFormData, this.props); let errors = schemaValidation.errors; let errorSchema = schemaValidation.errorSchema; const schemaValidationErrors = errors; @@ -241,7 +346,7 @@ export default class Form extends Component { } if (!this.props.noValidate) { - let schemaValidation = validate(newFormData, this.props); + let schemaValidation = Form.validate(newFormData, this.props); let errors = schemaValidation.errors; let errorSchema = schemaValidation.errorSchema; const schemaValidationErrors = errors; @@ -297,6 +402,20 @@ export default class Form extends Component { ); }; + static getRegistry(props) { + const { fields, widgets } = getDefaultRegistry(); + return { + fields: { ...fields, ...props.fields }, + widgets: { ...widgets, ...props.widgets }, + ArrayFieldTemplate: props.ArrayFieldTemplate, + ObjectFieldTemplate: props.ObjectFieldTemplate, + FieldTemplate: props.FieldTemplate, + definitions: props.schema.definitions || {}, + rootSchema: props.schema, + formContext: props.formContext || {}, + }; + } + submit() { if (this.formElement) { this.formElement.dispatchEvent( @@ -328,7 +447,7 @@ export default class Form extends Component { } = this.props; const { schema, uiSchema, formData, errorSchema, idSchema } = this.state; - const registry = getRegistry(this.props); + const registry = Form.getRegistry(this.props); const _SchemaField = registry.fields.SchemaField; const FormTag = tagName ? tagName : "form"; if (deprecatedAutocomplete) { diff --git a/packages/core/src/utils.js b/packages/core/src/utils.js index 267d501453..83c20cdec8 100644 --- a/packages/core/src/utils.js +++ b/packages/core/src/utils.js @@ -2,11 +2,11 @@ import React from "react"; import * as ReactIs from "react-is"; import mergeAllOf from "json-schema-merge-allof"; import fill from "core-js-pure/features/array/fill"; -import validateFormData, { isValid, toErrorList } from "./validate"; import union from "lodash/union"; import jsonpointer from "jsonpointer"; import fields from "./components/fields"; import widgets from "./components/widgets"; +import validateFormData, { isValid } from "./validate"; export const ADDITIONAL_PROPERTY_FLAG = "__additional_property"; @@ -1265,115 +1265,3 @@ export function schemaRequiresTrueValue(schema) { return false; } - -export function getRegistry(props) { - const { fields, widgets } = getDefaultRegistry(); - return { - fields: { ...fields, ...props.fields }, - widgets: { ...widgets, ...props.widgets }, - ArrayFieldTemplate: props.ArrayFieldTemplate, - ObjectFieldTemplate: props.ObjectFieldTemplate, - FieldTemplate: props.FieldTemplate, - definitions: props.schema.definitions || {}, - rootSchema: props.schema, - formContext: props.formContext || {}, - }; -} - -export function validate( - formData, - props, - schema = props.schema, - additionalMetaSchemas = props.additionalMetaSchemas, - customFormats = props.customFormats -) { - const { validate, transformErrors } = props; - const { rootSchema } = getRegistry(props); - const resolvedSchema = retrieveSchema(schema, rootSchema, formData); - return validateFormData( - formData, - resolvedSchema, - validate, - transformErrors, - additionalMetaSchemas, - customFormats - ); -} - -export function getStateFromProps(props, inputFormData, state = {}) { - const edit = typeof inputFormData !== "undefined"; - const mustValidate = edit && !props.noValidate && props.liveValidate; - const formData = getDefaultFormState( - props.schema, - inputFormData, - props.schema - ); - const retrievedSchema = retrieveSchema(props.schema, props.schema, formData); - - const getCurrentErrors = () => { - if (props.noValidate) { - return { errors: [], errorSchema: {} }; - } else if (!props.liveValidate) { - return { - errors: state.schemaValidationErrors || [], - errorSchema: state.schemaValidationErrorSchema || {}, - }; - } - return { - errors: state.errors || [], - errorSchema: state.errorSchema || {}, - }; - }; - - let errors, errorSchema, schemaValidationErrors, schemaValidationErrorSchema; - if (mustValidate) { - const schemaValidation = validate( - formData, - props, - props.schema, - props.additionalMetaSchemas, - props.customFormats - ); - errors = schemaValidation.errors; - errorSchema = schemaValidation.errorSchema; - schemaValidationErrors = errors; - schemaValidationErrorSchema = errorSchema; - } else { - const currentErrors = getCurrentErrors(); - errors = currentErrors.errors; - errorSchema = currentErrors.errorSchema; - schemaValidationErrors = state.schemaValidationErrors; - schemaValidationErrorSchema = state.schemaValidationErrorSchema; - } - if (props.extraErrors) { - errorSchema = mergeObjects( - errorSchema, - props.extraErrors, - !!"concat arrays" - ); - errors = toErrorList(errorSchema); - } - const idSchema = toIdSchema( - retrievedSchema, - props.uiSchema["ui:rootFieldId"], - props.schema, - formData, - props.idPrefix - ); - const nextState = { - schema: props.schema, - uiSchema: props.uiSchema, - idSchema, - formData, - edit, - errors, - errorSchema, - additionalMetaSchemas: props.additionalMetaSchemas, - lastProps: props, - }; - if (schemaValidationErrors) { - nextState.schemaValidationErrors = schemaValidationErrors; - nextState.schemaValidationErrorSchema = schemaValidationErrorSchema; - } - return nextState; -}