Skip to content

Commit

Permalink
FIX an issue where forwardRefs make addon-info throw (#6859)
Browse files Browse the repository at this point in the history
FIX an issue where forwardRefs make addon-info throw
  • Loading branch information
ndelangen authored May 28, 2019
2 parents f92f28e + b558cbb commit 7c35570
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 2 deletions.
9 changes: 7 additions & 2 deletions addons/info/src/components/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,128 @@ exports[`Storyshots Addons|Info/ForwardRef Displays forwarded ref components cor
</tbody>
</table>
</div>
<div>
<h3
style="margin:20px 0 0 0"
>
"Unknown" Component
</h3>
<table
class="info-table"
>
<thead>
<tr>
<th>
property
</th>
<th>
propType
</th>
<th>
required
</th>
<th>
default
</th>
<th>
description
</th>
</tr>
</thead>
<tbody>
<tr>
<td
class="info-table-monospace"
>
disabled
</td>
<td
class="info-table-monospace"
>
<span>
bool
</span>
</td>
<td>
-
</td>
<td>
<span>
false
</span>
</td>
<td />
</tr>
<tr>
<td
class="info-table-monospace"
>
label
</td>
<td
class="info-table-monospace"
>
<span>
string
</span>
</td>
<td>
yes
</td>
<td>
-
</td>
<td />
</tr>
<tr>
<td
class="info-table-monospace"
>
onClick
</td>
<td
class="info-table-monospace"
>
<span>
func
</span>
</td>
<td>
-
</td>
<td>
<span>
onClick
</span>
</td>
<td />
</tr>
<tr>
<td
class="info-table-monospace"
>
style
</td>
<td
class="info-table-monospace"
>
<span>
other
</span>
</td>
<td>
-
</td>
<td>
<span>
{}
</span>
</td>
<td />
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -791,6 +913,128 @@ exports[`Storyshots Addons|Info/ForwardRef Uses forwardRef displayName if availa
</tbody>
</table>
</div>
<div>
<h3
style="margin:20px 0 0 0"
>
"ButtonDisplayName" Component
</h3>
<table
class="info-table"
>
<thead>
<tr>
<th>
property
</th>
<th>
propType
</th>
<th>
required
</th>
<th>
default
</th>
<th>
description
</th>
</tr>
</thead>
<tbody>
<tr>
<td
class="info-table-monospace"
>
disabled
</td>
<td
class="info-table-monospace"
>
<span>
bool
</span>
</td>
<td>
-
</td>
<td>
<span>
false
</span>
</td>
<td />
</tr>
<tr>
<td
class="info-table-monospace"
>
label
</td>
<td
class="info-table-monospace"
>
<span>
string
</span>
</td>
<td>
yes
</td>
<td>
-
</td>
<td />
</tr>
<tr>
<td
class="info-table-monospace"
>
onClick
</td>
<td
class="info-table-monospace"
>
<span>
func
</span>
</td>
<td>
-
</td>
<td>
<span>
onClick
</span>
</td>
<td />
</tr>
<tr>
<td
class="info-table-monospace"
>
style
</td>
<td
class="info-table-monospace"
>
<span>
other
</span>
</td>
<td>
-
</td>
<td>
<span>
{}
</span>
</td>
<td />
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 7c35570

Please sign in to comment.