DEV: Deprecate template overrides (#29544)
Template overrides have been advised against for a long time, and are increasingly hard to maintain as Discourse's development accelerates. This commit officially deprecates this customization method, which will be removed in the not-too-distant future (likely in the first half of 2025).
This commit is contained in:
parent
9c5fc6f1df
commit
216845e4c7
|
@ -1,3 +1,5 @@
|
||||||
|
import deprecated from "./deprecated";
|
||||||
|
|
||||||
const pluginRegex = /^discourse\/plugins\/([^\/]+)\/(.*)$/;
|
const pluginRegex = /^discourse\/plugins\/([^\/]+)\/(.*)$/;
|
||||||
const themeRegex = /^discourse\/theme-([^\/]+)\/(.*)$/;
|
const themeRegex = /^discourse\/theme-([^\/]+)\/(.*)$/;
|
||||||
|
|
||||||
|
@ -77,12 +79,28 @@ class DiscourseTemplateMap {
|
||||||
* theme/plugin namespaces and overrides.
|
* theme/plugin namespaces and overrides.
|
||||||
*/
|
*/
|
||||||
resolve(name) {
|
resolve(name) {
|
||||||
for (const cache of this.prioritizedCaches) {
|
const [themeMatch, pluginMatch, coreMatch] = this.prioritizedCaches.map(
|
||||||
const val = cache.get(name);
|
(cache) => {
|
||||||
if (val) {
|
const val = cache.get(name);
|
||||||
return val[val.length - 1];
|
if (val) {
|
||||||
|
return val[val.length - 1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if ((themeMatch || pluginMatch) && coreMatch) {
|
||||||
|
deprecated(
|
||||||
|
`[${
|
||||||
|
themeMatch || pluginMatch
|
||||||
|
}] Overriding templates is deprecated, and will soon be disabled. Use plugin outlets, CSS, or other customization APIs instead.`,
|
||||||
|
{
|
||||||
|
id: "discourse.resolver-template-overrides",
|
||||||
|
url: "https://meta.discourse.org/t/247487",
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return themeMatch || pluginMatch || coreMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,6 +75,14 @@ export default {
|
||||||
console.error(message);
|
console.error(message);
|
||||||
}
|
}
|
||||||
} else if (originalTemplate) {
|
} else if (originalTemplate) {
|
||||||
|
deprecated(
|
||||||
|
`[${finalOverrideModuleName}] Overriding component templates is deprecated, and will soon be disabled. Use plugin outlets, CSS, or other customization APIs instead.`,
|
||||||
|
{
|
||||||
|
id: "discourse.component-template-overrides",
|
||||||
|
url: "https://meta.discourse.org/t/247487",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const overrideTemplate = require(finalOverrideModuleName).default;
|
const overrideTemplate = require(finalOverrideModuleName).default;
|
||||||
|
|
||||||
COLOCATED_TEMPLATE_OVERRIDES.set(component, overrideTemplate);
|
COLOCATED_TEMPLATE_OVERRIDES.set(component, overrideTemplate);
|
||||||
|
|
|
@ -10,12 +10,16 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated";
|
import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated";
|
||||||
import { registerTemporaryModule } from "../helpers/temporary-module-helper";
|
import { registerTemporaryModule } from "../helpers/temporary-module-helper";
|
||||||
|
|
||||||
function silenceMobileDeprecations(hooks) {
|
function silenceMobileAndOverrideDeprecations(hooks) {
|
||||||
let unsilenceCallback;
|
let unsilenceCallback;
|
||||||
hooks.beforeEach(() => {
|
hooks.beforeEach(() => {
|
||||||
const promise = new Promise((resolve) => (unsilenceCallback = resolve));
|
const promise = new Promise((resolve) => (unsilenceCallback = resolve));
|
||||||
withSilencedDeprecationsAsync(
|
withSilencedDeprecationsAsync(
|
||||||
["discourse.mobile-templates"],
|
[
|
||||||
|
"discourse.mobile-templates",
|
||||||
|
"discourse.resolver-template-overrides",
|
||||||
|
"discourse.component-template-overrides",
|
||||||
|
],
|
||||||
() => promise
|
() => promise
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -112,7 +116,7 @@ function registerTemplateOnlyComponents() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module("Integration | Initializers | plugin-component-templates", function (h) {
|
module("Integration | Initializers | plugin-component-templates", function (h) {
|
||||||
silenceMobileDeprecations(h);
|
silenceMobileAndOverrideDeprecations(h);
|
||||||
|
|
||||||
module("template-only component definition behaviour", function (hooks) {
|
module("template-only component definition behaviour", function (hooks) {
|
||||||
hooks.beforeEach(() => registerTemplateOnlyComponents());
|
hooks.beforeEach(() => registerTemplateOnlyComponents());
|
||||||
|
|
|
@ -295,20 +295,24 @@ module("Unit | Ember | resolver", function (hooks) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Defined in core and plugin
|
// Defined in core and plugin
|
||||||
lookupTemplate(
|
withSilencedDeprecations("discourse.resolver-template-overrides", () => {
|
||||||
assert,
|
lookupTemplate(
|
||||||
"template:bar",
|
assert,
|
||||||
"discourse/plugins/my-plugin/discourse/templates/bar",
|
"template:bar",
|
||||||
"prefers plugin version over core"
|
"discourse/plugins/my-plugin/discourse/templates/bar",
|
||||||
);
|
"prefers plugin version over core"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Defined in core and plugin and theme
|
// Defined in core and plugin and theme
|
||||||
lookupTemplate(
|
withSilencedDeprecations("discourse.resolver-template-overrides", () => {
|
||||||
assert,
|
lookupTemplate(
|
||||||
"template:baz",
|
assert,
|
||||||
"discourse/theme-12/discourse/templates/baz",
|
"template:baz",
|
||||||
"prefers theme version over plugin and core"
|
"discourse/theme-12/discourse/templates/baz",
|
||||||
);
|
"prefers theme version over plugin and core"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Defined in core only
|
// Defined in core only
|
||||||
lookupTemplate(
|
lookupTemplate(
|
||||||
|
@ -330,31 +334,34 @@ module("Unit | Ember | resolver", function (hooks) {
|
||||||
|
|
||||||
setResolverOption("mobileView", true);
|
setResolverOption("mobileView", true);
|
||||||
|
|
||||||
withSilencedDeprecations("discourse.mobile-templates", () => {
|
withSilencedDeprecations(
|
||||||
// Default with plugin template override
|
["discourse.mobile-templates", "discourse.resolver-template-overrides"],
|
||||||
lookupTemplate(
|
() => {
|
||||||
assert,
|
// Default with plugin template override
|
||||||
"template:foo",
|
lookupTemplate(
|
||||||
"discourse/plugins/my-plugin/discourse/templates/mobile/foo",
|
assert,
|
||||||
"finding plugin version even if normal one is not present"
|
"template:foo",
|
||||||
);
|
"discourse/plugins/my-plugin/discourse/templates/mobile/foo",
|
||||||
|
"finding plugin version even if normal one is not present"
|
||||||
|
);
|
||||||
|
|
||||||
// Default with plugin mobile added, takes precedence over non-mobile
|
// Default with plugin mobile added, takes precedence over non-mobile
|
||||||
lookupTemplate(
|
lookupTemplate(
|
||||||
assert,
|
assert,
|
||||||
"template:bar",
|
"template:bar",
|
||||||
"discourse/plugins/my-plugin/discourse/templates/mobile/bar",
|
"discourse/plugins/my-plugin/discourse/templates/mobile/bar",
|
||||||
"preferring plugin mobile version when both non-mobile plugin version is also present"
|
"preferring plugin mobile version when both non-mobile plugin version is also present"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Default with when non-plugin mobile version is present
|
// Default with when non-plugin mobile version is present
|
||||||
lookupTemplate(
|
lookupTemplate(
|
||||||
assert,
|
assert,
|
||||||
"template:baz",
|
"template:baz",
|
||||||
"discourse/plugins/my-plugin/discourse/templates/mobile/baz",
|
"discourse/plugins/my-plugin/discourse/templates/mobile/baz",
|
||||||
"preferring plugin mobile version over non-plugin mobile version"
|
"preferring plugin mobile version over non-plugin mobile version"
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("resolves templates with 'admin' prefix", function (assert) {
|
test("resolves templates with 'admin' prefix", function (assert) {
|
||||||
|
|
Loading…
Reference in New Issue