@rjsf/core 5.13.2 → 5.13.3

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
@@ -687,7 +687,7 @@ var ArrayField = class extends import_react.Component {
687
687
  const { key, item } = keyedItem;
688
688
  const itemCast = item;
689
689
  const additional = index >= itemSchemas.length;
690
- const itemSchema = additional && (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
690
+ const itemSchema = (additional && (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
691
691
  const itemIdPrefix = idSchema.$id + idSeparator + index;
692
692
  const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
693
693
  const itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) ? uiSchema.items[index] : uiSchema.items || {};
@@ -3381,18 +3381,55 @@ var Form = class extends import_react17.Component {
3381
3381
  }
3382
3382
  this.formElement = (0, import_react17.createRef)();
3383
3383
  }
3384
- /** React lifecycle method that gets called before new props are provided, updates the state based on new props. It
3385
- * will also call the`onChange` handler if the `formData` is modified to add missing default values as part of the
3386
- * state construction.
3384
+ /**
3385
+ * `getSnapshotBeforeUpdate` is a React lifecycle method that is invoked right before the most recently rendered
3386
+ * output is committed to the DOM. It enables your component to capture current values (e.g., scroll position) before
3387
+ * they are potentially changed.
3388
+ *
3389
+ * In this case, it checks if the props have changed since the last render. If they have, it computes the next state
3390
+ * of the component using `getStateFromProps` method and returns it along with a `shouldUpdate` flag set to `true` IF
3391
+ * the `nextState` and `prevState` are different, otherwise `false`. This ensures that we have the most up-to-date
3392
+ * state ready to be applied in `componentDidUpdate`.
3393
+ *
3394
+ * If `formData` hasn't changed, it simply returns an object with `shouldUpdate` set to `false`, indicating that a
3395
+ * state update is not necessary.
3396
+ *
3397
+ * @param prevProps - The previous set of props before the update.
3398
+ * @param prevState - The previous state before the update.
3399
+ * @returns Either an object containing the next state and a flag indicating that an update should occur, or an object
3400
+ * with a flag indicating that an update is not necessary.
3401
+ */
3402
+ getSnapshotBeforeUpdate(prevProps, prevState) {
3403
+ if (!(0, import_utils39.deepEquals)(this.props, prevProps)) {
3404
+ const nextState = this.getStateFromProps(this.props, this.props.formData);
3405
+ const shouldUpdate = !(0, import_utils39.deepEquals)(nextState, prevState);
3406
+ return { nextState, shouldUpdate };
3407
+ }
3408
+ return { shouldUpdate: false };
3409
+ }
3410
+ /**
3411
+ * `componentDidUpdate` is a React lifecycle method that is invoked immediately after updating occurs. This method is
3412
+ * not called for the initial render.
3413
+ *
3414
+ * Here, it checks if an update is necessary based on the `shouldUpdate` flag received from `getSnapshotBeforeUpdate`.
3415
+ * If an update is required, it applies the next state and, if needed, triggers the `onChange` handler to inform about
3416
+ * changes.
3387
3417
  *
3388
- * @param nextProps - The new set of props about to be applied to the `Form`
3418
+ * This method effectively replaces the deprecated `UNSAFE_componentWillReceiveProps`, providing a safer alternative
3419
+ * to handle prop changes and state updates.
3420
+ *
3421
+ * @param _ - The previous set of props.
3422
+ * @param prevState - The previous state of the component before the update.
3423
+ * @param snapshot - The value returned from `getSnapshotBeforeUpdate`.
3389
3424
  */
3390
- UNSAFE_componentWillReceiveProps(nextProps) {
3391
- const nextState = this.getStateFromProps(nextProps, nextProps.formData);
3392
- if (!(0, import_utils39.deepEquals)(nextState.formData, nextProps.formData) && !(0, import_utils39.deepEquals)(nextState.formData, this.state.formData) && nextProps.onChange) {
3393
- nextProps.onChange(nextState);
3425
+ componentDidUpdate(_, prevState, snapshot) {
3426
+ if (snapshot.shouldUpdate) {
3427
+ const { nextState } = snapshot;
3428
+ if (!(0, import_utils39.deepEquals)(nextState.formData, this.props.formData) && !(0, import_utils39.deepEquals)(nextState.formData, prevState.formData) && this.props.onChange) {
3429
+ this.props.onChange(nextState);
3430
+ }
3431
+ this.setState(nextState);
3394
3432
  }
3395
- this.setState(nextState);
3396
3433
  }
3397
3434
  /** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
3398
3435
  * `inputFormData` is first processed to add any missing required defaults. After that, the data is run through the