DEV: Ensure plugin outlet parentView deprecation cannot be avoided (#27973)

We'd implemented the deprecation by overriding `get parentView`, and storing the real value on `_parentView`. Unfortunately that meant people could access `_parentView` directly, thereby bypassing the deprecation message.

This commit moves the internal storage to a private field, which cannot be accessed from outside the class. A deprecated getter for `_parentView` is introduced to avoid immediate breakage for any code using this workaround.
This commit is contained in:
David Taylor 2024-07-18 16:48:46 +01:00 committed by GitHub
parent 79e0aa6a64
commit 445951e854
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,7 +50,6 @@ const ARGS_DEPRECATION_MSG =
export default class PluginOutletComponent extends GlimmerComponentWithDeprecatedParentView { export default class PluginOutletComponent extends GlimmerComponentWithDeprecatedParentView {
@service clientErrorHandler; @service clientErrorHandler;
context = { context = {
...helperContext(), ...helperContext(),
get parentView() { get parentView() {
@ -64,6 +63,8 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate
}, },
}; };
#parentView;
constructor() { constructor() {
const result = super(...arguments); const result = super(...arguments);
@ -136,10 +137,13 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate
deprecated(`${PARENT_VIEW_DEPRECATION_MSG} (outlet: ${this.args.name})`, { deprecated(`${PARENT_VIEW_DEPRECATION_MSG} (outlet: ${this.args.name})`, {
id: "discourse.plugin-outlet-parent-view", id: "discourse.plugin-outlet-parent-view",
}); });
return this._parentView; return this.#parentView;
} }
set parentView(value) { set parentView(value) {
this._parentView = value; this.#parentView = value;
}
get _parentView() {
return this.parentView;
} }
// Older plugin outlets have a `tagName` which we need to preserve for backwards-compatibility // Older plugin outlets have a `tagName` which we need to preserve for backwards-compatibility
@ -149,16 +153,21 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate
} }
class PluginOutletWithTagNameWrapper extends ClassicComponent { class PluginOutletWithTagNameWrapper extends ClassicComponent {
#parentView;
// Overridden parentView to make this wrapper 'transparent' // Overridden parentView to make this wrapper 'transparent'
// Calling this will trigger the deprecation notice in PluginOutletComponent // Calling this will trigger the deprecation notice in PluginOutletComponent
get parentView() { get parentView() {
// init() of CoreView calls `this.parentView`. That would trigger the deprecation notice, // init() of CoreView calls `this.parentView`. That would trigger the deprecation notice,
// so skip it until this component is initialized. // so skip it until this component is initialized.
if (this._state) { if (this._state) {
return this._parentView.parentView; return this.#parentView.parentView;
} }
} }
set parentView(value) { set parentView(value) {
this._parentView = value; this.#parentView = value;
}
get _parentView() {
return this.parentView;
} }
} }