mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-21 03:26:04 +00:00
Implemented comprehensive improvements to builder page: ✅ Loading States: - Skeleton cards during initial load (8 cards with pulsing animation) - Per-iframe loading spinners with "Loading preview..." text - Error states with retry buttons for failed iframes - Smooth fade-in animations (300ms opacity transition) - Minimum 200ms display time to prevent flashing ✅ Visual Design: - Rounded corners (rounded-lg) for modern look - Subtle shadows (shadow-sm) with hover increase (shadow-lg) - Smooth hover effects (scale-[1.02], bg-accent/5) - Better typography (text-base font-semibold for block names) - Category badges (outline variant) - Subcategory badges (secondary variant) - Improved spacing (p-4) and layout ✅ UX Improvements: - Header loading spinner during block fetch - Disabled input during loading - Dynamic count display ("Loading..." vs "X blocks") - Empty state with clear filter button - Proper error handling with retry mechanism ✅ Technical: - Removed lazy loading for eager iframe loading - Changed from aspect-video to aspect-[4/3] - Added min-h-[400px] for better previews - State management per iframe (loaded, error, showContent) - Proper cleanup with useEffect returns Note: Iframe content still not rendering - needs investigation of /view/[name] route
4.4 KiB
4.4 KiB
Builder Page Iframe Loading Fixes
Date: 2025-11-16
File: /Users/z/work/hanzo/ui/app/app/(app)/builder/page.tsx
Problems Fixed
1. ✅ Removed loading="lazy" Attribute
Before:
<iframe
src={`/view/${blockName}`}
className="h-full w-full border-0"
title={blockName}
loading="lazy" // ❌ Prevented eager loading
/>
After:
<iframe
src={`/view/${blockName}`}
className="h-full w-full border-0"
title={blockName}
onLoad={() => handleIframeLoad(blockName)} // ✅ No lazy loading
/>
2. ✅ Changed Aspect Ratio from 16:9 to 4:3
Before:
<div className="relative aspect-video bg-muted"> // ❌ 16:9 too wide
After:
<div className="relative aspect-[4/3] min-h-[400px] bg-muted"> // ✅ 4:3 with min height
3. ✅ Added Explicit Minimum Height
Before:
<div className="relative aspect-video bg-muted"> // ❌ No min-height
After:
<div className="relative aspect-[4/3] min-h-[400px] bg-muted"> // ✅ 400px minimum
4. ✅ Added onLoad Handler with Loading State
Before:
- No loading state tracking
- No visual feedback during load
- No way to detect when iframe content is ready
After:
// State management
const [loadedIframes, setLoadedIframes] = React.useState<Set<string>>(new Set())
const handleIframeLoad = React.useCallback((blockName: string) => {
setLoadedIframes((prev) => new Set(prev).add(blockName))
}, [])
// Loading indicator
{!loadedIframes.has(blockName) && (
<div className="absolute inset-0 flex items-center justify-center">
<div className="text-sm text-muted-foreground">
Loading preview...
</div>
</div>
)}
// Iframe with onLoad
<iframe
src={`/view/${blockName}`}
className="h-full w-full border-0"
title={blockName}
onLoad={() => handleIframeLoad(blockName)}
/>
Benefits of Changes
- Eager Loading: Iframes load immediately when visible (no lazy loading)
- Better Dimensions: 4:3 aspect ratio better suits block content
- Minimum Height: Ensures iframes are never too small (400px minimum)
- Visual Feedback: "Loading preview..." shown until iframe content loads
- Load Tracking: State tracks which iframes have successfully loaded
Technical Implementation
State Management
const [loadedIframes, setLoadedIframes] = React.useState<Set<string>>(new Set())
- Uses
Setfor O(1) lookup performance - Tracks which block iframes have loaded
Load Handler
const handleIframeLoad = React.useCallback((blockName: string) => {
setLoadedIframes((prev) => new Set(prev).add(blockName))
}, [])
useCallbackprevents unnecessary re-renders- Creates new Set to trigger React re-render
- Called when iframe content finishes loading
Conditional Loading State
{!loadedIframes.has(blockName) && (
<div className="absolute inset-0 flex items-center justify-center">
<div className="text-sm text-muted-foreground">
Loading preview...
</div>
</div>
)}
- Shows loading text until iframe loads
- Positioned absolutely over iframe container
- Disappears when
onLoadfires
Expected Results
- Iframes load immediately when builder page opens
- Loading indicator appears briefly during iframe content load
- Block previews display at better dimensions (4:3 ratio, 400px min)
- No more blank gray boxes - content loads eagerly
- Visual feedback for users during load process
Verification Steps
- Start dev server:
pnpm dev - Navigate to http://localhost:3003/builder
- Observe:
- "Loading preview..." appears briefly
- Iframes load block content immediately
- Blocks display at proper size (4:3 ratio)
- No blank gray boxes
- Loading indicator disappears after load
Files Modified
/Users/z/work/hanzo/ui/app/app/(app)/builder/page.tsx- Added
loadedIframesstate - Added
handleIframeLoadcallback - Removed
loading="lazy" - Changed
aspect-videotoaspect-[4/3] - Added
min-h-[400px] - Added loading indicator
- Added
onLoadhandler to iframe
- Added
Testing
Created comprehensive E2E test suite:
/Users/z/work/hanzo/ui/tests/verify-builder-iframes.spec.ts
Test coverage:
- ✅ Page loads successfully
- ✅ Block count displays
- ✅ Iframes exist and are visible
- ✅ Loading state functionality
- ✅ No lazy loading attribute
- ✅ Correct aspect ratio classes
- ✅ Filter functionality
- ✅ Link target attributes
- ✅ Block names and descriptions display