@rjsf/core 6.5.1 → 6.5.2

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": "6.5.1",
3
+ "version": "6.5.2",
4
4
  "description": "A simple React component capable of building HTML forms out of a JSON schema.",
5
5
  "scripts": {
6
6
  "compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
@@ -76,9 +76,9 @@
76
76
  "prop-types": "^15.8.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@rjsf/snapshot-tests": "6.5.1",
80
- "@rjsf/utils": "6.5.1",
81
- "@rjsf/validator-ajv8": "6.5.1",
79
+ "@rjsf/snapshot-tests": "6.5.2",
80
+ "@rjsf/utils": "6.5.2",
81
+ "@rjsf/validator-ajv8": "6.5.2",
82
82
  "@testing-library/jest-dom": "^6.9.1",
83
83
  "@testing-library/react": "^16.3.2",
84
84
  "@testing-library/user-event": "^14.6.1",
@@ -896,7 +896,11 @@ export default class Form<
896
896
  const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange, removeEmptyOptionalObjects } =
897
897
  this.props;
898
898
  const { formData: oldFormData, schemaUtils, schema, fieldPathId, schemaValidationErrorSchema, errors } = this.state;
899
- let { customErrors, errorSchema: originalErrorSchema } = this.state;
899
+ let { customErrors } = this.state;
900
+ // Use the un-merged AJV-only schema as the base for re-merging extraErrors. Mirrors the
901
+ // pattern in getStateFromProps/getDerivedStateFromProps and avoids the duplication that
902
+ // happened when state.errorSchema (already containing merged extraErrors) was passed in.
903
+ let mergeBaseErrorSchema: ErrorSchema<T> = schemaValidationErrorSchema as ErrorSchema<T>;
900
904
  const rootPathId = fieldPathId.path[0] || '';
901
905
 
902
906
  const isRootPath = !path || path.length === 0 || (path.length === 1 && path[0] === rootPathId);
@@ -958,11 +962,13 @@ export default class Form<
958
962
  const oldValidationError = !isRootPath ? _get(schemaValidationErrorSchema, path) : schemaValidationErrorSchema;
959
963
  // If there is an old validation error for this path, assume we are updating it directly
960
964
  if (!_isEmpty(oldValidationError)) {
961
- // Update the originalErrorSchema "in place" or replace it if it is the root
965
+ // Apply the user-supplied newErrorSchema onto a clone of the AJV-only base, so that
966
+ // mergeErrors below sees the user's error at this path without mutating shared state.
962
967
  if (!isRootPath) {
963
- _set(originalErrorSchema, path, newErrorSchema);
968
+ mergeBaseErrorSchema = _cloneDeep(schemaValidationErrorSchema) as ErrorSchema<T>;
969
+ _set(mergeBaseErrorSchema, path, newErrorSchema);
964
970
  } else {
965
- originalErrorSchema = newErrorSchema;
971
+ mergeBaseErrorSchema = newErrorSchema as ErrorSchema<T>;
966
972
  }
967
973
  } else {
968
974
  if (!customErrors) {
@@ -987,7 +993,7 @@ export default class Form<
987
993
  const liveValidation = this.liveValidate(
988
994
  schema,
989
995
  schemaUtils,
990
- originalErrorSchema,
996
+ mergeBaseErrorSchema,
991
997
  newFormData,
992
998
  extraErrors,
993
999
  customErrors,
@@ -996,7 +1002,7 @@ export default class Form<
996
1002
  state = { formData: newFormData, ...liveValidation, customErrors };
997
1003
  } else if (!noValidate && newErrorSchema) {
998
1004
  // Merging 'newErrorSchema' into 'errorSchema' to display the custom raised errors.
999
- const mergedErrors = this.mergeErrors({ errorSchema: originalErrorSchema, errors }, extraErrors, customErrors);
1005
+ const mergedErrors = this.mergeErrors({ errorSchema: mergeBaseErrorSchema, errors }, extraErrors, customErrors);
1000
1006
  state = {
1001
1007
  formData: newFormData,
1002
1008
  ...mergedErrors,
@@ -1028,10 +1028,12 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
1028
1028
  */
1029
1029
  const handleChange = useCallback(
1030
1030
  (value: any, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
1031
+ const lastPathIsItemIndex = typeof path.at(-1) === 'number';
1031
1032
  onChange(
1032
1033
  // We need to treat undefined items as nulls to have validation.
1033
1034
  // See https://github.com/tdegrunt/jsonschema/issues/206
1034
- value === undefined ? null : value,
1035
+ // Only set to null for array items, and not for object properties within array items
1036
+ lastPathIsItemIndex && value === undefined ? null : value,
1035
1037
  path,
1036
1038
  newErrorSchema as ErrorSchema<T[]>,
1037
1039
  id,