File tree Expand file tree Collapse file tree 5 files changed +45
-12
lines changed
packages/pretty-proptypes/src Expand file tree Collapse file tree 5 files changed +45
-12
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' pretty-proptypes ' : patch
3+ ---
4+
5+ Permalink generation should also work now when ` extract-react-types ` is used.
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type { Components } from '../components';
1010import getPropTypes from '../getPropTypes' ;
1111import renderPropType from '../renderPropType' ;
1212import PrettyPropType from '../PrettyConvert' ;
13+ import { getComponentDisplayName } from '../utils' ;
1314
1415type Obj = {
1516 kind : 'object' ,
@@ -91,12 +92,11 @@ const LayoutRenderer: FC<LayoutRendererProps> = ({
9192 }
9293
9394 let renderProps = rest ;
94- // ensure displayName passes through, assuming it has been captured
95- // $FlowFixMe as mentioned above, the typing for `component` is a bit off here...
96- if ( component && component . ___displayName ) {
95+ const componentDisplayName = getComponentDisplayName ( component || ( props || { } ) . component ) ;
96+ if ( typeof componentDisplayName === 'string' ) {
9797 renderProps = {
9898 ...rest ,
99- componentDisplayName : String ( component . ___displayName )
99+ componentDisplayName
100100 } ;
101101 }
102102
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import type { CommonProps } from '../types';
99import PropsWrapper from './Wrapper' ;
1010import getPropTypes from '../getPropTypes' ;
1111import renderPropType from '../renderPropType' ;
12+ import { getComponentDisplayName } from '../utils' ;
1213
1314import Prop from '../Prop' ;
1415
@@ -69,12 +70,12 @@ export default class Props extends Component<DynamicPropsProps> {
6970 if ( ! propTypes ) return null ;
7071
7172 let renderProps = rest ;
72- // ensure displayName passes through, assuming it has been captured
73- // $FlowFixMe as mentioned above, the typing for ` component` is a bit off here...
74- if ( component && component . ___displayName ) {
73+ // $FlowFixMe types are not exactly correct here ... sadly :/
74+ const componentDisplayName = getComponentDisplayName ( component || ( props || { } ) . component ) ;
75+ if ( typeof componentDisplayName === 'string' ) {
7576 renderProps = {
7677 ...rest ,
77- componentDisplayName : String ( component . ___displayName )
78+ componentDisplayName
7879 } ;
7980 }
8081
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import type { CommonProps } from '../types';
1111import PropsWrapper from '../Props/Wrapper' ;
1212import getPropTypes from '../getPropTypes' ;
1313import renderPropType from '../renderPropType' ;
14+ import { getComponentDisplayName } from '../utils' ;
1415import PropRow from './PropRow' ;
1516
1617type Obj = {
@@ -70,12 +71,12 @@ export default class PropsTable extends Component<DynamicPropsProps> {
7071 if ( ! propTypes ) return null ;
7172
7273 let renderProps = rest ;
73- // ensure displayName passes through, assuming it has been captured
74- // $FlowFixMe as mentioned above, the typing for ` component` is a bit off here...
75- if ( component && component . ___displayName ) {
74+ // $FlowFixMe types are not exactly correct here ... sadly :/
75+ const componentDisplayName = getComponentDisplayName ( component || ( props || { } ) . component ) ;
76+ if ( typeof componentDisplayName === 'string' ) {
7677 renderProps = {
7778 ...rest ,
78- componentDisplayName : String ( component . ___displayName )
79+ componentDisplayName
7980 } ;
8081 }
8182
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-underscore-dangle */
2+ // @flow strict-local
3+
4+ // eslint-disable-next-line import/prefer-default-export
5+ export const getComponentDisplayName = (
6+ data :
7+ | {
8+ ___displayName ?: string
9+ }
10+ | {
11+ name ?: {
12+ name ?: string
13+ }
14+ }
15+ | void
16+ ) : string | void => {
17+ // ensure displayName passes through, assuming it has been captured by Babel
18+ if ( data && data . ___displayName ) {
19+ return String ( data . ___displayName ) ;
20+ // or it might be obtainable from the converter logic in `packages/extract-react-types/src/converter`
21+ } else if ( data && data . name && data . name . name ) {
22+ return String ( data . name . name ) ;
23+ }
24+
25+ return undefined ;
26+ } ;
You can’t perform that action at this time.
0 commit comments