🌊 Волна 6: frontend данные + утечки (8 багов)

Утечки памяти:
- animated_cat_timeout_leak: timersRef + cleanup (AnimatedCat.tsx)
- compress_fallback_objecturl_leak: revokeObjectURL в onload/onerror (FeedPostComposer.tsx)
- lightbox_timeout_leak: safeTimeout + timersRef (ImageLightbox.tsx)
- OBJECT_URL_LEAK_TTS: audioUrlRef + revoke на onended/onerror (TeacherChatPage.tsx)

Данные:
- existing_image_removal_no_delete: removed_images в payload (FeedPostComposer.tsx + api.ts, ТРЕБУЕТ BACKEND)
- post_created_images_failed: пост создан → не даём дубль (FeedPostComposer.tsx)
- GET_INIT_DATA_EMPTY_STRING: логирование + безопасный fallback (telegram.ts)
- unvalidated_lang_from_url: валидация ['pl','ru','uk','en'] (LanguageContext.tsx)

Производительность:
- LEADERBOARD_O_N2_FILTER: filter вынесен из map (LeaderboardPage.tsx)

TTS_VOICE_NOT_ENCODED — уже сделано в Волне 4.

Аудит: Issue #3, frontend 8/34 задач
This commit is contained in:
2026-09-23 17:52:46 +03:00
parent fa9b678255
commit 97541e78ec
8 changed files with 152 additions and 23 deletions
+6 -2
View File
@@ -219,6 +219,10 @@ const LeaderboardPage: React.FC = () => {
return orderA - orderB;
});
// 🔧 ФИКС (23.09.2026): LEADERBOARD_O_N2_FILTER — выносим filter из .map(),
// чтобы не делать O(n²) на каждой строке.
const restEntries = entries.filter(e => e.rank > 3);
const labels: Record<string, string> = {
achievements: language === 'pl' ? 'Osiągnięcia' : language === 'ru' ? 'Достижения' : language === 'uk' ? 'Досягнення' : 'Achievements',
unlocked: language === 'pl' ? 'odblokowano' : language === 'ru' ? 'получено' : language === 'uk' ? 'отримано' : 'unlocked',
@@ -565,7 +569,7 @@ const LeaderboardPage: React.FC = () => {
<span style={{ textAlign: 'right' }}>{t('score')}</span>
</div>
{entries.filter(e => e.rank > 3).map((entry, index) => {
{restEntries.map((entry, index) => {
const isCurrentUser = entry.telegram_id === currentUserId;
const displayName = isCurrentUser ? 'You' : truncateName(entry.username, 15);
@@ -577,7 +581,7 @@ const LeaderboardPage: React.FC = () => {
gridTemplateColumns: '40px 1fr 80px',
gap: '6px',
padding: '12px 14px',
borderBottom: index < entries.filter(e => e.rank > 3).length - 1 ? '1px solid rgba(0,0,0,0.05)' : 'none',
borderBottom: index < restEntries.length - 1 ? '1px solid rgba(0,0,0,0.05)' : 'none',
alignItems: 'center',
fontSize: '13px',
animation: `fadeInUp 0.3s ease ${0.3 + index * 0.02}s both`,
+48 -5
View File
@@ -103,6 +103,8 @@ const TeacherChatPage: React.FC = () => {
const messagesEndRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const audioRef = useRef<HTMLAudioElement | null>(null);
// 🔧 ФИКС (23.09.2026): OBJECT_URL_LEAK_TTS — храним URL для revoke.
const audioUrlRef = useRef<string | null>(null);
const idRef = useRef(messages.length > 0 ? Math.max(...messages.map(m => m.id)) + 1 : 0);
const startTimeRef = useRef<number>(Date.now());
@@ -277,7 +279,11 @@ const TeacherChatPage: React.FC = () => {
audioRef.current.pause();
audioRef.current = null;
}
// 🔧 ФИКС (23.09.2026): OBJECT_URL_LEAK_TTS — освобождаем предыдущий URL
if (audioUrlRef.current) {
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
audioUrlRef.current = null;
}
if ('speechSynthesis' in window) {
window.speechSynthesis.cancel();
}
@@ -287,12 +293,26 @@ const TeacherChatPage: React.FC = () => {
try {
const audioBlob = await getTTS(polishText, 'male');
const audioUrl = URL.createObjectURL(audioBlob);
audioUrlRef.current = audioUrl; // 🔧 сохраняем для revoke
const audio = new Audio(audioUrl);
audioRef.current = audio;
audio.onended = () => setIsPlaying(null);
audio.onerror = () => setIsPlaying(null);
audio.onended = () => {
setIsPlaying(null);
// 🔧 ФИКС (23.09.2026): освобождаем URL после воспроизведения
if (audioUrlRef.current === audioUrl) {
try { URL.revokeObjectURL(audioUrl); } catch { /* ignore */ }
audioUrlRef.current = null;
}
};
audio.onerror = () => {
setIsPlaying(null);
if (audioUrlRef.current === audioUrl) {
try { URL.revokeObjectURL(audioUrl); } catch { /* ignore */ }
audioUrlRef.current = null;
}
};
await audio.play();
} catch (e) {
@@ -314,6 +334,11 @@ const TeacherChatPage: React.FC = () => {
audioRef.current.pause();
audioRef.current = null;
}
// 🔧 ФИКС (23.09.2026): OBJECT_URL_LEAK_TTS
if (audioUrlRef.current) {
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
audioUrlRef.current = null;
}
if ('speechSynthesis' in window) {
window.speechSynthesis.cancel();
}
@@ -323,10 +348,23 @@ const TeacherChatPage: React.FC = () => {
try {
const audioBlob = await getTTS(polishText, 'male');
const audioUrl = URL.createObjectURL(audioBlob);
audioUrlRef.current = audioUrl;
const audio = new Audio(audioUrl);
audioRef.current = audio;
audio.onended = () => setPlayingExampleLine(null);
audio.onerror = () => setPlayingExampleLine(null);
audio.onended = () => {
setPlayingExampleLine(null);
if (audioUrlRef.current === audioUrl) {
try { URL.revokeObjectURL(audioUrl); } catch { /* ignore */ }
audioUrlRef.current = null;
}
};
audio.onerror = () => {
setPlayingExampleLine(null);
if (audioUrlRef.current === audioUrl) {
try { URL.revokeObjectURL(audioUrl); } catch { /* ignore */ }
audioUrlRef.current = null;
}
};
await audio.play();
} catch (e) {
console.error('TTS error:', e);
@@ -356,6 +394,11 @@ const TeacherChatPage: React.FC = () => {
audioRef.current.pause();
audioRef.current = null;
}
// 🔧 ФИКС (23.09.2026): OBJECT_URL_LEAK_TTS — освобождаем URL при размонтировании
if (audioUrlRef.current) {
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
audioUrlRef.current = null;
}
if ('speechSynthesis' in window) {
window.speechSynthesis.cancel();
}