fix(memory): утечки ObjectURL в 4 компонентах (22.09.2026)

This commit is contained in:
2026-09-22 13:09:34 +03:00
parent eabe823d7f
commit 45628fdaf8
4 changed files with 64 additions and 34 deletions
+9 -1
View File
@@ -43,11 +43,18 @@ const TypingModal: React.FC<TypingModalProps> = ({ isOpen, onClose }) => {
...extra,
});
// 🔧 ФИКС (22.09.2026): утечка ObjectURL в playAnswer.
const audioUrlRef = useRef<string | null>(null);
const stopAudio = () => {
if (audioRef.current) {
audioRef.current.pause();
audioRef.current = null;
}
if (audioUrlRef.current) {
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
audioUrlRef.current = null;
}
if ('speechSynthesis' in window) {
window.speechSynthesis.cancel();
}
@@ -146,13 +153,14 @@ const TypingModal: React.FC<TypingModalProps> = ({ isOpen, onClose }) => {
setShowAnswer(true);
};
const playAnswer = async () => {
const playAnswer = async () => {
if (!correctAnswer) return;
stopAudio();
setIsPlaying(true);
try {
const audioBlob = await getTTS(correctAnswer, 'male');
const audioUrl = URL.createObjectURL(audioBlob);
audioUrlRef.current = audioUrl;
const audio = new Audio(audioUrl);
audioRef.current = audio;
audio.onended = () => setIsPlaying(false);