mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-17 18:06:06 +00:00
fix(web): stop spurious page refresh on account menu open; plugin log auto-refresh as switch
Two unrelated frontend fixes: - LanguageSelector mounts each time the sidebar account dropdown opens and unconditionally called i18n.changeLanguage() on mount, emitting a languageChanged event even when the language was unchanged. That handed every useTranslation() consumer a fresh `t` reference, re-running effects keyed on `t` (e.g. the plugins page system-status fetch) and surfacing as a page "refresh". Guard the call so it only fires on an actual change. - Plugin logs auto-refresh control changed from a toggle Button to a Switch + Label; the on/off button i18n keys are replaced by a single static logsAutoRefresh label across all 8 locales.
This commit is contained in:
@@ -56,7 +56,16 @@ export function LanguageSelector({
|
||||
|
||||
const savedLanguage = localStorage.getItem('langbot_language');
|
||||
if (savedLanguage) {
|
||||
i18n.changeLanguage(savedLanguage);
|
||||
// Only switch when the active language actually differs. Calling
|
||||
// i18n.changeLanguage() unconditionally on every mount emits a
|
||||
// `languageChanged` event even when nothing changed, which hands every
|
||||
// useTranslation() consumer a fresh `t` reference and re-runs effects
|
||||
// that depend on `t` (e.g. data refetches). Since this selector mounts
|
||||
// each time the account dropdown opens, that surfaced as a spurious
|
||||
// page "refresh". Guard the call to keep mounts side-effect-free.
|
||||
if (i18n.language !== savedLanguage) {
|
||||
i18n.changeLanguage(savedLanguage);
|
||||
}
|
||||
setCurrentLanguage(savedLanguage);
|
||||
} else {
|
||||
const browserLanguage = navigator.language;
|
||||
|
||||
Reference in New Issue
Block a user