From 019ba099c84f2e2e4fa0053588707acd2e728376 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 21 Nov 2024 16:35:05 +0000 Subject: [PATCH] DEV: Unsilence this-property-fallback deprecation (#29855) This one has the potential to be very noisy, so a special dedupliation handler is introduced. https://meta.discourse.org/t/337276 --- .../addon/deprecation-workflow.js | 4 -- ...recation-this-property-fallback-handler.js | 44 +++++++++++++++++++ .../discourse/app/lib/highlight-syntax.js | 2 +- .../services/deprecation-warning-handler.js | 7 ++- 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/initializers/deprecation-this-property-fallback-handler.js diff --git a/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js b/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js index 30a83f6d61e..5782e89fc56 100644 --- a/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js +++ b/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js @@ -1,8 +1,4 @@ const DEPRECATION_WORKFLOW = [ - { - handler: "silence", - matchId: "ember-this-fallback.this-property-fallback", - }, { handler: "silence", matchId: "discourse.select-kit" }, { handler: "silence", diff --git a/app/assets/javascripts/discourse/app/initializers/deprecation-this-property-fallback-handler.js b/app/assets/javascripts/discourse/app/initializers/deprecation-this-property-fallback-handler.js new file mode 100644 index 00000000000..a431af71966 --- /dev/null +++ b/app/assets/javascripts/discourse/app/initializers/deprecation-this-property-fallback-handler.js @@ -0,0 +1,44 @@ +import { registerDeprecationHandler } from "@ember/debug"; +import { consolePrefix, getThemeInfo } from "discourse/lib/source-identifier"; + +let registered = false; +const seenMessages = new Set(); + +export default { + initialize() { + if (registered) { + return; + } + + registerDeprecationHandler((message, options, next) => { + if (options.id !== "ember-this-fallback.this-property-fallback") { + return; + } + + // These errors don't have useful backtraces, but we can parse theme/plugin + // info from the message itself. + const pluginMatch = message.match(/\/plugins\/([\w-]+)\//)?.[1]; + const themeIdMatch = message.match(/\/theme-(\d+)\//)?.[1]; + + if (pluginMatch || themeIdMatch) { + const source = { + type: pluginMatch ? "plugin" : "theme", + name: pluginMatch || getThemeInfo(parseInt(themeIdMatch, 10)), + id: themeIdMatch, + }; + options.source = source; + message = `${consolePrefix(null, source)} ${message}`; + } + + // Only print each message once, to avoid flood of console noise + if (seenMessages.has(message)) { + return; + } + seenMessages.add(message); + options.url = "https://meta.discourse.org/t/337276"; + next(message, options); + }); + + registered = true; + }, +}; diff --git a/app/assets/javascripts/discourse/app/lib/highlight-syntax.js b/app/assets/javascripts/discourse/app/lib/highlight-syntax.js index 279f0069832..6188932840c 100644 --- a/app/assets/javascripts/discourse/app/lib/highlight-syntax.js +++ b/app/assets/javascripts/discourse/app/lib/highlight-syntax.js @@ -1,4 +1,4 @@ -import DEBUG from "@glimmer/env"; +import { DEBUG } from "@glimmer/env"; import { waitForPromise } from "@ember/test-waiters"; import mergeHTMLPlugin from "discourse/lib/highlight-syntax-merge-html-plugin"; import { isTesting } from "discourse-common/config/environment"; diff --git a/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js b/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js index d9c494d1496..331bade034f 100644 --- a/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js +++ b/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js @@ -1,3 +1,4 @@ +import { DEBUG } from "@glimmer/env"; import { registerDeprecationHandler } from "@ember/debug"; import Service, { service } from "@ember/service"; import { addGlobalNotice } from "discourse/components/global-notice"; @@ -19,9 +20,13 @@ export const CRITICAL_DEPRECATIONS = [ "discourse.plugin-outlet-tag-name", "discourse.plugin-outlet-parent-view", "discourse.d-button-action-string", - /^(?!discourse\.)/, // All unsilenced ember deprecations ]; +if (DEBUG) { + // used in system specs + CRITICAL_DEPRECATIONS.push("fake-deprecation"); +} + // Deprecation handling APIs don't have any way to unregister handlers, so we set up permanent // handlers and link them up to the application lifecycle using module-local state. let handler;