fix(memory): утечки ObjectURL в 4 компонентах (22.09.2026)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user