fix(chat): clear translation memory + worker on logout
Translations are memory-only; on logout/account switch we now clear the cache, reject pending requests and terminate the worker (the model itself is public and stays in the browser cache).
This commit is contained in:
parent
d2a24679f0
commit
67bc89861d
3 changed files with 10 additions and 1 deletions
|
|
@ -16,6 +16,7 @@ import {
|
|||
import { LoginArea } from '@/components/auth/LoginArea';
|
||||
import { useSasquatchGuide } from '@/hooks/useSasquatchGuide';
|
||||
import { LanguageToggle } from '@/components/LanguageToggle';
|
||||
import { clearTranslationMemory } from '@/lib/translation';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useTranslation } from '@/contexts/language';
|
||||
import { useLoggedInAccounts } from '@/hooks/useLoggedInAccounts';
|
||||
|
|
@ -812,7 +813,7 @@ export function Layout({ children, noPadding }: LayoutProps) {
|
|||
{user && (
|
||||
<MobileHeaderUserMenu
|
||||
pubkey={user.pubkey}
|
||||
onLogout={() => removeLogin(currentAccount?.id || '')}
|
||||
onLogout={() => { clearTranslationMemory(); removeLogin(currentAccount?.id || ''); }}
|
||||
onSetStatus={() => setShowStatusDialog(true)}
|
||||
onAddAccount={() => setShowAddAccount(true)}
|
||||
/>
|
||||
|
|
@ -1038,6 +1039,7 @@ export function Layout({ children, noPadding }: LayoutProps) {
|
|||
size="lg"
|
||||
className="w-full justify-center gap-3 text-red-400 border-red-500/50 hover:bg-red-500/20 hover:text-red-300 hover:border-red-500 h-12 text-base font-bold"
|
||||
onClick={() => {
|
||||
clearTranslationMemory();
|
||||
removeLogin(currentAccount?.id || '');
|
||||
setMobileMenuOpen(false);
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar.tsx';
|
||||
import { WalletModal } from '@/components/WalletModal';
|
||||
import { clearDmDecryptCache } from '@/lib/dmDecryptCache';
|
||||
import { clearTranslationMemory } from '@/lib/translation';
|
||||
import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts';
|
||||
import { genUserName } from '@/lib/genUserName';
|
||||
import { useTranslation } from '@/contexts/language';
|
||||
|
|
@ -102,6 +103,7 @@ export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) {
|
|||
// Drop this account's plaintext DM cache (device-local) on logout so
|
||||
// another account on the same device can't read it from IndexedDB.
|
||||
void clearDmDecryptCache(currentUser.id).catch(() => {});
|
||||
clearTranslationMemory();
|
||||
removeLogin(currentUser.id);
|
||||
}}
|
||||
className='flex items-center gap-2 cursor-pointer p-2 rounded-md text-red-500'
|
||||
|
|
|
|||
|
|
@ -145,4 +145,9 @@ export async function translateText(params: TranslateParams): Promise<string> {
|
|||
/** Clear the in-memory translation cache (e.g. on logout). */
|
||||
export function clearTranslationMemory(): void {
|
||||
memoryCache.clear();
|
||||
rejectAll(new Error('CLEARED'));
|
||||
if (worker) {
|
||||
worker.terminate();
|
||||
worker = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue