fix(language-switcher): initialize currentLang$ after availableLanguages is resolved#674
Open
giulio-leone wants to merge 1 commit into
Open
fix(language-switcher): initialize currentLang$ after availableLanguages is resolved#674giulio-leone wants to merge 1 commit into
giulio-leone wants to merge 1 commit into
Conversation
…ges is resolved Move the `currentLang$` observable initialization from the constructor to `ngOnInit()` so it runs after `availableLanguages` is resolved. Previously, the `startWith` + `map` pipeline was created in the constructor when `availableLanguages` was still `undefined`, causing the initial emission to always map to `undefined` and the template to permanently show the fallback text 'Seleziona una lingua'. This also fixes the dropdown positioning issue reported in the same ticket: the correct (shorter) label is now rendered from the first paint, so the dropdown calculates its position based on the final button width rather than the longer fallback string. Closes italia#596 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
What
Closes #596 — Fixes both the logical and graphical problems with
<it-language-switcher>.Logical fix
The
currentLang$observable was created in the constructor, beforeavailableLanguageswas resolved inngOnInit(). ThestartWith → mappipeline's first emission ranthis.availableLanguages?.find(...)againstundefined, always returningundefinedand permanently showing the fallback text "Seleziona una lingua".Fix: Move observable initialization into
ngOnInit(), afteravailableLanguagesis populated. The component now correctly shows the current language label (e.g. "ITA", "ENG") from the first render.Graphical fix (positioning)
The dropdown positioning issue was a side effect: the longer fallback string caused the button to be wider than the final label, leading to a miscalculated dropdown position. With the correct label rendered from the first paint, the dropdown positions correctly.
How
Tests
Migration
None — fully backward compatible.