diff --git a/shell/core/plugins.js b/shell/core/plugins.js index 6dfa825966f..cedc95e9bab 100644 --- a/shell/core/plugins.js +++ b/shell/core/plugins.js @@ -78,72 +78,43 @@ export default function(context, inject, vueApp) { element.id = id; element.dataset.purpose = 'extension'; - // id is `-`. - 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')); - } - - // Update the timestamp that new plugins were loaded - may be needed - // to update caches when new plugins are loaded - _lastLoaded = new Date().getTime(); - - // name is the name of the plugin, including the version number - const plugin = new Plugin(id); - - plugins[id] = plugin; + element.onload = () => { + if (!window[id]) { + return reject(new Error('Could not load plugin code')); + } - // Initialize the plugin - window[id].default(plugin, this.internal()); + // Update the timestamp that new plugins were loaded - may be needed + // to update caches when new plugins are loaded + _lastLoaded = new Date().getTime(); - // Uninstall existing plugin if there is one - this.removePlugin(plugin.name); // Removing this causes the plugin to not load on refresh + // name is the name of the plugin, including the version number + const plugin = new Plugin(id); - // Load all of the types etc from the plugin - this.applyPlugin(plugin); + plugins[id] = plugin; - // Add the plugin to the store - store.dispatch('uiplugins/addPlugin', plugin); + // Initialize the plugin + window[id].default(plugin, this.internal()); - resolve(); - }; + // Load all of the types etc from the plugin + this.applyPlugin(plugin); - element.onerror = (e) => { - element.parentElement.removeChild(element); + // Add the plugin to the store + store.dispatch('uiplugins/addPlugin', plugin); - // Massage the error into something useful - const errorMessage = `Failed to load script from '${ e.target.src }'`; + resolve(); + }; - console.error(errorMessage, e); // eslint-disable-line no-console - reject(new Error(errorMessage)); // This is more useful where it's used - }; + element.onerror = (e) => { + element.parentElement.removeChild(element); - document.head.appendChild(element); - }).catch((e) => { - const errorMessage = `Failed to unload old plugin${ oldPlugin?.id }`; + // Massage the error into something useful + const errorMessage = `Failed to load script from '${ e.target.src }'`; console.error(errorMessage, e); // eslint-disable-line no-console reject(new Error(errorMessage)); // This is more useful where it's used - }); + }; + + document.head.appendChild(element); }); },