Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

perf: Lazy-load zoom library in Figure component

Sushmithamallesh6ec0023a8b24
diff --git a/docs/components/figure.tsx b/docs/components/figure.tsx
index b16f3dee2..63569d860 100644
--- a/docs/components/figure.tsx
+++ b/docs/components/figure.tsx
@@ -1,11 +1,16 @@
'use client';
-import { useState } from 'react';
+import { useState, useEffect, type ReactNode } from 'react';
import Image from 'next/image';
-import Zoom from 'react-medium-image-zoom';
-import 'react-medium-image-zoom/dist/styles.css';
+import dynamic from 'next/dynamic';
import { cn } from '@/lib/utils';
+// Lazy-load zoom library - only loads when Figure component is rendered
+const ZoomWrapper = dynamic<{ children: ReactNode; zoomImg: { src: string } }>(
+ () => import('react-medium-image-zoom').then((mod) => mod.default),
+ { ssr: false }
+);
+
type FigureSize = 'sm' | 'md' | 'lg' | 'full';
interface FigureProps {
@@ -48,12 +53,17 @@ export function Figure({ src, alt, caption, size = 'full', className, width, hei
const isConstrained = size !== 'full';
const dimensions = defaultDimensions[size];
+ // Load zoom CSS on mount
+ useEffect(() => {
+ import('react-medium-image-zoom/dist/styles.css');
+ }, []);
+
// Show image on load or error (so broken images are visible for debugging)
const handleReady = () => setIsLoaded(true);
return (
<figure className={cn('my-8', isConstrained && 'flex flex-col items-center', className)}>
- <Zoom zoomImg={{ src }}>
+ <ZoomWrapper zoomImg={{ src }}>
<Image
src={src}
alt={alt}
@@ -70,7 +80,7 @@ export function Figure({ src, alt, caption, size = 'full', className, width, hei
isConstrained ? 'w-auto h-auto' : 'w-full h-auto'
)}
/>
- </Zoom>
+ </ZoomWrapper>
{caption && (
<figcaption className="mt-3 text-sm text-fd-muted-foreground text-center">
{caption}
diff --git a/docs/types/css.d.ts b/docs/types/css.d.ts
new file mode 100644
index 000000000..e4e0ab054
--- /dev/null
+++ b/docs/types/css.d.ts
@@ -0,0 +1,6 @@
+declare module '*.css' {
+ const content: Record<string, string>;
+ export default content;
+}
+
+declare module 'react-medium-image-zoom/dist/styles.css';