]> cat aescling's git repositories - mastodon.git/commitdiff
Fix crash when switching back/from mobile layout (#11655)
authorThibG <thib@sitedethib.com>
Sun, 25 Aug 2019 13:49:02 +0000 (15:49 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 25 Aug 2019 13:49:02 +0000 (15:49 +0200)
Fixes #11630

app/javascript/mastodon/components/column_back_button.js
app/javascript/mastodon/components/column_header.js

index cc0e5c07c3c06c5b657eb7be78701185266d58fe..d97622705e588b8951cbf0197c714ae0a37fe07e 100644 (file)
@@ -35,7 +35,19 @@ export default class ColumnBackButton extends React.PureComponent {
     if (multiColumn) {
       return component;
     } else {
-      return createPortal(component, document.getElementById('tabs-bar__portal'));
+      // The portal container and the component may be rendered to the DOM in
+      // the same React render pass, so the container might not be available at
+      // the time `render()` is called.
+      const container = document.getElementById('tabs-bar__portal');
+      if (container === null) {
+        // The container wasn't available, force a re-render so that the
+        // component can eventually be inserted in the container and not scroll
+        // with the rest of the area.
+        this.forceUpdate();
+        return component;
+      } else {
+        return createPortal(component, container);
+      }
     }
   }
 
index 89c5fe723febd6346e04b7b9e8e5c2d2ad98a28d..8a26742b577b9c43b1502c7db0941c3c7a735668 100644 (file)
@@ -178,7 +178,19 @@ class ColumnHeader extends React.PureComponent {
     if (multiColumn || placeholder) {
       return component;
     } else {
-      return createPortal(component, document.getElementById('tabs-bar__portal'));
+      // The portal container and the component may be rendered to the DOM in
+      // the same React render pass, so the container might not be available at
+      // the time `render()` is called.
+      const container = document.getElementById('tabs-bar__portal');
+      if (container === null) {
+        // The container wasn't available, force a re-render so that the
+        // component can eventually be inserted in the container and not scroll
+        // with the rest of the area.
+        this.forceUpdate();
+        return component;
+      } else {
+        return createPortal(component, container);
+      }
     }
   }