diff --git a/app/assets/javascripts/discourse-common/addon/lib/deprecated.js b/app/assets/javascripts/discourse-common/addon/lib/deprecated.js index 0b164f1dffd..bce9aebe86b 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/deprecated.js +++ b/app/assets/javascripts/discourse-common/addon/lib/deprecated.js @@ -1,7 +1,7 @@ const handlers = []; const disabledDeprecations = new Set(); -const emberCliDeprecationWorkflows = - window.deprecationWorkflow?.config?.workflow; +const deprecationWorkflow = window.deprecationWorkflow; +const workflows = deprecationWorkflow?.config?.workflow; let emberDeprecationSilencer; @@ -47,14 +47,16 @@ export default function deprecated(msg, options = {}) { handlers.forEach((h) => h(msg, options)); - if (raiseError) { + const matchedWorkflow = workflows?.find((w) => w.matchId === id); + + if ( + raiseError || + matchedWorkflow?.handler === "throw" || + (!matchedWorkflow && deprecationWorkflow.throwOnUnhandled) + ) { throw msg; } - const matchedWorkflow = emberCliDeprecationWorkflows?.find( - (w) => w.matchId === id - ); - if (matchedWorkflow?.handler !== "silence") { console.warn(...[consolePrefix, msg].filter(Boolean)); //eslint-disable-line no-console } diff --git a/app/assets/javascripts/discourse/app/initializers/deprecation-error-mode.js b/app/assets/javascripts/discourse/app/initializers/deprecation-error-mode.js new file mode 100644 index 00000000000..1d98752debe --- /dev/null +++ b/app/assets/javascripts/discourse/app/initializers/deprecation-error-mode.js @@ -0,0 +1,9 @@ +export default { + initialize() { + const params = new URLSearchParams(window.location.search); + if (params.get("safe_mode")?.split(",").includes("deprecation_errors")) { + window.deprecationWorkflow.throwOnUnhandled = true; + return; + } + }, +}; diff --git a/app/controllers/safe_mode_controller.rb b/app/controllers/safe_mode_controller.rb index 53cc0cff32b..bbc160c6823 100644 --- a/app/controllers/safe_mode_controller.rb +++ b/app/controllers/safe_mode_controller.rb @@ -19,6 +19,8 @@ class SafeModeController < ApplicationController safe_mode << "no_plugins" elsif params["no_unofficial_plugins"] == "true" safe_mode << "no_unofficial_plugins" + elsif params["deprecation_errors"] == "true" + safe_mode << "deprecation_errors" end if safe_mode.length > 0 diff --git a/app/views/safe_mode/index.html.erb b/app/views/safe_mode/index.html.erb index d5d8cc0728f..070d23d993b 100644 --- a/app/views/safe_mode/index.html.erb +++ b/app/views/safe_mode/index.html.erb @@ -22,6 +22,17 @@ <%= t 'safe_mode.no_plugins' %>
+ ++ <%= t 'safe_mode.deprecation_error_description' %> +
++ +
+<%= submit_tag t('safe_mode.enter'), class: 'btn btn-danger' %> <%- if flash[:must_select] %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 6895dba7310..25c86022c78 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -5073,6 +5073,8 @@ en: no_themes: "Disable themes and theme components" no_unofficial_plugins: "Disable unofficial client-side plugin customizations" no_plugins: "Disable all client-side plugin customizations" + deprecation_error_description: "To check for compatibility with upcoming Discourse updates, you can make Javascript deprecations raise an error:" + deprecation_error_label: Make Javascript deprecations raise an error enter: "Enter Safe Mode" must_select: "You must select at least one option to enter safe mode." wizard: