Skip to content

Commit

Permalink
Fix an error when ancestors get loaded before the status itself (#5312)
Browse files Browse the repository at this point in the history
When ancestors get loaded, we scroll to the target status (i.e. skip
ancestors). However, ancestors may get loaded before the status itself,
then it causes TypeError because `this.node` is undefined yet.

Since we don't show anything until the status gets loaded, we don't need
to scroll to the target status in this time. If we get the status itslef
later, it causes `componentDidUpdate` and scrolling correctly.
  • Loading branch information
unarist authored and Gargron committed Oct 11, 2017
1 parent 9b3d8ee commit b0407ec
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/javascript/mastodon/features/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ export default class Status extends ImmutablePureComponent {
}

componentDidUpdate () {
const { ancestorsIds } = this.props;
const { status, ancestorsIds } = this.props;

if (ancestorsIds && ancestorsIds.size > 0) {
if (status && ancestorsIds && ancestorsIds.size > 0) {
const element = this.node.querySelectorAll('.focusable')[ancestorsIds.size];
element.scrollIntoView();
}
Expand Down

0 comments on commit b0407ec

Please sign in to comment.