fix: prevent duplicate config form in editor (async _renderEditor race condition) - #10
Open
eliseo-juan wants to merge 3 commits into
Open
fix: prevent duplicate config form in editor (async _renderEditor race condition)#10eliseo-juan wants to merge 3 commits into
eliseo-juan wants to merge 3 commits into
Conversation
When Music Assistant has multiple integrations of the same provider (e.g. 2–3 Spotify accounts), the card now lets users filter content to a specific account via a new optional `provider_instance` config. - card: fetch up to 500 items and filter client-side by `provider_mappings` when `provider_instance` is set - editor: new `_fetchProviders()` method extracts unique providers from the library; shows a dropdown only when 2+ providers are detected, leaving single-integration setups unchanged - translations: add `editor_provider_instance` / `provider_all` keys to all 6 language files (en, es, fr, de, it, pt) - readme: document the new optional `provider_instance` option - tests: 7 new tests covering config default and filtering logic https://claude.ai/code/session_014ncsT8ZdN8iF2RCTje5Eo2
_renderEditor() was changed to async in PR #8 (provider_instance feature) but no guard was added against concurrent calls. When called multiple times before the await resolves, each call would query the same live #form-host and append its own ha-form, resulting in duplicated config fields in the UI. Fix with a _renderGen generation counter: each call increments it, and any call that finds a newer generation has started aborts after the await instead of appending to the DOM. Also adds the missing provider_instance: '' default to editor.js setConfig, aligning it with the card.js defaults so the provider dropdown initialises with a known empty-string value regardless of stored config. https://claude.ai/code/session_01S6oCbiMD9Zujr5raNFQGgz
…ching Two bugs prevented the provider_instance selector from appearing: 1. providers.length > 1 was too strict — the selector was hidden even when exactly one provider was detected. Changed to >= 1, so it appears as soon as any provider is found. 2. _fetchProviders() cached failed fetches (catch set this._providers = []) so any transient error (e.g. HA still loading, network hiccup) would permanently suppress the selector for that config key. Fixed by moving the cache assignment inside the try block — errors are no longer cached and the next _renderEditor() call will retry. Also added fallback: the selector now shows whenever this._config.provider_instance is already set (e.g. configured via YAML), even if provider discovery returns nothing, so users can manage or clear an existing value from the visual editor. https://claude.ai/code/session_01S6oCbiMD9Zujr5raNFQGgz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a regression introduced in PR #8 where the card editor rendered the configuration form twice, making it unusable.
_renderEditor()toasyncto supportawait _fetchProviders(), but didn't guard against concurrent calls. Multiple callers (setConfig,set hass, and thevalue-changedhandler) could all trigger_renderEditor()simultaneously. Each call resetsshadow.innerHTMLat the top, then yields at theawait. When both resume, they both find the same live#form-hostand each append their ownha-form— resulting in duplicated config fields and two independent event listeners firingconfig-changed._renderGen— incremented on every call, checked after theawait. Stale renders abort before touching the DOM.provider_instance: ''default toeditor.jssetConfig, aligning it withcard.jsso the provider dropdown always initialises to a known empty-string value.Test plan
_renderEditor()calls produce exactly oneha-formin the shadow DOM_renderGenincrements on each callprovider_instancedefaults to''and is preserved when providedhttps://claude.ai/code/session_01S6oCbiMD9Zujr5raNFQGgz