Skip to content

Skip dashboard resource for plugins loaded through extra_module_url - #5551

Open
PilaScat wants to merge 1 commit into
hacs:mainfrom
PilaScat:skip-resource-when-extra-module-url
Open

PilaScat wants to merge 1 commit into
hacs:mainfrom
PilaScat:skip-resource-when-extra-module-url

Conversation

@PilaScat

Copy link
Copy Markdown

Proposed change

Some plugins are meant to be loaded through frontend: extra_module_url instead of, or before, dashboard resources. custom-brand-icons is one example: its icons are also used outside dashboards, so the user adds it to extra_module_url.

When such a plugin is installed or updated, update_dashboard_resources finds no entry under /hacsfiles/<name>/ and creates one. The user can delete it, but it comes back on the next update. The module then loads twice on every page, because ES modules are keyed by URL and the two URLs differ (/local/community/<name>/... vs /hacsfiles/<name>/...?hacstag=...). For custom-brand-icons that is 4.7 MB of JavaScript fetched and evaluated twice. Google Cast receivers only read dashboard resources, so they fetch it as well even when the cast dashboard does not use it.

With this change, update_dashboard_resources does not create a new resource when the plugin is already registered in extra_module_url under /hacsfiles/<name>/ or /local/community/<name>/. It reads the list through hass.data[DATA_EXTRA_MODULE_URL], the same registry that add_extra_js_url (already used by HACS for iconset.js) writes to.

What does not change:

  • An existing resource is still updated to the new hacstag as before. A user who keeps both registrations, for example to keep a plugin available on Cast, sees no difference.
  • Plugins that are not in extra_module_url behave exactly as before.
  • No new hacs.json key, so plugin authors and users have nothing to configure.

Related: #5516, which proposes the opposite direction (letting plugins opt into extra_module_url registration). The two changes do not conflict.

Tests added:

  • no resource is created when extra_module_url points at the plugin under /hacsfiles/<name>/, or under /local/community/<name>/;
  • the resource is still created when extra_module_url points at another plugin whose name shares a prefix (plugin-basic-extra).

Type of change

  • Bugfix (non-breaking change which fixes an issue)

Checklist

  • The code change is tested and works locally.
  • Local tests pass.
  • There is no commented out code in this PR.

🤖 Generated with Claude Code

When a plugin is already registered in frontend extra_module_url under
/hacsfiles/<name>/ or /local/community/<name>/, do not create a new
dashboard resource for it on install or update. The module would
otherwise load twice, because the two URLs differ, and the resource
comes back on every update after the user deletes it.

Existing resources are still updated as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant