Skip to content

A platform for community discussion. Free, open, simple.

FIX: Avoid possible rendering infinite-loop in post-menu (#30873)

David Taylor89df65e8434c
diff --git a/app/assets/javascripts/discourse/app/components/post/menu.gjs b/app/assets/javascripts/discourse/app/components/post/menu.gjs
index ed70c9cc0f2..44883fd886d 100644
--- a/app/assets/javascripts/discourse/app/components/post/menu.gjs
+++ b/app/assets/javascripts/discourse/app/components/post/menu.gjs
@@ -3,7 +3,6 @@ import { cached, tracked } from "@glimmer/tracking";
import { hash } from "@ember/helper";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
-import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { service } from "@ember/service";
import { isEmpty, isPresent } from "@ember/utils";
import { and, eq } from "truth-helpers";
@@ -396,11 +395,6 @@ export default class PostMenu extends Component {
return items;
}
- @action
- expandIfOnlyOneHiddenButton() {
- this.collapsed = this.renderableCollapsedButtons.length > 1;
- }
-
@cached
get renderableCollapsedButtons() {
return this.availableCollapsedButtons.filter((button) =>
@@ -410,9 +404,13 @@ export default class PostMenu extends Component {
@cached
get visibleButtons() {
- const nonCollapsed = this.availableButtons.filter((button) => {
- return !this.availableCollapsedButtons.includes(button);
- });
+ let nonCollapsed = this.availableButtons;
+
+ if (this.renderableCollapsedButtons.length > 1) {
+ nonCollapsed = nonCollapsed.filter((button) => {
+ return !this.renderableCollapsedButtons.includes(button);
+ });
+ }
return DAG.from(
nonCollapsed.map((button) => [button.key, button, button.position]),
@@ -609,7 +607,6 @@ export default class PostMenu extends Component {
"replies-button-visible"
)
}}
- {{didInsert this.expandIfOnlyOneHiddenButton}}
>
{{! do not include PluginOutlets here, use the PostMenu DAG API instead }}
{{#each this.extraControls key="key" as |extraControl|}}
diff --git a/app/assets/javascripts/discourse/app/components/post/menu/buttons/show-more.gjs b/app/assets/javascripts/discourse/app/components/post/menu/buttons/show-more.gjs
index d4aaa78c650..0fb6c4476e6 100644
--- a/app/assets/javascripts/discourse/app/components/post/menu/buttons/show-more.gjs
+++ b/app/assets/javascripts/discourse/app/components/post/menu/buttons/show-more.gjs
@@ -3,7 +3,7 @@ import DButton from "discourse/components/d-button";
export default class PostMenuShowMoreButton extends Component {
static shouldRender(args) {
- return args.state.collapsedButtons.length && args.state.collapsed;
+ return args.state.collapsedButtons.length > 1 && args.state.collapsed;
}
<template>