Skip to content

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

DEV: Promote modifyClass warning to error (#28300)

David Taylorb59b24884ff1
diff --git a/app/assets/javascripts/discourse-common/addon/resolver.js b/app/assets/javascripts/discourse-common/addon/resolver.js
index d8356d917e2..6cfbded2825 100644
--- a/app/assets/javascripts/discourse-common/addon/resolver.js
+++ b/app/assets/javascripts/discourse-common/addon/resolver.js
@@ -115,10 +115,6 @@ const DEPRECATED_MODULES = new Map(
})
);
-export function normalizeDeprecatedModule(name) {
- return DEPRECATED_MODULES.get(name)?.newName || name;
-}
-
export function setResolverOption(name, value) {
_options[name] = value;
}
diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs
index 9ed9a97e8c3..a1ce362174d 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs
@@ -159,7 +159,6 @@ import {
registerIconRenderer,
replaceIcon,
} from "discourse-common/lib/icon-library";
-import { normalizeDeprecatedModule } from "discourse-common/resolver";
import { addImageWrapperButton } from "discourse-markdown-it/features/image-controls";
import { CUSTOM_USER_SEARCH_OPTIONS } from "select-kit/components/user-chooser";
import { modifySelectKit } from "select-kit/mixins/plugin-api";
@@ -254,26 +253,27 @@ class PluginApi {
_resolveClass(resolverName, opts) {
opts = opts || {};
-
+ const normalized = this.container.registry.normalize(resolverName);
if (
- this.container.cache[normalizeDeprecatedModule(resolverName)] ||
- (resolverName === "model:user" &&
+ this.container.cache[normalized] ||
+ (normalized === "model:user" &&
this.container.lookup("service:current-user"))
) {
// eslint-disable-next-line no-console
- console.warn(
+ console.error(
consolePrefix(),
`Attempted to modify "${resolverName}", but it was already initialized earlier in the boot process (e.g. via a lookup()). Remove that lookup, or move the modifyClass call earlier in the boot process for changes to take effect. https://meta.discourse.org/t/262064`
);
+ return;
}
- const klass = this.container.factoryFor(resolverName);
+ const klass = this.container.factoryFor(normalized);
if (!klass) {
if (!opts.ignoreMissing) {
// eslint-disable-next-line no-console
console.warn(
consolePrefix(),
- `"${resolverName}" was not found by modifyClass`
+ `"${normalized}" was not found by modifyClass`
);
}
return;