Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick(#6948): Ensure that dynamically created vue components are destroyed #6958

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/plugins/charts/scatter/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ export default function () {
};

function getScatterPlotFormControl(openmct) {
let destroyComponent;

return {
show(element, model, onChange) {
const { vNode } = mount(
const { vNode, destroy } = mount(
{
el: element,
components: {
Expand All @@ -122,8 +124,12 @@ export default function () {
element
}
);
destroyComponent = destroy;

return vNode;
},
destroy() {
destroyComponent();
}
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/clearData/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function plugin(appliesToObjects, options = { indicator: true })

return function install(openmct) {
if (installIndicator) {
const { vNode } = mount(
const { vNode, destroy } = mount(
{
components: {
GlobalClearIndicator
Expand All @@ -49,7 +49,8 @@ export default function plugin(appliesToObjects, options = { indicator: true })
let indicator = {
element: vNode.el,
key: 'global-clear-indicator',
priority: openmct.priority.DEFAULT
priority: openmct.priority.DEFAULT,
destroy: destroy
};

openmct.indicators.add(indicator);
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/gauge/GaugePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ export default function () {
};

function getGaugeFormController(openmct) {
let destroyComponent;

return {
show(element, model, onChange) {
const { vNode } = mount(
const { vNode, destroy } = mount(
{
el: element,
components: {
Expand All @@ -191,8 +193,12 @@ export default function () {
element
}
);
destroyComponent = destroy;

return vNode.componentInstance;
},
destroy() {
destroyComponent();
}
};
}
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/imagery/components/ImageryTimeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export default {
if (this.unlisten) {
this.unlisten();
}
if (this.destroyImageryContainer) {
this.destroyImageryContainer();
}
},
methods: {
setTimeContext() {
Expand Down Expand Up @@ -237,7 +240,10 @@ export default {
imageryContainer = existingContainer;
imageryContainer.style.maxWidth = `${containerWidth}px`;
} else {
const { vNode } = mount(
if (this.destroyImageryContainer) {
this.destroyImageryContainer();
}
const { vNode, destroy } = mount(
{
components: {
SwimLane
Expand All @@ -257,6 +263,7 @@ export default {
}
);

this.destroyImageryContainer = destroy;
const component = vNode.componentInstance;
this.$refs.imageryHolder.appendChild(component.$el);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export default {
drawerElement.innerHTML = '<div></div>';
const divElement = document.querySelector('.l-shell__drawer div');

mount(
if (this.destroySnapshotContainer) {
this.destroySnapshotContainer();
}
const { destroy } = mount(
{
el: divElement,
components: {
Expand All @@ -113,6 +116,7 @@ export default {
element: divElement
}
);
this.destroySnapshotContainer = destroy;
},
updateSnapshotIndicatorTitle() {
const snapshotCount = this.snapshotContainer.getSnapshots().length;
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/notebook/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function installBaseNotebookFunctionality(openmct) {
openmct.actions.register(new CopyToNotebookAction(openmct));
openmct.actions.register(new ExportNotebookAsTextAction(openmct));

const { vNode } = mount(
const { vNode, destroy } = mount(
{
components: {
NotebookSnapshotIndicator
Expand All @@ -102,7 +102,8 @@ function installBaseNotebookFunctionality(openmct) {
const indicator = {
element: vNode.el,
key: 'notebook-snapshot-indicator',
priority: openmct.priority.DEFAULT
priority: openmct.priority.DEFAULT,
destroy: destroy
};

openmct.indicators.add(indicator);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/notificationIndicator/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import NotificationIndicator from './components/NotificationIndicator.vue';

export default function plugin() {
return function install(openmct) {
const { vNode } = mount(
const { vNode, destroy } = mount(
{
components: {
NotificationIndicator
Expand All @@ -42,7 +42,8 @@ export default function plugin() {
let indicator = {
key: 'notifications-indicator',
element: vNode.el,
priority: openmct.priority.DEFAULT
priority: openmct.priority.DEFAULT,
destroy: destroy
};
openmct.indicators.add(indicator);
};
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/plot/stackedPlot/StackedPlotItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default {
this.composition.load();
}

const { vNode } = mount(
const { vNode, destroy } = mount(
{
components: {
Plot
Expand Down Expand Up @@ -249,6 +249,7 @@ export default {
}
);
this.component = vNode.componentInstance;
this._destroy = destroy;

if (this.isEditing) {
this.setSelection();
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/userIndicator/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import UserIndicator from './components/UserIndicator.vue';

export default function UserIndicatorPlugin() {
function addIndicator(openmct) {
const { vNode } = mount(
const { vNode, destroy } = mount(
{
components: {
UserIndicator
Expand All @@ -43,7 +43,8 @@ export default function UserIndicatorPlugin() {
openmct.indicators.add({
key: 'user-indicator',
element: vNode.el,
priority: openmct.priority.HIGH
priority: openmct.priority.HIGH,
destroy: destroy
});
}

Expand Down