Skip to content

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

DEV: Ensure deprecation warning banner works in development builds (#28302)

David Taylordf5561d78069
diff --git a/app/assets/javascripts/discourse/app/components/global-notice.js b/app/assets/javascripts/discourse/app/components/global-notice.js
index 1393d619f65..548f255fe00 100644
--- a/app/assets/javascripts/discourse/app/components/global-notice.js
+++ b/app/assets/javascripts/discourse/app/components/global-notice.js
@@ -2,16 +2,16 @@ import Component from "@ember/component";
import EmberObject, { action } from "@ember/object";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
-import { TrackedArray } from "@ember-compat/tracked-built-ins";
import { tagName } from "@ember-decorators/component";
import cookie, { removeCookie } from "discourse/lib/cookie";
+import { DeferredTrackedSet } from "discourse/lib/tracked-tools";
import { bind } from "discourse-common/utils/decorators";
import I18n from "discourse-i18n";
-const _pluginNotices = new TrackedArray();
+const _pluginNotices = new DeferredTrackedSet();
export function addGlobalNotice(text, id, options = {}) {
- _pluginNotices.push(Notice.create({ text, id, options }));
+ _pluginNotices.add(Notice.create({ text, id, options }));
}
const GLOBAL_NOTICE_DISMISSED_PROMPT_KEY = "dismissed-global-notice-v2";
@@ -153,7 +153,7 @@ export default class GlobalNotice extends Component {
notices.push(this.get("logNotice"));
}
- return notices.concat(_pluginNotices).filter((notice) => {
+ return notices.concat(Array.from(_pluginNotices)).filter((notice) => {
if (notice.options.visibility) {
return notice.options.visibility(notice);
}
diff --git a/spec/system/ember_deprecation_spec.rb b/spec/system/ember_deprecation_spec.rb
index 738d4c642b7..a7c4fcc24a5 100644
--- a/spec/system/ember_deprecation_spec.rb
+++ b/spec/system/ember_deprecation_spec.rb
@@ -52,4 +52,30 @@ describe "JS Deprecation Handling", type: :system do
)
expect(message).to have_text(SiteSetting.warn_critical_js_deprecations_message)
end
+
+ it "can show warnings triggered during initial render" do
+ sign_in Fabricate(:admin)
+
+ t = Fabricate(:theme, name: "Theme With Tests")
+ t.set_field(
+ target: :extra_js,
+ type: :js,
+ name: "discourse/connectors/below-footer/my-connector.gjs",
+ value: <<~JS,
+ import deprecated from "discourse-common/lib/deprecated";
+ function triggerDeprecation(){
+ deprecated("Fake deprecation message", { id: "fake-deprecation" })
+ }
+ export default <template>
+ {{triggerDeprecation}}
+ </template>
+ JS
+ )
+ t.save!
+ SiteSetting.default_theme_id = t.id
+
+ visit "/latest"
+
+ expect(page).to have_css("#global-notice-critical-deprecation")
+ end
end