@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/core",
3
- "version": "5.17.1",
3
+ "version": "5.18.0",
4
4
  "description": "A simple React component capable of building HTML forms out of a JSON schema.",
5
5
  "scripts": {
6
6
  "build:ts": "tsc -b",
@@ -54,10 +54,10 @@
54
54
  "@babel/preset-env": "^7.23.9",
55
55
  "@babel/preset-react": "^7.23.3",
56
56
  "@babel/preset-typescript": "^7.23.3",
57
- "@rjsf/snapshot-tests": "^5.17.1",
58
- "@rjsf/utils": "^5.17.1",
59
- "@rjsf/validator-ajv6": "^5.17.1",
60
- "@rjsf/validator-ajv8": "^5.17.1",
57
+ "@rjsf/snapshot-tests": "^5.18.0",
58
+ "@rjsf/utils": "^5.18.0",
59
+ "@rjsf/validator-ajv6": "^5.18.0",
60
+ "@rjsf/validator-ajv8": "^5.18.0",
61
61
  "@types/jest": "^29.5.12",
62
62
  "@types/lodash": "^4.14.202",
63
63
  "@types/react": "^17.0.75",
@@ -104,5 +104,5 @@
104
104
  "publishConfig": {
105
105
  "access": "public"
106
106
  },
107
- "gitHead": "4d13c51c861fa0d21ec6e40881a21ba16c72d8bd"
107
+ "gitHead": "7059e5ec14e0e454fe016aa367d9b65208f3bd8d"
108
108
  }
@@ -306,10 +306,16 @@ export default class Form<
306
306
  prevState: FormState<T, S, F>
307
307
  ): { nextState: FormState<T, S, F>; shouldUpdate: true } | { shouldUpdate: false } {
308
308
  if (!deepEquals(this.props, prevProps)) {
309
+ const isSchemaChanged = !deepEquals(prevProps.schema, this.props.schema);
310
+ const isFormDataChanged = !deepEquals(prevProps.formData, this.props.formData);
309
311
  const nextState = this.getStateFromProps(
310
312
  this.props,
311
313
  this.props.formData,
312
- prevProps.schema !== this.props.schema ? undefined : this.state.retrievedSchema
314
+ // If the `schema` has changed, we need to update the retrieved schema.
315
+ // Or if the `formData` changes, for example in the case of a schema with dependencies that need to
316
+ // match one of the subSchemas, the retrieved schema must be updated.
317
+ isSchemaChanged || isFormDataChanged ? undefined : this.state.retrievedSchema,
318
+ isSchemaChanged
313
319
  );
314
320
  const shouldUpdate = !deepEquals(nextState, prevState);
315
321
  return { nextState, shouldUpdate };
@@ -357,9 +363,16 @@ export default class Form<
357
363
  *
358
364
  * @param props - The props passed to the `Form`
359
365
  * @param inputFormData - The new or current data for the `Form`
366
+ * @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
367
+ * @param isSchemaChanged - A flag indicating whether the schema has changed.
360
368
  * @returns - The new state for the `Form`
361
369
  */
362
- getStateFromProps(props: FormProps<T, S, F>, inputFormData?: T, retrievedSchema?: S): FormState<T, S, F> {
370
+ getStateFromProps(
371
+ props: FormProps<T, S, F>,
372
+ inputFormData?: T,
373
+ retrievedSchema?: S,
374
+ isSchemaChanged = false
375
+ ): FormState<T, S, F> {
363
376
  const state: FormState<T, S, F> = this.state || {};
364
377
  const schema = 'schema' in props ? props.schema : this.props.schema;
365
378
  const uiSchema: UiSchema<T, S, F> = ('uiSchema' in props ? props.uiSchema! : this.props.uiSchema!) || {};
@@ -382,7 +395,8 @@ export default class Form<
382
395
  const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
383
396
 
384
397
  const getCurrentErrors = (): ValidationData<T> => {
385
- if (props.noValidate) {
398
+ // If the `props.noValidate` option is set or the schema has changed, we reset the error state.
399
+ if (props.noValidate || isSchemaChanged) {
386
400
  return { errors: [], errorSchema: {} };
387
401
  } else if (!props.liveValidate) {
388
402
  return {