fix(frontend): harden font/theme preferences for production edge cases
Edge-case review identified several issues that would degrade UX or silently break under unusual conditions: - Anon settings chosen on the login screen were lost on first login because the storage namespace switched from "anon" to the user id; resolveStorageValue now falls through user -> anon -> legacy, so pre-login choices carry over and v1 unscoped keys are still picked up. - localStorage.setItem can throw under quota / private mode; setters now swallow the error so the UI still updates for the session. - applyFont reduced to String(undefined) when currentSize held an invalid value; runtime fallbacks to the default scale guard against manipulated storage. - Added var(--app-font-scale, 1) defaults to all 32 calc() expressions in theme.css and the body font-size, so a missing variable cannot void the calc() value. - Validation guards in setSansFont / setMonoFont / setFontSize / setTheme reject invalid keys instead of writing them to storage. - GeneralSettings.vue now watches the composable refs so the form stays in sync if preferences change externally (e.g. user switch while on the page). - Dropped the unverified t-radio-group variant prop in favour of the default style. https://claude.ai/code/session_01S1FVPf4jRfWXkTSnpMmMp7
This commit is contained in:
@@ -106,7 +106,6 @@
|
||||
<div class="setting-control">
|
||||
<t-radio-group
|
||||
v-model="localFontSize"
|
||||
variant="default-filled"
|
||||
@change="handleFontSizeChange"
|
||||
>
|
||||
<t-radio-button value="small">{{ $t('font.size.small') }}</t-radio-button>
|
||||
@@ -160,7 +159,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { ref, onMounted, computed, watch } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
@@ -196,6 +195,12 @@ const localSansFont = ref<FontKey>(currentSans.value)
|
||||
const localMonoFont = ref<MonoFontKey>(currentMono.value)
|
||||
const localFontSize = ref<FontSizeKey>(currentSize.value)
|
||||
|
||||
// Keep the form in sync if preferences change externally (e.g. on user switch).
|
||||
watch(currentTheme, (val) => { localTheme.value = val })
|
||||
watch(currentSans, (val) => { localSansFont.value = val })
|
||||
watch(currentMono, (val) => { localMonoFont.value = val })
|
||||
watch(currentSize, (val) => { localFontSize.value = val })
|
||||
|
||||
const sansFontOptions = computed<{ value: FontKey; label: string; preview: string }[]>(() => [
|
||||
{ value: 'system', label: t('font.sans.system'), preview: SANS_STACKS.system },
|
||||
{ value: 'pingfang', label: t('font.sans.pingfang'), preview: SANS_STACKS.pingfang },
|
||||
|
||||
Reference in New Issue
Block a user