@devries-cameron20 / composio Mirror · read-only / commits / 9129d8ed9
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 10:45 UTC

fix(docs): Fix SSR rendering and CSS race condition in Figure component

- Replace dynamic import with ssr:false with ClientZoom wrapper that renders children immediately during SSR, then adds zoom after hydration - Static import CSS to ensure styles are available before zoom interaction - Fixes images missing from initial HTML (SEO, CLS issues) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Sushmithamallesh committed Feb 2, 2026 at 14:12 UTC 9129d8ed98ad1a3c0005a3d61abbd2e14a23ee26
1 file changed +44 -31
docs/components/figure.tsx
+44 -31
@@ -1,15 +1,10 @@
1 'use client';
2
3 -import { useState, useEffect, type ReactNode } from 'react';
3 +import { useState, useEffect, type ReactElement } from 'react';
4 import Image from 'next/image';
5 -import dynamic from 'next/dynamic';
5 import { cn } from '@/lib/utils';
7 -
8 -// Lazy-load zoom library - only loads when Figure component is rendered
9 -const ZoomWrapper = dynamic<{ children: ReactNode; zoomImg: { src: string } }>(
10 - () => import('react-medium-image-zoom').then((mod) => mod.default),
11 - { ssr: false }
12 -);
6 +// Static import ensures CSS is available before any zoom interaction
7 +import 'react-medium-image-zoom/dist/styles.css';
8
9 type FigureSize = 'sm' | 'md' | 'lg' | 'full';
10
@@ -48,39 +43,57 @@ const sizesAttr: Record<FigureSize, string> = {
43 full: '(max-width: 640px) 100vw, (max-width: 1024px) 90vw, min(900px, 70vw)',
44 };
45
46 +// Client-side zoom wrapper that renders children immediately (for SSR)
47 +// and wraps with zoom functionality after hydration
48 +function ClientZoom({ children, zoomSrc }: { children: ReactElement; zoomSrc: string }) {
49 + const [Zoom, setZoom] = useState<React.ComponentType<{ children: ReactElement; zoomImg: { src: string } }> | null>(null);
50 +
51 + useEffect(() => {
52 + // Dynamically load zoom component on client (CSS is statically imported)
53 + import('react-medium-image-zoom').then((mod) => {
54 + setZoom(() => mod.default);
55 + });
56 + }, []);
57 +
58 + // SSR and initial client render: just the image
59 + // After zoom loads: wrap with zoom functionality
60 + if (!Zoom) {
61 + return children;
62 + }
63 +
64 + return <Zoom zoomImg={{ src: zoomSrc }}>{children}</Zoom>;
65 +}
66 +
67 export function Figure({ src, alt, caption, size = 'full', className, width, height, priority = false }: FigureProps) {
68 const [isLoaded, setIsLoaded] = useState(false);
69 const isConstrained = size !== 'full';
70 const dimensions = defaultDimensions[size];
71
56 - // Load zoom CSS on mount
57 - useEffect(() => {
58 - import('react-medium-image-zoom/dist/styles.css');
59 - }, []);
60 -
72 // Show image on load or error (so broken images are visible for debugging)
73 const handleReady = () => setIsLoaded(true);
74
75 + const image = (
76 + <Image
77 + src={src}
78 + alt={alt}
79 + width={width || dimensions.width}
80 + height={height || dimensions.height}
81 + sizes={sizesAttr[size]}
82 + priority={priority}
83 + onLoad={handleReady}
84 + onError={handleReady}
85 + className={cn(
86 + 'rounded-lg border border-fd-border transition-opacity duration-300',
87 + isLoaded ? 'opacity-100' : 'opacity-0',
88 + sizeClasses[size],
89 + isConstrained ? 'w-auto h-auto' : 'w-full h-auto'
90 + )}
91 + />
92 + );
93 +
94 return (
95 <figure className={cn('my-8', isConstrained && 'flex flex-col items-center', className)}>
66 - <ZoomWrapper zoomImg={{ src }}>
67 - <Image
68 - src={src}
69 - alt={alt}
70 - width={width || dimensions.width}
71 - height={height || dimensions.height}
72 - sizes={sizesAttr[size]}
73 - priority={priority}
74 - onLoad={handleReady}
75 - onError={handleReady}
76 - className={cn(
77 - 'rounded-lg border border-fd-border transition-opacity duration-300',
78 - isLoaded ? 'opacity-100' : 'opacity-0',
79 - sizeClasses[size],
80 - isConstrained ? 'w-auto h-auto' : 'w-full h-auto'
81 - )}
82 - />
83 - </ZoomWrapper>
96 + <ClientZoom zoomSrc={src}>{image}</ClientZoom>
97 {caption && (
98 <figcaption className="mt-3 text-sm text-fd-muted-foreground text-center">
99 {caption}