From f27b5e65048e310f6698c93103a1cc1b16bcbd12 Mon Sep 17 00:00:00 2001 From: Richard R Date: Wed, 27 May 2026 16:03:34 -0600 Subject: [PATCH] fix(epub): prevent stale clearCurrDoc reference on unmount in EPUB page --- src/app/(app)/epub/[id]/page.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/(app)/epub/[id]/page.tsx b/src/app/(app)/epub/[id]/page.tsx index bfa5d6d..d92e358 100644 --- a/src/app/(app)/epub/[id]/page.tsx +++ b/src/app/(app)/epub/[id]/page.tsx @@ -46,6 +46,7 @@ export default function EPUBPage() { const inFlightDocIdRef = useRef(null); const loadedDocIdRef = useRef(null); const didInitPadPctRef = useRef(false); + const clearCurrDocRef = useRef(clearCurrDoc); useEffect(() => { setIsLoading(true); @@ -103,11 +104,15 @@ export default function EPUBPage() { }, [loadDocument, isLoading]); useEffect(() => { - return () => { - clearCurrDoc(); - }; + clearCurrDocRef.current = clearCurrDoc; }, [clearCurrDoc]); + useEffect(() => { + return () => { + clearCurrDocRef.current(); + }; + }, []); + // Compute available height = viewport - (header height + tts bar height) useEffect(() => { const compute = () => {