fix(frontend): drop infectious preference fallback, add migration latch
QA review of the previous hardening commit identified two cross-user infection paths created by the smart-fallback read chain (CRIT-1/2), plus a UI-desync hazard from validation guards in setters (HIGH-1). - Extracted localStorage helpers and migration logic into composables/preferenceStorage.ts as a single source of truth. - Reads now hit only the active user's namespace - no anon / legacy fallback in the hot path. Pre-existing values are migrated **once** per active user via migratePreferencesIntoUser, which adopts anon and legacy keys into the user namespace and then deletes the source keys, so a second user logging into the same browser cannot inherit the previous user's preferences. - Migration latch tracks which user has already been migrated this session; auth store's reloadUserPreferences resets the latch on setUser/logout so the next active user gets a fresh migration. - setSansFont / setMonoFont / setFontSize / setTheme now return a boolean; GeneralSettings.vue handlers roll the form back to the canonical state when validation rejects a value, preventing the UI from drifting out of sync with the source of truth. - safeSetItem now console.warn on persistence failures so quota / private-mode issues are at least diagnosable. - applyFont is diff-aware: only the CSS variables that actually changed are written to the root style, avoiding unnecessary style recalculation when only one knob is flipped. - applyTheme caches the last effective mode to skip redundant attribute writes and Wails IPC calls. https://claude.ai/code/session_01S1FVPf4jRfWXkTSnpMmMp7
This commit is contained in:
@@ -5,10 +5,13 @@ import type { TenantInfo as TenantInfoFromAPI } from '@/api/tenant'
|
||||
import i18n from '@/i18n'
|
||||
import { reloadFontFromStorage } from '@/composables/useFont'
|
||||
import { reloadThemeFromStorage } from '@/composables/useTheme'
|
||||
import { resetMigrationLatch } from '@/composables/preferenceStorage'
|
||||
|
||||
// Per-user UI preferences are namespaced by user id in localStorage.
|
||||
// Reload them whenever the active user changes.
|
||||
function reloadUserPreferences() {
|
||||
// Reset the latch so migration runs once for the new active user.
|
||||
resetMigrationLatch()
|
||||
reloadFontFromStorage()
|
||||
reloadThemeFromStorage()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user