From b558cbb53155fbc3a98da81f45acf9f333b645f4 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 22 May 2019 11:05:01 +0200 Subject: [PATCH] FIX an issue where forwardRefs make addon-info throw --- addons/info/src/components/Story.js | 9 +- .../addon-info.stories.storyshot | 244 ++++++++++++++++++ 2 files changed, 251 insertions(+), 2 deletions(-) diff --git a/addons/info/src/components/Story.js b/addons/info/src/components/Story.js index 0716aa6a76a9..a8dc10026c6d 100644 --- a/addons/info/src/components/Story.js +++ b/addons/info/src/components/Story.js @@ -358,17 +358,22 @@ class Story extends Component { extract(innerChildren.props.children); } if (isForwardRef(innerChildren)) { - extract(innerChildren.type.render(innerChildren.props)); + try { + // this might fail because of hooks being used + extract(innerChildren.type.render(innerChildren.props)); + } catch (e) { + // do nothing + } } if ( typeof innerChildren === 'string' || typeof innerChildren.type === 'string' || - isForwardRef(innerChildren) || (Array.isArray(propTablesExclude) && // also ignore excluded types ~propTablesExclude.indexOf(innerChildren.type)) // eslint-disable-line no-bitwise ) { return; } + if (innerChildren.type && !types.has(innerChildren.type)) { types.set(innerChildren.type, true); } diff --git a/examples/official-storybook/stories/__snapshots__/addon-info.stories.storyshot b/examples/official-storybook/stories/__snapshots__/addon-info.stories.storyshot index a08a938a0c2f..0f12093915f1 100644 --- a/examples/official-storybook/stories/__snapshots__/addon-info.stories.storyshot +++ b/examples/official-storybook/stories/__snapshots__/addon-info.stories.storyshot @@ -555,6 +555,128 @@ exports[`Storyshots Addons|Info/ForwardRef Displays forwarded ref components cor +
+

+ "Unknown" Component +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ property + + propType + + required + + default + + description +
+ disabled + + + bool + + + - + + + false + + +
+ label + + + string + + + yes + + - + +
+ onClick + + + func + + + - + + + onClick + + +
+ style + + + other + + + - + + + {} + + +
+
@@ -791,6 +913,128 @@ exports[`Storyshots Addons|Info/ForwardRef Uses forwardRef displayName if availa +
+

+ "ButtonDisplayName" Component +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ property + + propType + + required + + default + + description +
+ disabled + + + bool + + + - + + + false + + +
+ label + + + string + + + yes + + - + +
+ onClick + + + func + + + - + + + onClick + + +
+ style + + + other + + + - + + + {} + + +
+