Skip to content

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

FIX: Ensure dialogs are still rendered if triggered during boot (#22511)

David Taylored2dae6d1ad4
diff --git a/app/assets/javascripts/dialog-holder/addon/services/dialog.js b/app/assets/javascripts/dialog-holder/addon/services/dialog.js
index 0724bbe81ca..3ccaaf2df1a 100644
--- a/app/assets/javascripts/dialog-holder/addon/services/dialog.js
+++ b/app/assets/javascripts/dialog-holder/addon/services/dialog.js
@@ -1,6 +1,7 @@
import Service from "@ember/service";
import A11yDialog from "a11y-dialog";
import { bind } from "discourse-common/utils/decorators";
+import { next } from "@ember/runloop";
export default Service.extend({
dialogInstance: null,
@@ -26,7 +27,7 @@ export default Service.extend({
class: null,
_confirming: false,
- dialog(params) {
+ async dialog(params) {
const {
message,
bodyComponent,
@@ -48,7 +49,19 @@ export default Service.extend({
buttons,
} = params;
- const element = document.getElementById("dialog-holder");
+ let element = document.getElementById("dialog-holder");
+ if (!element) {
+ await new Promise((resolve) => next(resolve));
+ element = document.getElementById("dialog-holder");
+ }
+
+ if (!element) {
+ const msg =
+ "dialog-holder wrapper element not found. Unable to render dialog";
+ // eslint-disable-next-line no-console
+ console.error(msg, params);
+ throw new Error(msg);
+ }
this.setProperties({
message,
diff --git a/plugins/chat/spec/system/visit_channel_spec.rb b/plugins/chat/spec/system/visit_channel_spec.rb
index 81e7cd1c14b..96a03b6b6e5 100644
--- a/plugins/chat/spec/system/visit_channel_spec.rb
+++ b/plugins/chat/spec/system/visit_channel_spec.rb
@@ -61,7 +61,7 @@ RSpec.describe "Visit channel", type: :system do
end
context "when channel is not found" do
- xit "shows an error" do
+ it "shows an error" do
visit("/chat/c/-/999")
expect(page).to have_content("Not Found") # this is not a translated key
@@ -78,7 +78,7 @@ RSpec.describe "Visit channel", type: :system do
context "when channel is not accessible" do
context "when category channel" do
- xit "shows an error" do
+ it "shows an error" do
chat.visit_channel(private_category_channel_1)
expect(page).to have_content(I18n.t("invalid_access"))
@@ -86,7 +86,7 @@ RSpec.describe "Visit channel", type: :system do
end
context "when direct message channel" do
- xit "shows an error" do
+ it "shows an error" do
chat.visit_channel(inaccessible_dm_channel_1)
expect(page).to have_content(I18n.t("invalid_access"))
@@ -111,7 +111,7 @@ RSpec.describe "Visit channel", type: :system do
)
end
- xit "shows an error" do
+ it "shows an error" do
chat.visit_channel(inaccessible_dm_channel_1)
expect(page).to have_content(I18n.t("invalid_access"))