Merge pull request #12822 from codyrancher/remove-unload

Removing unload logic from the plugin load logic
This commit is contained in:
codyrancher 2025-01-30 16:00:53 -07:00 committed by GitHub
commit 76d7af2620
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 54 deletions

View File

@ -78,26 +78,6 @@ export default function(context, inject, vueApp) {
element.id = id;
element.dataset.purpose = 'extension';
// id is `<product>-<version>`.
const oldPlugin = Object.values(plugins).find((p) => id.startsWith(p.name));
let removed = Promise.resolve();
if (oldPlugin) {
// Uninstall existing plugin if there is one. This ensures that last loaded plugin is not always used
// (nav harv1-->harv2-->harv1 and harv2 would be shown)
removed = this.removePlugin(oldPlugin.name).then(() => {
delete window[oldPlugin.id];
delete plugins[oldPlugin.id];
const oldElement = document.getElementById(oldPlugin.id);
oldElement.parentElement.removeChild(oldElement);
});
}
removed.then(() => {
element.onload = () => {
if (!window[id]) {
return reject(new Error('Could not load plugin code'));
@ -115,9 +95,6 @@ export default function(context, inject, vueApp) {
// Initialize the plugin
window[id].default(plugin, this.internal());
// Uninstall existing plugin if there is one
this.removePlugin(plugin.name); // Removing this causes the plugin to not load on refresh
// Load all of the types etc from the plugin
this.applyPlugin(plugin);
@ -138,12 +115,6 @@ export default function(context, inject, vueApp) {
};
document.head.appendChild(element);
}).catch((e) => {
const errorMessage = `Failed to unload old plugin${ oldPlugin?.id }`;
console.error(errorMessage, e); // eslint-disable-line no-console
reject(new Error(errorMessage)); // This is more useful where it's used
});
});
},