react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

propTypes cycles cause crashes

Open ZxBing0066 opened this issue 3 years ago • 0 comments

If there is a self-reference in propTypes define, docgen will throw an error: RangeError: Maximum call stack size exceeded. related to #249.

For reproduction, copy the code below to the playground: https://reactcommunity.org/react-docgen/

import React, { Component } from 'react';
import PropTypes from 'prop-types';

/**
 * General component description.
 */
class MyComponent extends Component {
  render() {
    // ...
  }
}

MyComponent.propTypes = {
  /**
   * Description of prop "foo".
   */
  foo: PropTypes.number,
  /**
   * Description of prop "bar" (a custom validation function).
   */
  bar: function(props, propName, componentName) {
    // ...
  },
  baz: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.string
  ]).isRequired,
  child: PropTypes.shape(MyComponent.propTypes)
};

MyComponent.defaultProps = {
  foo: 42,
  bar: 21
};

export default MyComponent;

ZxBing0066 avatar Jul 26 '22 02:07 ZxBing0066