Skip to content

propTypes cycles cause crashes #640

Closed
@ZxBing0066

Description

@ZxBing0066

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions