Spaces:
Paused
Paused
dr-data
Fix preview component: eliminate blinking, ensure HTML updates, add smooth transitions
dcd5e1d Preview Smooth Transitions Fix
Problem
The preview component was showing jarring transitions with:
- Black screen with "Updating preview smoothly..." message
- Sudden pop-ups of new HTML content
- Sharp, annoying transitions instead of smooth updates
- Blinking effect between content changes
Root Causes Identified
- Overly intrusive loading overlay - Full-screen overlay blocking content
- Dual iframe system not working properly - Both iframes used same content
- Immediate srcDoc updates - Causing sudden pop-up effects
- Complex update logic - Race conditions and unreliable state management
- Black background - Creating harsh visual contrast
Fixes Implemented
1. Fixed HTML Update Logic
- Immediate updates when AI finishes: Ensures final output is always displayed
- Seamless content injection: Tries DOM manipulation first for zero-flash updates
- Dual iframe fallback: Uses smooth iframe swapping when injection fails
- Simplified debouncing: 300ms debounce for streaming updates only
2. Improved Dual Iframe System
- Proper content separation: Primary and secondary iframes now use different content
- Smooth transitions: CSS-based opacity and transform transitions
- Correct iframe switching: Only active iframe gets new content
3. Reduced Loading Overlay Intrusion
- Removed full-screen overlay: No more blocking black screen
- Subtle corner indicator: Small, non-intrusive loading indicator
- Conditional display: Only shows during actual transitions
4. Enhanced Visual Smoothness
- White backgrounds: Changed from black to white for softer transitions
- CSS hardware acceleration: Better performance with
will-changeandtransform3d - Smooth easing curves: Cubic-bezier transitions for natural feel
5. Immediate Content Display
- Initialize displayHtml: Ensures content shows immediately on component mount
- Skip unnecessary updates: Prevents redundant re-renders
- Force final updates: Guarantees AI completion results are displayed
Technical Details
Updated Files
/components/editor/preview/index.tsx- Main preview component logic/assets/globals.css- CSS transitions and background colors
Key Changes
- Simplified
useEffecthook for HTML updates - Fixed dual iframe
srcDocassignment - Reduced loading state triggers
- Improved error handling for TypeScript compliance
Benefits
- ✅ No more jarring black screen transitions
- ✅ Smooth, fade-based content updates
- ✅ Reliable display of final AI output
- ✅ Better performance with hardware acceleration
- ✅ Reduced visual disruption during streaming
Testing Recommendations
- Test initial page load with default HTML
- Test AI streaming updates for smoothness
- Verify final output always displays after AI completion
- Check mobile device responsiveness
- Test rapid consecutive AI requests
The preview should now provide smooth, professional transitions without blinking or sudden content changes.