fix for memory leak

This commit is contained in:
austinkelsay 2025-05-12 11:17:57 -05:00
parent ccda05df96
commit 403948f7b2
No known key found for this signature in database
GPG Key ID: 5A763922E5BA08EE
2 changed files with 8 additions and 14 deletions

View File

@ -93,6 +93,7 @@ const useCourseDecryption = (session, paidCourse, course, lessons, setLessons, r
clearTimeout(timeoutId);
decryptTimeoutRef.current = null;
} catch (error) {
clearTimeout(timeoutId);
// If timeout or network error, schedule a retry
retryTimeoutRef.current = setTimeout(() => {
processingRef.current = false;

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState, useCallback } from 'react';
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { useRouter } from 'next/router';
import { findKind0Fields } from '@/utils/nostr';
import { useNDKContext } from '@/context/NDKContext';
@ -35,7 +35,6 @@ const Course = () => {
const [nsec, setNsec] = useState(null);
const [npub, setNpub] = useState(null);
const [nAddress, setNAddress] = useState(null);
const [isDecrypting, setIsDecrypting] = useState(false);
const windowWidth = useWindowWidth();
const isMobileView = windowWidth <= 968;
const navbarHeight = 60; // Match the height from Navbar component
@ -140,18 +139,12 @@ const Course = () => {
activeIndex
);
useEffect(() => {
if (paidCourse && uniqueLessons.length > 0) {
const currentLesson = uniqueLessons[activeIndex];
if (currentLesson && !decryptedLessonIds[currentLesson.id]) {
setIsDecrypting(true);
} else {
setIsDecrypting(false);
}
} else {
setIsDecrypting(false);
}
}, [activeIndex, uniqueLessons, decryptedLessonIds, paidCourse]);
// Replace useState + useEffect with useMemo for derived state
const isDecrypting = useMemo(() => {
if (!paidCourse || uniqueLessons.length === 0) return false;
const current = uniqueLessons[activeIndex];
return current && !decryptedLessonIds[current.id];
}, [paidCourse, uniqueLessons, activeIndex, decryptedLessonIds]);
useEffect(() => {
if (uniqueLessons.length > 0) {