@rjsf/core 5.17.1 → 5.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3466,10 +3466,16 @@ var Form = class extends import_react17.Component {
3466
3466
  */
3467
3467
  getSnapshotBeforeUpdate(prevProps, prevState) {
3468
3468
  if (!(0, import_utils39.deepEquals)(this.props, prevProps)) {
3469
+ const isSchemaChanged = !(0, import_utils39.deepEquals)(prevProps.schema, this.props.schema);
3470
+ const isFormDataChanged = !(0, import_utils39.deepEquals)(prevProps.formData, this.props.formData);
3469
3471
  const nextState = this.getStateFromProps(
3470
3472
  this.props,
3471
3473
  this.props.formData,
3472
- prevProps.schema !== this.props.schema ? void 0 : this.state.retrievedSchema
3474
+ // If the `schema` has changed, we need to update the retrieved schema.
3475
+ // Or if the `formData` changes, for example in the case of a schema with dependencies that need to
3476
+ // match one of the subSchemas, the retrieved schema must be updated.
3477
+ isSchemaChanged || isFormDataChanged ? void 0 : this.state.retrievedSchema,
3478
+ isSchemaChanged
3473
3479
  );
3474
3480
  const shouldUpdate = !(0, import_utils39.deepEquals)(nextState, prevState);
3475
3481
  return { nextState, shouldUpdate };
@@ -3506,9 +3512,11 @@ var Form = class extends import_react17.Component {
3506
3512
  *
3507
3513
  * @param props - The props passed to the `Form`
3508
3514
  * @param inputFormData - The new or current data for the `Form`
3515
+ * @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
3516
+ * @param isSchemaChanged - A flag indicating whether the schema has changed.
3509
3517
  * @returns - The new state for the `Form`
3510
3518
  */
3511
- getStateFromProps(props, inputFormData, retrievedSchema) {
3519
+ getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false) {
3512
3520
  const state = this.state || {};
3513
3521
  const schema = "schema" in props ? props.schema : this.props.schema;
3514
3522
  const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
@@ -3524,7 +3532,7 @@ var Form = class extends import_react17.Component {
3524
3532
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3525
3533
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3526
3534
  const getCurrentErrors = () => {
3527
- if (props.noValidate) {
3535
+ if (props.noValidate || isSchemaChanged) {
3528
3536
  return { errors: [], errorSchema: {} };
3529
3537
  } else if (!props.liveValidate) {
3530
3538
  return {