Skip to content

Commit

Permalink
chore: Avoid Form retrieveSchema twice when liveValidate is true (#3959)
Browse files Browse the repository at this point in the history
* Avoid retrieveSchema multiple times

* Fix changelog
  • Loading branch information
igorbrasileiro authored Nov 16, 2023
1 parent a87de48 commit 2a3c7c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ should change the heading of the (upcoming) version to include a major version b

- Update `sanitizeDataForNewSchema()` to avoid spreading strings and Arrays into the returned value when the old schema is of type `string` or `array` and the new schema is of type `object`. Fixing [#3922](https://github.com/rjsf-team/react-jsonschema-form/issues/3922)

## @rjsf/core

- avoid call `retrieveSchema` twice during `getStateFromProps` and `mustValidate` is true [#3959](https://github.com/rjsf-team/react-jsonschema-form/pull/3959)

# 5.14.1

## @rjsf/utils
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export default class Form<
let schemaValidationErrors: RJSFValidationError[] = state.schemaValidationErrors;
let schemaValidationErrorSchema: ErrorSchema<T> = state.schemaValidationErrorSchema;
if (mustValidate) {
const schemaValidation = this.validate(formData, schema, schemaUtils);
const schemaValidation = this.validate(formData, schema, schemaUtils, retrievedSchema);
errors = schemaValidation.errors;
errorSchema = schemaValidation.errorSchema;
schemaValidationErrors = errors;
Expand Down Expand Up @@ -451,11 +451,12 @@ export default class Form<
validate(
formData: T | undefined,
schema = this.props.schema,
altSchemaUtils?: SchemaUtilsType<T, S, F>
altSchemaUtils?: SchemaUtilsType<T, S, F>,
retrievedSchema?: S
): ValidationData<T> {
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
const { customValidate, transformErrors, uiSchema } = this.props;
const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
const resolvedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
return schemaUtils
.getValidator()
.validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
Expand Down

0 comments on commit 2a3c7c8

Please sign in to comment.