Skip to content

Commit b4265bf

Browse files
committed
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.
1 parent 2534424 commit b4265bf

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/hooks/usePendingRoute.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const usePendingRoute = () => {
1717
const [pendingRoute, setPendingRoute] = useState<string | null>(null);
1818
const currentRoute = useRef<string | null>(null);
1919
useEffect(() => {
20-
let routeTransitionTimer: any = null;
20+
let routeTransitionTimer: NodeJS.Timeout | undefined = undefined;
2121

2222
const handleRouteChangeStart = (url: string) => {
23-
clearTimeout(routeTransitionTimer);
23+
if (routeTransitionTimer) clearTimeout(routeTransitionTimer);
2424
routeTransitionTimer = setTimeout(() => {
2525
if (currentRoute.current !== url) {
2626
currentRoute.current = url;
@@ -30,15 +30,15 @@ const usePendingRoute = () => {
3030
};
3131
const handleRouteChangeComplete = () => {
3232
setPendingRoute(null);
33-
clearTimeout(routeTransitionTimer);
33+
if (routeTransitionTimer) clearTimeout(routeTransitionTimer);
3434
};
3535
events.on('routeChangeStart', handleRouteChangeStart);
3636
events.on('routeChangeComplete', handleRouteChangeComplete);
3737

3838
return () => {
3939
events.off('routeChangeStart', handleRouteChangeStart);
4040
events.off('routeChangeComplete', handleRouteChangeComplete);
41-
clearTimeout(routeTransitionTimer);
41+
if (routeTransitionTimer) clearTimeout(routeTransitionTimer);
4242
};
4343
}, [events]);
4444

src/utils/compileMDX.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {MDXComponents} from 'components/MDX/MDXComponents';
1010

1111
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1212
// ~~~~ IMPORTANT: BUMP THIS IF YOU CHANGE ANY CODE BELOW ~~~
13-
const DISK_CACHE_BREAKER = 11;
13+
const DISK_CACHE_BREAKER = 12;
1414
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1515

1616
export default async function compileMDX(
@@ -45,16 +45,8 @@ export default async function compileMDX(
4545
);
4646
const cached = await store.get(hash);
4747
if (cached) {
48-
console.log(
49-
'Reading compiled MDX for /' + path + ' from ./node_modules/.cache/'
50-
);
5148
return cached;
5249
}
53-
if (process.env.NODE_ENV === 'production') {
54-
console.log(
55-
'Cache miss for MDX for /' + path + ' from ./node_modules/.cache/'
56-
);
57-
}
5850

5951
// If we don't add these fake imports, the MDX compiler
6052
// will insert a bunch of opaque components we can't introspect.

0 commit comments

Comments
 (0)