@rjsf/utils 6.0.1 → 6.0.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/utils",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -121,6 +121,7 @@ export function computeDefaultBasedOnSchemaTypeAndDefaults<T = any, S extends St
121
121
  * @param experimental_defaultFormStateBehavior - Optional configuration object, if provided, allows users to override
122
122
  * default form state behavior
123
123
  * @param isConst - Optional flag, if true, indicates that the schema has a const property defined, thus we should always return the computedDefault since it's coming from the const.
124
+ * @param isNullType - The type of the schema is null
124
125
  */
125
126
  function maybeAddDefaultToObject<T = any>(
126
127
  obj: GenericObjectType,
@@ -131,6 +132,7 @@ function maybeAddDefaultToObject<T = any>(
131
132
  requiredFields: string[] = [],
132
133
  experimental_defaultFormStateBehavior: Experimental_DefaultFormStateBehavior = {},
133
134
  isConst = false,
135
+ isNullType = false,
134
136
  ) {
135
137
  const { emptyObjectFields = 'populateAllDefaults' } = experimental_defaultFormStateBehavior;
136
138
 
@@ -141,7 +143,7 @@ function maybeAddDefaultToObject<T = any>(
141
143
  } else if (includeUndefinedValues === 'excludeObjectChildren') {
142
144
  // Fix for Issue #4709: When in 'excludeObjectChildren' mode, don't set primitive fields to empty objects
143
145
  // Only add the computed default if it's not an empty object placeholder for a primitive field
144
- if (!isObject(computedDefault) || !isEmpty(computedDefault)) {
146
+ if ((isNullType && computedDefault !== undefined) || !isObject(computedDefault) || !isEmpty(computedDefault)) {
145
147
  obj[key] = computedDefault;
146
148
  }
147
149
  // If computedDefault is an empty object {}, don't add it - let the field stay undefined
@@ -517,6 +519,7 @@ export function getObjectDefaults<T = any, S extends StrictRJSFSchema = RJSFSche
517
519
  retrievedSchema.required,
518
520
  experimental_defaultFormStateBehavior,
519
521
  hasConst,
522
+ propertySchema?.type === 'null',
520
523
  );
521
524
 
522
525
  return acc;