]> cat aescling's git repositories - mastodon.git/commitdiff
Fix an error when ancestors get loaded before the status itself (#5312)
authorunarist <m.unarist@gmail.com>
Wed, 11 Oct 2017 09:25:15 +0000 (18:25 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 11 Oct 2017 09:25:15 +0000 (11:25 +0200)
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.

app/javascript/mastodon/features/status/index.js

index abcfee99e788ea20ead00e510d18ee063503b8e4..eed8ea2602ab0b3231fa1a573353609b01cd7032 100644 (file)
@@ -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();
     }