Skip to content

Commit fa932db

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Fix crash when switching back/from mobile layout (mastodon#11655)
Fixes mastodon#11630
1 parent 37a826f commit fa932db

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

app/javascript/mastodon/components/column_back_button.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@ export default class ColumnBackButton extends React.PureComponent {
3535
if (multiColumn) {
3636
return component;
3737
} else {
38-
return createPortal(component, document.getElementById('tabs-bar__portal'));
38+
// The portal container and the component may be rendered to the DOM in
39+
// the same React render pass, so the container might not be available at
40+
// the time `render()` is called.
41+
const container = document.getElementById('tabs-bar__portal');
42+
if (container === null) {
43+
// The container wasn't available, force a re-render so that the
44+
// component can eventually be inserted in the container and not scroll
45+
// with the rest of the area.
46+
this.forceUpdate();
47+
return component;
48+
} else {
49+
return createPortal(component, container);
50+
}
3951
}
4052
}
4153

app/javascript/mastodon/components/column_header.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,19 @@ class ColumnHeader extends React.PureComponent {
178178
if (multiColumn || placeholder) {
179179
return component;
180180
} else {
181-
return createPortal(component, document.getElementById('tabs-bar__portal'));
181+
// The portal container and the component may be rendered to the DOM in
182+
// the same React render pass, so the container might not be available at
183+
// the time `render()` is called.
184+
const container = document.getElementById('tabs-bar__portal');
185+
if (container === null) {
186+
// The container wasn't available, force a re-render so that the
187+
// component can eventually be inserted in the container and not scroll
188+
// with the rest of the area.
189+
this.forceUpdate();
190+
return component;
191+
} else {
192+
return createPortal(component, container);
193+
}
182194
}
183195
}
184196

0 commit comments

Comments
 (0)