@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/core.umd.js CHANGED
@@ -3211,10 +3211,16 @@
3211
3211
  */
3212
3212
  getSnapshotBeforeUpdate(prevProps, prevState) {
3213
3213
  if (!utils.deepEquals(this.props, prevProps)) {
3214
+ const isSchemaChanged = !utils.deepEquals(prevProps.schema, this.props.schema);
3215
+ const isFormDataChanged = !utils.deepEquals(prevProps.formData, this.props.formData);
3214
3216
  const nextState = this.getStateFromProps(
3215
3217
  this.props,
3216
3218
  this.props.formData,
3217
- prevProps.schema !== this.props.schema ? void 0 : this.state.retrievedSchema
3219
+ // If the `schema` has changed, we need to update the retrieved schema.
3220
+ // Or if the `formData` changes, for example in the case of a schema with dependencies that need to
3221
+ // match one of the subSchemas, the retrieved schema must be updated.
3222
+ isSchemaChanged || isFormDataChanged ? void 0 : this.state.retrievedSchema,
3223
+ isSchemaChanged
3218
3224
  );
3219
3225
  const shouldUpdate = !utils.deepEquals(nextState, prevState);
3220
3226
  return { nextState, shouldUpdate };
@@ -3251,9 +3257,11 @@
3251
3257
  *
3252
3258
  * @param props - The props passed to the `Form`
3253
3259
  * @param inputFormData - The new or current data for the `Form`
3260
+ * @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
3261
+ * @param isSchemaChanged - A flag indicating whether the schema has changed.
3254
3262
  * @returns - The new state for the `Form`
3255
3263
  */
3256
- getStateFromProps(props, inputFormData, retrievedSchema) {
3264
+ getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false) {
3257
3265
  const state = this.state || {};
3258
3266
  const schema = "schema" in props ? props.schema : this.props.schema;
3259
3267
  const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
@@ -3269,7 +3277,7 @@
3269
3277
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3270
3278
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3271
3279
  const getCurrentErrors = () => {
3272
- if (props.noValidate) {
3280
+ if (props.noValidate || isSchemaChanged) {
3273
3281
  return { errors: [], errorSchema: {} };
3274
3282
  } else if (!props.liveValidate) {
3275
3283
  return {
package/dist/index.esm.js CHANGED
@@ -3560,10 +3560,16 @@ var Form = class extends Component5 {
3560
3560
  */
3561
3561
  getSnapshotBeforeUpdate(prevProps, prevState) {
3562
3562
  if (!deepEquals3(this.props, prevProps)) {
3563
+ const isSchemaChanged = !deepEquals3(prevProps.schema, this.props.schema);
3564
+ const isFormDataChanged = !deepEquals3(prevProps.formData, this.props.formData);
3563
3565
  const nextState = this.getStateFromProps(
3564
3566
  this.props,
3565
3567
  this.props.formData,
3566
- prevProps.schema !== this.props.schema ? void 0 : this.state.retrievedSchema
3568
+ // If the `schema` has changed, we need to update the retrieved schema.
3569
+ // Or if the `formData` changes, for example in the case of a schema with dependencies that need to
3570
+ // match one of the subSchemas, the retrieved schema must be updated.
3571
+ isSchemaChanged || isFormDataChanged ? void 0 : this.state.retrievedSchema,
3572
+ isSchemaChanged
3567
3573
  );
3568
3574
  const shouldUpdate = !deepEquals3(nextState, prevState);
3569
3575
  return { nextState, shouldUpdate };
@@ -3600,9 +3606,11 @@ var Form = class extends Component5 {
3600
3606
  *
3601
3607
  * @param props - The props passed to the `Form`
3602
3608
  * @param inputFormData - The new or current data for the `Form`
3609
+ * @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
3610
+ * @param isSchemaChanged - A flag indicating whether the schema has changed.
3603
3611
  * @returns - The new state for the `Form`
3604
3612
  */
3605
- getStateFromProps(props, inputFormData, retrievedSchema) {
3613
+ getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false) {
3606
3614
  const state = this.state || {};
3607
3615
  const schema = "schema" in props ? props.schema : this.props.schema;
3608
3616
  const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
@@ -3618,7 +3626,7 @@ var Form = class extends Component5 {
3618
3626
  const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3619
3627
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
3620
3628
  const getCurrentErrors = () => {
3621
- if (props.noValidate) {
3629
+ if (props.noValidate || isSchemaChanged) {
3622
3630
  return { errors: [], errorSchema: {} };
3623
3631
  } else if (!props.liveValidate) {
3624
3632
  return {