diff --git a/src/components/FeedPostComposer.tsx b/src/components/FeedPostComposer.tsx index 9e2c28b..06851e0 100644 --- a/src/components/FeedPostComposer.tsx +++ b/src/components/FeedPostComposer.tsx @@ -209,16 +209,21 @@ const FeedPostComposer: React.FC = ({ setSuccess(false); }, [isOpen, editingPost, language]); - // 🔧 ФИКС: revoke ObjectURL при размонтировании + // 🔧 ФИКС (22.09.2026): утечка ObjectURL при размонтировании. + // Было: setSlots в cleanup — setState в unmounted компоненте НЕ выполняется, + // поэтому URL.revokeObjectURL никогда не вызывался. + // Стало: ref с актуальными слотами + чтение из ref в cleanup. + const slotsRef = useRef<(ImageSlot | null)[]>([null, null, null]); + useEffect(() => { + slotsRef.current = slots; + }, [slots]); + useEffect(() => { return () => { - setSlots(prev => { - prev.forEach(slot => { - if (slot?.previewUrl) { - try { URL.revokeObjectURL(slot.previewUrl); } catch { /* ignore */ } - } - }); - return prev; + slotsRef.current.forEach(slot => { + if (slot?.previewUrl) { + try { URL.revokeObjectURL(slot.previewUrl); } catch { /* ignore */ } + } }); }; }, []); diff --git a/src/components/PronunciationModal.tsx b/src/components/PronunciationModal.tsx index 266811f..69b8b8d 100644 --- a/src/components/PronunciationModal.tsx +++ b/src/components/PronunciationModal.tsx @@ -45,11 +45,20 @@ const PronunciationModal: React.FC = ({ isOpen, onClose ...extra, }); + // 🔧 ФИКС (22.09.2026): утечка ObjectURL. Каждый playWord создавал blob-URL + // без revoke. Добавили audioUrlRef — хранит текущий URL для очистки. + const audioUrlRef = useRef(null); + const stopAudio = () => { if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } + // 🔧 Освобождаем предыдущий blob-URL + if (audioUrlRef.current) { + try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ } + audioUrlRef.current = null; + } if ('speechSynthesis' in window) { window.speechSynthesis.cancel(); } @@ -61,6 +70,7 @@ const PronunciationModal: React.FC = ({ isOpen, onClose try { const audioBlob = await getTTS(word, 'male'); const audioUrl = URL.createObjectURL(audioBlob); + audioUrlRef.current = audioUrl; const audio = new Audio(audioUrl); audioRef.current = audio; audio.onended = () => setIsPlaying(false); diff --git a/src/components/TeacherMenuModal.tsx b/src/components/TeacherMenuModal.tsx index 68ef39a..806b5e0 100644 --- a/src/components/TeacherMenuModal.tsx +++ b/src/components/TeacherMenuModal.tsx @@ -64,6 +64,25 @@ const TeacherMenuModal: React.FC = ({ const [isPhraseLoading, setIsPhraseLoading] = useState(false); const [isPlayingPhrase, setIsPlayingPhrase] = useState(false); const audioRef = useRef(null); + + // 🔧 ФИКС (22.09.2026): утечка ObjectURL в handlePlayPhrase, handlePlayTranslate, handlePlayLetter. + // Каждый play создавал blob-URL без revoke. Добавили audioUrlRef + stopAudioHelper. + const audioUrlRef = useRef(null); + + const stopAudioHelper = () => { + 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(); + } + }; + const scrollContainerRef = useRef(null); const menuTrackedRef = useRef(false); @@ -132,6 +151,13 @@ const TeacherMenuModal: React.FC = ({ onClose(); }; + // 🔧 ФИКС (22.09.2026): очистка audio при размонтировании + useEffect(() => { + return () => { + stopAudioHelper(); + }; + }, []); + const handleOpenLetter = (index: number) => { setSelectedLetter(index); scrollToTop(); @@ -250,20 +276,13 @@ const TeacherMenuModal: React.FC = ({ const handlePlayPhrase = async () => { if (!phraseOfDay || isPlayingPhrase) return; - if (audioRef.current) { - audioRef.current.pause(); - audioRef.current = null; - } - - if ('speechSynthesis' in window) { - window.speechSynthesis.cancel(); - } - + stopAudioHelper(); setIsPlayingPhrase(true); try { const audioBlob = await getTTS(phraseOfDay.phrase_pl, 'male'); const audioUrl = URL.createObjectURL(audioBlob); + audioUrlRef.current = audioUrl; const audio = new Audio(audioUrl); audioRef.current = audio; audio.onended = () => setIsPlayingPhrase(false); @@ -296,20 +315,13 @@ const TeacherMenuModal: React.FC = ({ const handlePlayTranslate = async () => { if (!translateResult || isPlaying) return; - if (audioRef.current) { - audioRef.current.pause(); - audioRef.current = null; - } - - if ('speechSynthesis' in window) { - window.speechSynthesis.cancel(); - } - + stopAudioHelper(); setIsPlaying(true); try { const audioBlob = await getTTS(translateResult, 'male'); const audioUrl = URL.createObjectURL(audioBlob); + audioUrlRef.current = audioUrl; const audio = new Audio(audioUrl); audioRef.current = audio; audio.onended = () => setIsPlaying(false); @@ -321,17 +333,12 @@ const TeacherMenuModal: React.FC = ({ }; const handlePlayLetter = async (word: string) => { - if (audioRef.current) { - audioRef.current.pause(); - audioRef.current = null; - } - if ('speechSynthesis' in window) { - window.speechSynthesis.cancel(); - } + stopAudioHelper(); setIsPlaying(true); try { const audioBlob = await getTTS(word, 'male'); const audioUrl = URL.createObjectURL(audioBlob); + audioUrlRef.current = audioUrl; const audio = new Audio(audioUrl); audioRef.current = audio; audio.onended = () => setIsPlaying(false); diff --git a/src/components/TypingModal.tsx b/src/components/TypingModal.tsx index a7e6a25..7ff0952 100644 --- a/src/components/TypingModal.tsx +++ b/src/components/TypingModal.tsx @@ -43,11 +43,18 @@ const TypingModal: React.FC = ({ isOpen, onClose }) => { ...extra, }); + // 🔧 ФИКС (22.09.2026): утечка ObjectURL в playAnswer. + const audioUrlRef = useRef(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 = ({ 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);