From b4265bfcc5043614bc0c17dacafe4d5c8486616f Mon Sep 17 00:00:00 2001 From: Shubham Patra Date: Thu, 27 Nov 2025 23:06:24 +0530 Subject: [PATCH] refactor: remove debug console logs and improve TypeScript type safety- Remove build-time console.log statements from compileMDX.ts- Replace 'any' type with proper NodeJS.Timeout | undefined in usePendingRoute.ts- Add conditional guards before clearTimeout calls for type safety- Bump DISK_CACHE_BREAKER to invalidate MDX cache after changesImproves code quality and type safety while maintaining existing functionality. --- src/hooks/usePendingRoute.ts | 8 ++++---- src/utils/compileMDX.ts | 10 +--------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/hooks/usePendingRoute.ts b/src/hooks/usePendingRoute.ts index 17d7525b4f8..682a84a308c 100644 --- a/src/hooks/usePendingRoute.ts +++ b/src/hooks/usePendingRoute.ts @@ -17,10 +17,10 @@ const usePendingRoute = () => { const [pendingRoute, setPendingRoute] = useState(null); const currentRoute = useRef(null); useEffect(() => { - let routeTransitionTimer: any = null; + let routeTransitionTimer: NodeJS.Timeout | undefined = undefined; const handleRouteChangeStart = (url: string) => { - clearTimeout(routeTransitionTimer); + if (routeTransitionTimer) clearTimeout(routeTransitionTimer); routeTransitionTimer = setTimeout(() => { if (currentRoute.current !== url) { currentRoute.current = url; @@ -30,7 +30,7 @@ const usePendingRoute = () => { }; const handleRouteChangeComplete = () => { setPendingRoute(null); - clearTimeout(routeTransitionTimer); + if (routeTransitionTimer) clearTimeout(routeTransitionTimer); }; events.on('routeChangeStart', handleRouteChangeStart); events.on('routeChangeComplete', handleRouteChangeComplete); @@ -38,7 +38,7 @@ const usePendingRoute = () => { return () => { events.off('routeChangeStart', handleRouteChangeStart); events.off('routeChangeComplete', handleRouteChangeComplete); - clearTimeout(routeTransitionTimer); + if (routeTransitionTimer) clearTimeout(routeTransitionTimer); }; }, [events]); diff --git a/src/utils/compileMDX.ts b/src/utils/compileMDX.ts index c312f03fe96..5968f1113c6 100644 --- a/src/utils/compileMDX.ts +++ b/src/utils/compileMDX.ts @@ -10,7 +10,7 @@ import {MDXComponents} from 'components/MDX/MDXComponents'; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~ IMPORTANT: BUMP THIS IF YOU CHANGE ANY CODE BELOW ~~~ -const DISK_CACHE_BREAKER = 11; +const DISK_CACHE_BREAKER = 12; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ export default async function compileMDX( @@ -45,16 +45,8 @@ export default async function compileMDX( ); const cached = await store.get(hash); if (cached) { - console.log( - 'Reading compiled MDX for /' + path + ' from ./node_modules/.cache/' - ); return cached; } - if (process.env.NODE_ENV === 'production') { - console.log( - 'Cache miss for MDX for /' + path + ' from ./node_modules/.cache/' - ); - } // If we don't add these fake imports, the MDX compiler // will insert a bunch of opaque components we can't introspect.