Skip to content

Migrate the map card to an ES module resource once Home Assistant removes classic "js" resources #151

Description

@it-rec

Background

The interactive map card is currently auto-registered as a classic js Lovelace resource (CARD_RESOURCE_TYPE = "js" in map_card.py). That choice is deliberate: a classic <script> re-executes on every page load even when served from the browser cache, so the custom element is reliably defined before the dashboard renders. An ES module served from cache is not re-executed (the browser keeps its first evaluation in the module map), which caused the intermittent permanent "Configuration error" in #140.

The catch: the js resource type is deprecated in Home Assistant. It still works on all current versions (verified on 2026.6 and 2026.7), but HA may remove it in a future release. When that happens, the card would stop loading for every install that relies on the auto-registered resource.

Proposed enhancement

Switch the card to an ES module resource combined with a per-boot cache-buster, which removes the cached-module failure mode by construction:

  • Mint a token at integration import time (= every HA start) and append it to the resource URL: /terramow-frontend/terramow-map-card.js?v=<version>-<token>.
  • Because the URL is new after every restart, the browser has never evaluated that module before — it always executes, so the element is always defined. Map card fails to load: resource registered as "JavaScript File" instead of "Module" #140's root cause cannot occur.
  • The existing self-heal loop updates the stored Lovelace resource on each boot and also flips old js entries to module automatically, so no user action is needed at migration time.

Cost: one Lovelace resource-storage write per HA start. That's why this shouldn't ship while js still works — it adds churn for no user-visible benefit today.

Prepared implementation

The change is fully implemented, tested (100% coverage maintained), and parked in draft PR #147. It is intentionally left unmerged.

Trigger to act

Merge #147 (after rebasing/re-verifying) when any of these happens:

  • A Home Assistant release note or deprecation warning announces removal of classic js Lovelace resources.
  • Field reports show the card failing to load on a new HA version while registered as js.

Until then this issue just tracks the need so the deprecation doesn't catch us by surprise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions