DEV: Add safe_mode=deprecation_errors mode (#24870)

This commit adds an additional toggle to our safe-mode system. When enabled, it will cause all deprecation messages to become exceptions. This gives admins a way to test their themes/plugins against upcoming Discourse changes without needing to use the browser developer tools.
This commit is contained in:
David Taylor 2023-12-13 14:06:59 +00:00 committed by GitHub
parent 7da33ad6ba
commit fadcfd1451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 7 deletions

View File

@ -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
}

View File

@ -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;
}
},
};

View File

@ -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

View File

@ -22,6 +22,17 @@
<%= t 'safe_mode.no_plugins' %>
</label>
</p>
<p>
<%= t 'safe_mode.deprecation_error_description' %>
</p>
<p>
<label>
<%= check_box_tag 'deprecation_errors', true, false %>
<%= t 'safe_mode.deprecation_error_label' %>
</label>
</p>
<p>
<%= submit_tag t('safe_mode.enter'), class: 'btn btn-danger' %>
<%- if flash[:must_select] %>

View File

@ -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: