Umbraco.CMS.Backoffice icon indicating copy to clipboard operation
Umbraco.CMS.Backoffice copied to clipboard

[BUG]: Unloading extensions from entry point feels hacky

Open enkelmedia opened this issue 10 months ago • 1 comments

Describe the bug I have a package that replaces the dictionary dashboard with a custom dashboard. When I played with the API to unregister a certain extension it did not really work as I expected.

I did something like this:

export const onInit: UmbEntryPointOnInit = (host, extensionRegistry) => {
    if(extensionRegistry.isRegistered("Umb.Dashboard.Dictionary.Overview")) 
    {
        extensionRegistry.unregister("Umb.Dashboard.Dictionary.Overview");
    }
};

I noticed a couple of things.

First, the Entry Point for my extension is always loaded before the extensions from the backoffice. No matter if I set the weight in umbraco-package.json to something crazy. No matter this use case I think it would make more sense if the core stuff is loaded before any packages, right now my custom section shows up first.

umb-entry-point-loading

I guess that the best things would be if we could use weight to control this.

Since my goal is to remove the dashboard I right now need to write some hack that pulls the registry to look for the dashboard extension and remove it as soon as it shows up. I know that the registry is very dynamic but maybe it would be possible to add something where a entry point could add a callback to be called when all the initial loadings has been done? It actually looks like UmbBackofficeElement is loading the bundles (used by core) first and then entry points, maybe the last thing in this loading-chain could call some callback or something.

Or maybe that any call to "unregister" will keep the alias of the extension if it was not found and block the next call to add it, then remove it from the "block list" so that any subsequential call would add it - think out loud here.

I mean, I can always chain a couple of setTimeout and remove the extension but it feels like it would be nice if the core could provide a nicer API for this.

This is what I currently need to do do make it work:

setTimeout(() => {
    if(extensionRegistry.isRegistered("Umb.Dashboard.Dictionary.Overview")) 
    {
        extensionRegistry.unregister("Umb.Dashboard.Dictionary.Overview");
    }
},2500);

Let me know what you think, happy yo help out if I know the preferred direction.

enkelmedia avatar Apr 05 '24 21:04 enkelmedia