]> cat aescling's git repositories - mastodon.git/blobdiff - app/javascript/mastodon/components/column_back_button.js
Fix crash when switching back/from mobile layout (#11655)
[mastodon.git] / app / javascript / mastodon / components / column_back_button.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);
+      }
     }
   }
 
This page took 0.02652 seconds and 3 git commands to generate.