Skip to content

Commit 2a3c7c8

Browse files
chore: Avoid Form retrieveSchema twice when liveValidate is true (#3959)
* Avoid retrieveSchema multiple times * Fix changelog
1 parent a87de48 commit 2a3c7c8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ should change the heading of the (upcoming) version to include a major version b
2727

2828
- 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)
2929

30+
## @rjsf/core
31+
32+
- avoid call `retrieveSchema` twice during `getStateFromProps` and `mustValidate` is true [#3959](https://github.com/rjsf-team/react-jsonschema-form/pull/3959)
33+
3034
# 5.14.1
3135

3236
## @rjsf/utils

packages/core/src/components/Form.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export default class Form<
394394
let schemaValidationErrors: RJSFValidationError[] = state.schemaValidationErrors;
395395
let schemaValidationErrorSchema: ErrorSchema<T> = state.schemaValidationErrorSchema;
396396
if (mustValidate) {
397-
const schemaValidation = this.validate(formData, schema, schemaUtils);
397+
const schemaValidation = this.validate(formData, schema, schemaUtils, retrievedSchema);
398398
errors = schemaValidation.errors;
399399
errorSchema = schemaValidation.errorSchema;
400400
schemaValidationErrors = errors;
@@ -451,11 +451,12 @@ export default class Form<
451451
validate(
452452
formData: T | undefined,
453453
schema = this.props.schema,
454-
altSchemaUtils?: SchemaUtilsType<T, S, F>
454+
altSchemaUtils?: SchemaUtilsType<T, S, F>,
455+
retrievedSchema?: S
455456
): ValidationData<T> {
456457
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
457458
const { customValidate, transformErrors, uiSchema } = this.props;
458-
const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
459+
const resolvedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
459460
return schemaUtils
460461
.getValidator()
461462
.validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);

0 commit comments

Comments
 (0)