Safari: Fix loading error on account switch (#6547)

This commit is contained in:
zubiden 2025-12-22 22:54:22 +01:00 committed by Alexander Zinchuk
parent dbc363e79d
commit eab1559134
2 changed files with 35 additions and 9 deletions

View File

@ -2,9 +2,11 @@ import { memo, useMemo } from '../../../lib/teact/teact';
import { getActions } from '../../../global';
import type { ApiUser } from '../../../api/types';
import type { CustomPeer } from '../../../types';
import type { AccountInfo, CustomPeer } from '../../../types';
import { temporarilySuspendCacheUpdate } from '../../../global/cache';
import { getCurrentMaxAccountCount, getCurrentProdAccountCount } from '../../../global/helpers';
import { IS_SAFARI } from '../../../util/browser/windowEnvironment';
import { getAccountSlotUrl } from '../../../util/multiaccount';
import { REM } from '../../common/helpers/mediaDimensions';
@ -43,12 +45,27 @@ const AccountMenuItems = ({
const shouldShowLimit = currentCount >= maxCount;
const handleLimitClick = useLastCallback(() => {
showNotification({
title: lang('PremiumLimitAccountsTitle'),
message: currentUser.isPremium ? lang('PremiumLimitAccounts') : lang('PremiumLimitAccountsNoPremium'),
duration: NOTIFICATION_DURATION,
});
const handleAccountClick = useLastCallback((account: AccountInfo) => {
if (account.userId === currentUser.id) {
onSelectCurrent?.();
return;
}
// IDB locks up if we write large payload on navigation
if (IS_SAFARI) temporarilySuspendCacheUpdate();
});
const handleNewAccountClick = useLastCallback(() => {
if (shouldShowLimit) {
showNotification({
title: lang('PremiumLimitAccountsTitle'),
message: currentUser.isPremium ? lang('PremiumLimitAccounts') : lang('PremiumLimitAccountsNoPremium'),
duration: NOTIFICATION_DURATION,
});
return;
}
if (IS_SAFARI) temporarilySuspendCacheUpdate();
});
const newAccountUrl = useMemo(() => {
@ -96,7 +113,7 @@ const AccountMenuItems = ({
previewUrl={account.avatarUri}
/>
)}
onClick={account.userId === currentUser.id ? onSelectCurrent : undefined}
onClick={() => handleAccountClick(account)}
href={account.userId !== currentUser.id ? getAccountSlotUrl(Number(slot)) : undefined}
>
{account.isTest && <span className="account-menu-item-test">T</span>}
@ -111,7 +128,7 @@ const AccountMenuItems = ({
icon="add"
rel="noopener" // Allow referrer to be passed
href={!shouldShowLimit ? newAccountUrl : undefined}
onClick={shouldShowLimit ? handleLimitClick : undefined}
onClick={handleNewAccountClick}
>
{lang('MenuAddAccount')}
</MenuItem>

View File

@ -55,6 +55,7 @@ const updateCacheForced = () => updateCache(true);
let isCaching = false;
let isRemovingCache = false;
let cacheUpdateSuspensionTimestamp = 0;
let unsubscribeFromBeforeUnload: NoneToVoidFunction | undefined;
export function cacheGlobal(global: GlobalState) {
@ -382,7 +383,15 @@ function updateCache(force?: boolean) {
forceUpdateCache();
}
export function temporarilySuspendCacheUpdate() {
cacheUpdateSuspensionTimestamp = Date.now() + UPDATE_THROTTLE;
}
export function forceUpdateCache(noEncrypt = false) {
if (Date.now() < cacheUpdateSuspensionTimestamp) {
return;
}
const global = getGlobal();
const { hasPasscode, isScreenLocked } = global.passcode;