Spaces:
Running
Running
dr-data
Fix preview component: eliminate blinking, ensure HTML updates, add smooth transitions
dcd5e1d
Preview White Page Fix
Problem Identified
The preview was showing a completely white page instead of displaying HTML content, including the starter HTML code.
Root Causes Found
1. Critical iframe srcDoc Logic Error
- Primary iframe:
srcDoc={activeIframeIndex === 0 ? displayHtml : ''}- When
activeIframeIndexwas 0, it showed content - When
activeIframeIndexwas NOT 0, it showed empty string β
- When
- Secondary iframe:
srcDoc={activeIframeIndex === 1 ? displayHtml : secondaryHtml}- Only worked when
activeIframeIndexwas 1 secondaryHtmlstarted as empty string β
- Only worked when
2. Empty Secondary HTML State
secondaryHtmlwas initialized as empty string''- This meant the secondary iframe never had content
3. Complex Update Logic Interference
- Over-complicated update flow prevented basic HTML display
- Multiple conditions and async operations blocked simple content showing
Fixes Applied
β Fix 1: Corrected iframe srcDoc Logic
// Before (BROKEN):
srcDoc={activeIframeIndex === 0 ? displayHtml : ''}
srcDoc={activeIframeIndex === 1 ? displayHtml : secondaryHtml}
// After (FIXED):
srcDoc={displayHtml}
srcDoc={secondaryHtml || displayHtml}
β Fix 2: Initialize Secondary HTML Properly
// Before:
const [secondaryHtml, setSecondaryHtml] = useState('');
// After:
const [secondaryHtml, setSecondaryHtml] = useState(html);
β Fix 3: Simplified Update Logic
- ALWAYS update
displayHtmlimmediately whenhtmlprop changes - Prioritize showing content over complex transition effects
- Use enhanced updates only during AI streaming for improvements
- Removed blocking conditions that prevented basic HTML display
β Fix 4: Enhanced Debug Logging
- Added console logs to track HTML content flow
- Monitor component mounting and state initialization
- Track when displayHtml gets updated
Expected Results
β Immediate Benefits:
- Starter HTML displays - Preview shows default HTML content on load
- Basic HTML rendering works - Any HTML content should display properly
- No more white page - Content is always visible in the preview
- Reliable updates - HTML changes reflect in the preview consistently
β Maintained Features:
- Smooth transitions - Enhanced updates during AI streaming
- Dual iframe system - For zero-flash transitions when needed
- Loading indicators - Subtle progress feedback during AI work
- Mobile/desktop responsive - All device styling preserved
Testing Checklist
- Preview shows starter HTML on fresh page load
- Manual HTML edits reflect in preview immediately
- AI-generated content displays after streaming
- No white page or blank content issues
- Smooth transitions work during AI updates
The core issue was the iframe content assignment logic - now both iframes always have valid HTML content to display.