]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Fix crash when switching back/from mobile layout
authorThibG <thib@sitedethib.com>
Sun, 25 Aug 2019 13:49:02 +0000 (15:49 +0200)
committerThibG <thib@sitedethib.com>
Fri, 11 Oct 2019 20:40:52 +0000 (22:40 +0200)
Port 91582937f34c74dd76dabe7253864da8565f227e to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/components/column_back_button.js
app/javascript/flavours/glitch/components/column_header.js

index 8326cbb79da6282802afbd017b50e22cc4dbe89a..05688f867d199447e84d1b1cc60af081670bd0c2 100644 (file)
@@ -41,7 +41,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 43c9f1144c4f34592a5094f5a053a5a883a9dc36..dd116242909d1bcffec378e65546b0082e9fc293 100644 (file)
@@ -235,7 +235,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);
+      }
     }
   }